winnie 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,21 +1,3 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
-
21
- ## PROJECT::SPECIFIC
1
+ pkg/*
2
+ *.gem
3
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,26 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ winnie (0.0.1)
5
+ json
6
+ rest-client
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ fakefs (0.2.1)
12
+ json (1.4.6)
13
+ mime-types (1.16)
14
+ rest-client (1.6.1)
15
+ mime-types (>= 1.16)
16
+ rspec (1.3.1)
17
+
18
+ PLATFORMS
19
+ ruby
20
+
21
+ DEPENDENCIES
22
+ fakefs
23
+ json
24
+ rest-client
25
+ rspec (>= 1.2.9)
26
+ winnie!
data/Rakefile CHANGED
@@ -1,24 +1,5 @@
1
- require 'rubygems'
2
- require 'rake'
3
-
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "winnie"
8
- gem.summary = %Q{Winnie command line tool}
9
- gem.description = %Q{Command line tool which allows interacting with winnie's API}
10
- gem.email = "winnie-devs@ragnarson.com"
11
- gem.homepage = "http://winniecloud.net"
12
- gem.authors = ["winnie"]
13
- gem.add_dependency "json"
14
- gem.add_dependency "rest-client"
15
- gem.add_development_dependency "rspec", ">= 1.2.9"
16
- gem.add_development_dependency "fakefs"
17
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
18
- end
19
- rescue LoadError
20
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
21
- end
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
22
3
 
23
4
  require 'spec/rake/spectask'
24
5
  Spec::Rake::SpecTask.new(:spec) do |spec|
@@ -26,22 +7,4 @@ Spec::Rake::SpecTask.new(:spec) do |spec|
26
7
  spec.spec_files = FileList['spec/**/*_spec.rb']
27
8
  end
28
9
 
29
- Spec::Rake::SpecTask.new(:rcov) do |spec|
30
- spec.libs << 'lib' << 'spec'
31
- spec.pattern = 'spec/**/*_spec.rb'
32
- spec.rcov = true
33
- end
34
-
35
- task :spec => :check_dependencies
36
-
37
10
  task :default => :spec
38
-
39
- require 'rake/rdoctask'
40
- Rake::RDocTask.new do |rdoc|
41
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
42
-
43
- rdoc.rdoc_dir = 'rdoc'
44
- rdoc.title = "winnie #{version}"
45
- rdoc.rdoc_files.include('README*')
46
- rdoc.rdoc_files.include('lib/**/*.rb')
47
- end
data/lib/winnie/client.rb CHANGED
@@ -3,23 +3,23 @@ module Winnie
3
3
  def initialize(api_key)
4
4
  @api_key = api_key
5
5
  end
6
-
6
+
7
7
  def host
8
8
  ENV['WINNIE_HOST'] || 'admin.winniecloud.net'
9
9
  end
10
-
10
+
11
11
  def winnie_url
12
12
  "http://#{host}"
13
13
  end
14
-
14
+
15
15
  def account
16
16
  get('/account')
17
17
  end
18
-
18
+
19
19
  def apps
20
20
  get('/apps')
21
21
  end
22
-
22
+
23
23
  def command(command, code_name)
24
24
  post("/apps/#{code_name}/command", :body => command)
25
25
  end
@@ -27,7 +27,7 @@ module Winnie
27
27
  def post(path, params = {})
28
28
  request(path, :post, params)
29
29
  end
30
-
30
+
31
31
  def get(path)
32
32
  request(path, :get)
33
33
  end
@@ -35,7 +35,7 @@ module Winnie
35
35
  def request(path, method, params = {})
36
36
  headers = {:accept => 'application/json'}.merge(Client.winnie_headers)
37
37
  params.merge!(:api_key => @api_key)
38
-
38
+
39
39
  RestClient::Request.execute(
40
40
  :method => method,
41
41
  :url => "#{winnie_url}#{path}",
@@ -43,23 +43,22 @@ module Winnie
43
43
  :payload => params
44
44
  ) { |response, request| process_response(response) }
45
45
  end
46
-
46
+
47
47
  class UnauthorizedException < Exception; end
48
48
  class ResourceNotFoundException < Exception; end
49
49
  class CommandFailedException < Exception; end
50
-
50
+
51
51
  def self.version
52
- version_file = File.join(File.dirname(__FILE__), '..', '..', 'VERSION')
53
- @@version ||= File.read(version_file).strip
52
+ VERSION
54
53
  end
55
-
54
+
56
55
  private
57
-
56
+
58
57
  def self.winnie_headers
59
58
  {'User-Agent' => "winnie-gem-#{version}",
60
59
  'X-Ruby-Version' => RUBY_VERSION}
61
60
  end
62
-
61
+
63
62
  def process_response(response)
64
63
  # TODO: this fragment could look better
65
64
  if [404, 500, 401].include?(response.code)
@@ -69,15 +68,15 @@ module Winnie
69
68
  when 500; CommandFailedException
70
69
  when 401; raise UnauthorizedException.new
71
70
  end
72
-
73
- error = JSON.parse(response.body)['error']
71
+
72
+ error = JSON.parse(response.body)['error']
74
73
  raise exception.new(error)
75
74
  end
76
-
75
+
77
76
  response.return!
78
77
 
79
78
  if response.code == 302 and response.args[:url] =~ /user_session/
80
- raise UnauthorizedException.new
79
+ raise UnauthorizedException.new
81
80
  end
82
81
 
83
82
  JSON.parse(response.body)
@@ -9,25 +9,26 @@ module Winnie
9
9
  super(args)
10
10
  load_api_key if api_key_exists?
11
11
  end
12
-
12
+
13
13
  def run
14
14
  confirm('Do you want to change your API key?') if api_key_exists?
15
15
  ask_for_api_key
16
16
  save_api_key
17
17
  validate_api_key
18
18
  end
19
-
19
+
20
20
  def ask_for_api_key
21
21
  display "Type your Winnie API key"
22
22
  display "Key: ", false
23
23
  self.api_key = ask
24
24
  end
25
-
25
+
26
26
  def save_api_key
27
27
  FileUtils.mkdir_p(config_path)
28
28
  File.open(api_key_path, 'w') { |file| file << api_key }
29
+ set_credentials_permissions
29
30
  end
30
-
31
+
31
32
  def load_api_key
32
33
  self.api_key = File.read(api_key_path)
33
34
  end
@@ -36,14 +37,19 @@ module Winnie
36
37
  winnie.account # If it's not correct, Winnie::Client::UnauthorizedException will be raised
37
38
  display 'Your winnie API key is OK!'
38
39
  end
39
-
40
+
40
41
  def api_key_exists?
41
42
  File.exists?(api_key_path)
42
43
  end
43
-
44
+
44
45
  def api_key_path
45
46
  File.join(config_path, 'api_key')
46
47
  end
48
+
49
+ def set_credentials_permissions
50
+ FileUtils.chmod(0700, config_path)
51
+ FileUtils.chmod(0600, api_key_path)
52
+ end
47
53
  end
48
54
  end
49
55
  end
@@ -0,0 +1,3 @@
1
+ module Winnie
2
+ VERSION = "0.0.2"
3
+ end
@@ -2,53 +2,53 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
3
  describe Winnie::Commands::Auth do
4
4
  include FakeFS::SpecHelpers
5
-
5
+
6
6
  before do
7
7
  @auth = Winnie::Commands::Auth.new
8
8
  @auth.stub(:display)
9
9
  end
10
-
10
+
11
11
  describe "initialize" do
12
12
  describe "when API key doesn't exist" do
13
13
  it "should not load API key" do
14
14
  @auth.api_key.should be_nil
15
15
  end
16
16
  end
17
-
17
+
18
18
  describe "when API key exists" do
19
19
  before { create_api_key_file('NobodyKnowsIt') }
20
-
20
+
21
21
  it "should load API key" do
22
22
  auth = Winnie::Commands::Auth.new
23
23
  auth.api_key.should == 'NobodyKnowsIt'
24
24
  end
25
25
  end
26
26
  end
27
-
27
+
28
28
  describe "run" do
29
29
  before do
30
30
  @auth.stub(:ask_for_api_key)
31
31
  @auth.stub(:save_api_key)
32
32
  @auth.stub(:validate_api_key)
33
33
  end
34
-
34
+
35
35
  describe "when API key doesn't exist" do
36
36
  it "should ask for API key" do
37
37
  @auth.should_receive(:ask_for_api_key)
38
38
  @auth.run
39
39
  end
40
-
40
+
41
41
  it "should save API key" do
42
42
  @auth.should_receive(:save_api_key)
43
43
  @auth.run
44
44
  end
45
-
45
+
46
46
  it "should validate API key" do
47
47
  @auth.should_receive(:validate_api_key)
48
- @auth.run
48
+ @auth.run
49
49
  end
50
50
  end
51
-
51
+
52
52
  describe "when API key exists" do
53
53
  it "should ask if overwrite API key" do
54
54
  @auth.should_receive(:confirm).with('Do you want to change your API key?')
@@ -57,22 +57,31 @@ describe Winnie::Commands::Auth do
57
57
  end
58
58
  end
59
59
  end
60
-
60
+
61
61
  describe "save_api_key" do
62
- before { @auth.api_key = 'secret_api_key' }
63
-
62
+ before do
63
+ @auth.api_key = 'secret_api_key'
64
+ @auth.stub(:set_credentials_permissions => true)
65
+ end
66
+
64
67
  it "should create config directory" do
65
68
  FileUtils.should_receive(:mkdir_p).with(@auth.config_path)
66
69
  @auth.save_api_key
67
70
  end
68
-
71
+
69
72
  it "should save API key to file" do
70
73
  @auth.save_api_key
71
74
  key = File.read(@auth.api_key_path)
72
75
  key.should == 'secret_api_key'
73
- end
76
+ end
77
+
78
+ it "should protect secret api key file from reading by others" do
79
+ # fakefs cannot check mode of files - File.stat(some_file)
80
+ @auth.should_receive(:set_credentials_permissions)
81
+ @auth.save_api_key
82
+ end
74
83
  end
75
-
84
+
76
85
  describe "load_api_key" do
77
86
  before { create_api_key_file('VerySecretOne') }
78
87
 
@@ -81,7 +90,7 @@ describe Winnie::Commands::Auth do
81
90
  @auth.api_key.should == 'VerySecretOne'
82
91
  end
83
92
  end
84
-
93
+
85
94
  it "should return api_key_path" do
86
95
  @auth.api_key_path.should == File.join(@auth.config_path, 'api_key')
87
96
  end
data/winnie.gemspec CHANGED
@@ -1,84 +1,39 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
1
  # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "winnie/version"
5
4
 
6
5
  Gem::Specification.new do |s|
7
- s.name = %q{winnie}
8
- s.version = "0.0.1"
6
+ s.name = "winnie"
7
+ s.version = Winnie::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["winnie"]
10
+ s.email = ["winnie-devs@ragnarson.com"]
11
+ s.homepage = "http://rubygems.org/gems/dupa"
12
+ s.summary = %Q{Winnie command line tool}
13
+ s.description = %Q{Command line tool which allows interacting with winnie's API}
9
14
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["winnie"]
12
- s.date = %q{2010-08-27}
13
- s.default_executable = %q{winnie}
14
- s.description = %q{Command line tool which allows interacting with winnie's API}
15
- s.email = %q{winnie-devs@ragnarson.com}
16
- s.executables = ["winnie"]
17
- s.extra_rdoc_files = [
18
- "LICENSE",
19
- "README.rdoc"
20
- ]
21
- s.files = [
22
- ".document",
23
- ".gitignore",
24
- "LICENSE",
25
- "README.rdoc",
26
- "Rakefile",
27
- "VERSION",
28
- "bin/winnie",
29
- "lib/winnie/client.rb",
30
- "lib/winnie/command.rb",
31
- "lib/winnie/commands/app.rb",
32
- "lib/winnie/commands/auth.rb",
33
- "lib/winnie/commands/base.rb",
34
- "lib/winnie/commands/help.rb",
35
- "lib/winnie/helpers.rb",
36
- "lib/winnie/winnie.rb",
37
- "spec/client_spec.rb",
38
- "spec/command_spec.rb",
39
- "spec/commands/app_spec.rb",
40
- "spec/commands/auth_spec.rb",
41
- "spec/commands/base_spec.rb",
42
- "spec/spec.opts",
43
- "spec/spec_helper.rb",
44
- "spec/winnie_spec.rb",
45
- "winnie.gemspec"
46
- ]
47
- s.homepage = %q{http://winniecloud.net}
48
- s.rdoc_options = ["--charset=UTF-8"]
15
+ s.rubyforge_project = "dupa"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
49
20
  s.require_paths = ["lib"]
50
- s.rubygems_version = %q{1.3.7}
51
- s.summary = %q{Winnie command line tool}
52
- s.test_files = [
53
- "spec/client_spec.rb",
54
- "spec/command_spec.rb",
55
- "spec/commands/app_spec.rb",
56
- "spec/commands/auth_spec.rb",
57
- "spec/commands/base_spec.rb",
58
- "spec/spec_helper.rb",
59
- "spec/winnie_spec.rb"
60
- ]
61
21
 
62
- if s.respond_to? :specification_version then
63
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
64
- s.specification_version = 3
22
+ s.add_dependency "json"
23
+ s.add_dependency "rest-client"
24
+ s.add_development_dependency "rspec", ">= 1.2.9"
25
+ s.add_development_dependency "fakefs"
65
26
 
66
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
67
- s.add_runtime_dependency(%q<json>, [">= 0"])
68
- s.add_runtime_dependency(%q<rest-client>, [">= 0"])
69
- s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
70
- s.add_development_dependency(%q<fakefs>, [">= 0"])
71
- else
72
- s.add_dependency(%q<json>, [">= 0"])
73
- s.add_dependency(%q<rest-client>, [">= 0"])
74
- s.add_dependency(%q<rspec>, [">= 1.2.9"])
75
- s.add_dependency(%q<fakefs>, [">= 0"])
76
- end
77
- else
78
- s.add_dependency(%q<json>, [">= 0"])
79
- s.add_dependency(%q<rest-client>, [">= 0"])
80
- s.add_dependency(%q<rspec>, [">= 1.2.9"])
81
- s.add_dependency(%q<fakefs>, [">= 0"])
82
- end
83
- end
27
+ # TODO: remove after few releases
28
+ s.post_install_message = %q{
29
+ ========================================================================
84
30
 
31
+ If upgrading from 0.0.1 version of winnie do the following:
32
+ > winnie auth
33
+ Enter your API key
34
+ confirm changes
35
+
36
+ This is important to protect your Winnie Cloud credentials.
37
+ ========================================================================
38
+ }
39
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: winnie
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - winnie
@@ -15,8 +15,8 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-27 00:00:00 +02:00
19
- default_executable: winnie
18
+ date: 2010-10-18 00:00:00 +02:00
19
+ default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: json
@@ -77,21 +77,21 @@ dependencies:
77
77
  type: :development
78
78
  version_requirements: *id004
79
79
  description: Command line tool which allows interacting with winnie's API
80
- email: winnie-devs@ragnarson.com
80
+ email:
81
+ - winnie-devs@ragnarson.com
81
82
  executables:
82
83
  - winnie
83
84
  extensions: []
84
85
 
85
- extra_rdoc_files:
86
- - LICENSE
87
- - README.rdoc
86
+ extra_rdoc_files: []
87
+
88
88
  files:
89
- - .document
90
89
  - .gitignore
90
+ - Gemfile
91
+ - Gemfile.lock
91
92
  - LICENSE
92
93
  - README.rdoc
93
94
  - Rakefile
94
- - VERSION
95
95
  - bin/winnie
96
96
  - lib/winnie/client.rb
97
97
  - lib/winnie/command.rb
@@ -100,6 +100,7 @@ files:
100
100
  - lib/winnie/commands/base.rb
101
101
  - lib/winnie/commands/help.rb
102
102
  - lib/winnie/helpers.rb
103
+ - lib/winnie/version.rb
103
104
  - lib/winnie/winnie.rb
104
105
  - spec/client_spec.rb
105
106
  - spec/command_spec.rb
@@ -111,12 +112,23 @@ files:
111
112
  - spec/winnie_spec.rb
112
113
  - winnie.gemspec
113
114
  has_rdoc: true
114
- homepage: http://winniecloud.net
115
+ homepage: http://rubygems.org/gems/dupa
115
116
  licenses: []
116
117
 
117
- post_install_message:
118
- rdoc_options:
119
- - --charset=UTF-8
118
+ post_install_message: |
119
+
120
+ ========================================================================
121
+
122
+ If upgrading from 0.0.1 version of winnie do the following:
123
+ > winnie auth
124
+ Enter your API key
125
+ confirm changes
126
+
127
+ This is important to protect your Winnie Cloud credentials.
128
+ ========================================================================
129
+
130
+ rdoc_options: []
131
+
120
132
  require_paths:
121
133
  - lib
122
134
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -139,7 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
151
  version: "0"
140
152
  requirements: []
141
153
 
142
- rubyforge_project:
154
+ rubyforge_project: dupa
143
155
  rubygems_version: 1.3.7
144
156
  signing_key:
145
157
  specification_version: 3
@@ -150,5 +162,6 @@ test_files:
150
162
  - spec/commands/app_spec.rb
151
163
  - spec/commands/auth_spec.rb
152
164
  - spec/commands/base_spec.rb
165
+ - spec/spec.opts
153
166
  - spec/spec_helper.rb
154
167
  - spec/winnie_spec.rb
data/.document DELETED
@@ -1,5 +0,0 @@
1
- README.rdoc
2
- lib/**/*.rb
3
- bin/*
4
- features/**/*.feature
5
- LICENSE
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.0.1