ey_cli 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/Gemfile +3 -0
  2. data/Gemfile.lock +57 -0
  3. data/LICENSE +22 -0
  4. data/README.md +104 -0
  5. data/Rakefile +129 -0
  6. data/bin/ey_cli +5 -0
  7. data/ey_cli.gemspec +117 -0
  8. data/history.md +3 -0
  9. data/lib/ey_cli/api.rb +96 -0
  10. data/lib/ey_cli/cli.rb +17 -0
  11. data/lib/ey_cli/command_manager.rb +29 -0
  12. data/lib/ey_cli/commands/accounts.rb +26 -0
  13. data/lib/ey_cli/commands/apps.rb +24 -0
  14. data/lib/ey_cli/commands/base.rb +16 -0
  15. data/lib/ey_cli/commands/console.rb +38 -0
  16. data/lib/ey_cli/commands/create_app.rb +76 -0
  17. data/lib/ey_cli/commands/create_env.rb +106 -0
  18. data/lib/ey_cli/commands/deploy.rb +23 -0
  19. data/lib/ey_cli/commands/help.rb +65 -0
  20. data/lib/ey_cli/commands/show.rb +65 -0
  21. data/lib/ey_cli/controllers/accounts.rb +23 -0
  22. data/lib/ey_cli/controllers/apps.rb +66 -0
  23. data/lib/ey_cli/controllers/environments.rb +78 -0
  24. data/lib/ey_cli/git_utils.rb +12 -0
  25. data/lib/ey_cli/models/account.rb +6 -0
  26. data/lib/ey_cli/models/app.rb +15 -0
  27. data/lib/ey_cli/models/base.rb +54 -0
  28. data/lib/ey_cli/models/environment.rb +32 -0
  29. data/lib/ey_cli/options_parser.rb +47 -0
  30. data/lib/ey_cli/smarty_parser.rb +29 -0
  31. data/lib/ey_cli/term.rb +58 -0
  32. data/lib/ey_cli.rb +46 -0
  33. data/spec/auth_helper.rb +28 -0
  34. data/spec/ey_cli/api_spec.rb +70 -0
  35. data/spec/ey_cli/command_manager_spec.rb +33 -0
  36. data/spec/ey_cli/commands/help_spec.rb +36 -0
  37. data/spec/ey_cli/controllers/accounts_spec.rb +40 -0
  38. data/spec/ey_cli/controllers/apps_spec.rb +97 -0
  39. data/spec/ey_cli/controllers/environments_spec.rb +101 -0
  40. data/spec/ey_cli/models/app_spec.rb +50 -0
  41. data/spec/ey_cli/models/base_spec.rb +98 -0
  42. data/spec/ey_cli/models/environment_spec.rb +51 -0
  43. data/spec/ey_cli/options_parser_spec.rb +19 -0
  44. data/spec/ey_cli/smarty_parser_spec.rb +19 -0
  45. data/spec/spec_helper.rb +29 -0
  46. metadata +288 -0
@@ -0,0 +1,98 @@
1
+ require File.expand_path('../../spec_helper', File.dirname(__FILE__))
2
+
3
+ describe EYCli::Model::Base do
4
+ class BaseMock < EYCli::Model::Base
5
+ base_path 'base_mocks'
6
+ end
7
+
8
+ class HierarchicalMock < EYCli::Model::Base
9
+ base_path 'parent/%s/children'
10
+ end
11
+
12
+ subject { EYCli::Model::Base }
13
+
14
+ it "knows its name" do
15
+ EYCli::Model::Account.class_name.should == 'account'
16
+ end
17
+
18
+ it "uses the class name as base path to call the api" do
19
+ EYCli::Model::Account.base_path.should == 'accounts'
20
+ end
21
+
22
+ it "allows to override the base path calling the method class" do
23
+ BaseMock.base_path.should == 'base_mocks'
24
+ end
25
+
26
+ it "resolves the resource children path given the base path and the variable arguments" do
27
+ path = BaseMock.resolve_child_path([1])
28
+ path.should == 'base_mocks/1'
29
+
30
+ path = HierarchicalMock.resolve_child_path([1, 1])
31
+ path.should == 'parent/1/children/1'
32
+ end
33
+
34
+ context '.all' do
35
+ it "returns the collection of elements" do
36
+ body = to_json({:base_mocks => [{:id => 1, :name => 'foo'}]})
37
+ stub_request(:get, 'http://example.com/base_mocks').
38
+ to_return(:body => body, :status => 200)
39
+
40
+ mocks = BaseMock.all
41
+ mocks.should have(1).mocks
42
+ end
43
+
44
+ it 'returns an empty array when the collection is empty' do
45
+ body = to_json({:base_mocks => []})
46
+ stub_request(:get, 'http://example.com/base_mocks').
47
+ to_return(:body => body, :status => 200)
48
+
49
+ BaseMock.all.should be_empty
50
+ end
51
+ end
52
+
53
+ context ".find" do
54
+ it "accepts several identifires to fill the hierarchy" do
55
+ expected = HierarchicalMock.new({:id => 1, :parent => BaseMock.new({:id => 2})})
56
+ stub_request(:get, 'http://example.com/parent/2/children/1').
57
+ to_return(:body => to_json(:hierarchicalmock => expected))
58
+
59
+ mock = HierarchicalMock.find(2, 1)
60
+ mock.should == expected
61
+ end
62
+
63
+ it "returns the element if exists" do
64
+ expected = BaseMock.new({:id => 1, :name => 'foo'})
65
+ body = to_json({:basemock => expected.to_hash})
66
+ stub_request(:get, 'http://example.com/base_mocks/1').
67
+ to_return(:body => body, :status => 200)
68
+
69
+ mock = BaseMock.find 1
70
+ mock.should == expected
71
+ end
72
+
73
+ it "raises an error when the element is not found" do
74
+ stub_request(:get, 'http://example.com/base_mocks/1').
75
+ to_return(:status => 404)
76
+
77
+ lambda { BaseMock.find 1 }.should raise_error(Faraday::Error::ResourceNotFound)
78
+ end
79
+ end
80
+
81
+ context '.find_by_name' do
82
+ before do
83
+ @expected = BaseMock.new({:id => 1, :name => 'foo'})
84
+ body = to_json({:base_mocks => [@expected.to_hash]})
85
+ stub_request(:get, 'http://example.com/base_mocks').
86
+ to_return(:body => body, :status => 200)
87
+ end
88
+
89
+ it "returns the element if it finds it by name" do
90
+ mock = BaseMock.find_by_name 'foo'
91
+ mock.should == @expected
92
+ end
93
+
94
+ it "returns nil when the element is not found" do
95
+ BaseMock.find_by_name('bar').should be_nil
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,51 @@
1
+ require File.expand_path('../../spec_helper', File.dirname(__FILE__))
2
+
3
+ describe EYCli::Model::Environment do
4
+ context "creating the resource path" do
5
+ let(:clazz) { EYCli::Model::Environment }
6
+ it "raises an error when the app is not into the parameters hash" do
7
+ lambda { clazz.create_collection_path({}) }.should raise_error
8
+ end
9
+
10
+ it "creates the resource path using the application id" do
11
+ app = EYCli::Model::App.new(:id => 1)
12
+ path = clazz.create_collection_path(:app => app)
13
+ path.should == 'apps/1/environments'
14
+ end
15
+ end
16
+
17
+ context "deploying" do
18
+ let(:app) { EYCli::Model::App.new(:id => 1, :name => 'fake_app') }
19
+ let(:env) do
20
+ EYCli::Model::Environment.new(
21
+ :id => 1,
22
+ :deployment_configurations => {
23
+ 'fake_app' => {:migrate => {:perform => true, :command => 'rake db:migrate'}}
24
+ })
25
+ end
26
+ let(:deploy_uri) { 'http://example.com/apps/1/environments/1/deployments/deploy' }
27
+
28
+ it "uses the default deployment options when the provided options are empty" do
29
+ stub_request(:post, "#{deploy_uri}?deployment[migrate]=true&deployment[migrate_command]=rake db:migrate&deployment[ref]=HEAD").
30
+ to_return(:status => 201, :body => to_json(:deployment => {}))
31
+
32
+ env.deploy(app)
33
+ end
34
+
35
+ it "uses the provided options as deploy parameters" do
36
+ stub_request(:post, "#{deploy_uri}?deployment[migrate]=false&deployment[migrate_command]=fake_migrate&deployment[ref]=master").
37
+ to_return(:status => 201, :body => to_json(:deployment => {}))
38
+
39
+ env.deploy(app, {:migrate => false, :migrate_command => 'fake_migrate', :ref => 'master'})
40
+ end
41
+
42
+ it "returns the body of the response when there is an error" do
43
+ expected_body = Hashie::Mash.new({:errors => {:provision => 'Amazon is down'}})
44
+ stub_request(:post, "#{deploy_uri}?deployment[migrate]=true&deployment[migrate_command]=rake db:migrate&deployment[ref]=HEAD").
45
+ to_return(:status => 400, :body => to_json(expected_body))
46
+
47
+ response = env.deploy(app)
48
+ response.should == expected_body
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,19 @@
1
+ require File.expand_path('../spec_helper', File.dirname(__FILE__))
2
+
3
+ describe EYCli::OptionsParser do
4
+
5
+ it 'accepts the account name as an option' do
6
+ opts = subject.parse ['-a', 'fake_account']
7
+ opts[:account].should == 'fake_account'
8
+ end
9
+
10
+ it 'accepts the app name as an option' do
11
+ opts = subject.parse ['-p', 'fake_app']
12
+ opts[:app].should == 'fake_app'
13
+ end
14
+
15
+ it 'accepts the environment name as an option' do
16
+ opts = subject.parse ['-e', 'fake_env']
17
+ opts[:environment].should == 'fake_env'
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require File.expand_path('../spec_helper', File.dirname(__FILE__))
2
+
3
+ describe 'EYCli::SmartyParser' do
4
+ class Parser; extend EYCli::SmartyParser; end
5
+
6
+ it "parses the entities in a recursively" do
7
+ out = Parser.smarty({'account' => {'id' => 1}})
8
+
9
+ out['account'].should be_instance_of(EYCli::Model::Account)
10
+ end
11
+
12
+ it "does not override other instances" do
13
+ out = Parser.smarty({'app'=> {'account' => {}, 'environments' => [{}]}})
14
+
15
+ out['app'].should be_instance_of(EYCli::Model::App)
16
+ out['app'].account.should be_instance_of(EYCli::Model::Account)
17
+ out['app'].environments.first.should be_instance_of(EYCli::Model::Environment)
18
+ end
19
+ end
@@ -0,0 +1,29 @@
1
+ require 'rspec'
2
+
3
+ $LOAD_PATH << '../lib'
4
+ require 'ey_cli'
5
+ require 'webmock/rspec'
6
+ require 'fakefs/spec_helpers'
7
+ require 'stringio'
8
+ require 'auth_helper'
9
+
10
+ # Setup for specs
11
+
12
+ EYCli.api 'http://example.com' # use example.com as an endpoint
13
+
14
+ $stdin_test = StringIO.new
15
+ $stdout_test = StringIO.new
16
+
17
+ EYCli.term($stdin_test, $stdout_test) # use fake buffers as input and output
18
+
19
+
20
+ RSpec.configure do |config|
21
+ config.include FakeFS::SpecHelpers
22
+ config.include EYCli::AuthHelper
23
+ end
24
+
25
+ # Helper methods
26
+
27
+ def to_json(hash)
28
+ MultiJson.encode(hash)
29
+ end
metadata ADDED
@@ -0,0 +1,288 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ey_cli
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - David Calavera
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-10-15 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ version_requirements: &id001 !ruby/object:Gem::Requirement
22
+ none: false
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ hash: 3
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ name: faraday
31
+ type: :runtime
32
+ prerelease: false
33
+ requirement: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ version_requirements: &id002 !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ hash: 3
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ name: faraday_middleware
45
+ type: :runtime
46
+ prerelease: false
47
+ requirement: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ version_requirements: &id003 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ hash: 3
55
+ segments:
56
+ - 0
57
+ version: "0"
58
+ name: faraday-stack
59
+ type: :runtime
60
+ prerelease: false
61
+ requirement: *id003
62
+ - !ruby/object:Gem::Dependency
63
+ version_requirements: &id004 !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ hash: 3
69
+ segments:
70
+ - 0
71
+ version: "0"
72
+ name: highline
73
+ type: :runtime
74
+ prerelease: false
75
+ requirement: *id004
76
+ - !ruby/object:Gem::Dependency
77
+ version_requirements: &id005 !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ hash: 3
83
+ segments:
84
+ - 0
85
+ version: "0"
86
+ name: hashie
87
+ type: :runtime
88
+ prerelease: false
89
+ requirement: *id005
90
+ - !ruby/object:Gem::Dependency
91
+ version_requirements: &id006 !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ hash: 3
97
+ segments:
98
+ - 0
99
+ version: "0"
100
+ name: json
101
+ type: :runtime
102
+ prerelease: false
103
+ requirement: *id006
104
+ - !ruby/object:Gem::Dependency
105
+ version_requirements: &id007 !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ hash: 3
111
+ segments:
112
+ - 0
113
+ version: "0"
114
+ name: multi_json
115
+ type: :runtime
116
+ prerelease: false
117
+ requirement: *id007
118
+ - !ruby/object:Gem::Dependency
119
+ version_requirements: &id008 !ruby/object:Gem::Requirement
120
+ none: false
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ hash: 3
125
+ segments:
126
+ - 0
127
+ version: "0"
128
+ name: slop
129
+ type: :runtime
130
+ prerelease: false
131
+ requirement: *id008
132
+ - !ruby/object:Gem::Dependency
133
+ version_requirements: &id009 !ruby/object:Gem::Requirement
134
+ none: false
135
+ requirements:
136
+ - - ~>
137
+ - !ruby/object:Gem::Version
138
+ hash: 25
139
+ segments:
140
+ - 0
141
+ - 9
142
+ version: "0.9"
143
+ name: rake
144
+ type: :development
145
+ prerelease: false
146
+ requirement: *id009
147
+ - !ruby/object:Gem::Dependency
148
+ version_requirements: &id010 !ruby/object:Gem::Requirement
149
+ none: false
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ hash: 3
154
+ segments:
155
+ - 0
156
+ version: "0"
157
+ name: rspec
158
+ type: :development
159
+ prerelease: false
160
+ requirement: *id010
161
+ - !ruby/object:Gem::Dependency
162
+ version_requirements: &id011 !ruby/object:Gem::Requirement
163
+ none: false
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ hash: 3
168
+ segments:
169
+ - 0
170
+ version: "0"
171
+ name: webmock
172
+ type: :development
173
+ prerelease: false
174
+ requirement: *id011
175
+ - !ruby/object:Gem::Dependency
176
+ version_requirements: &id012 !ruby/object:Gem::Requirement
177
+ none: false
178
+ requirements:
179
+ - - ">="
180
+ - !ruby/object:Gem::Version
181
+ hash: 3
182
+ segments:
183
+ - 0
184
+ version: "0"
185
+ name: fakefs
186
+ type: :development
187
+ prerelease: false
188
+ requirement: *id012
189
+ description: More user friendly CLI for Engine Yard cloud. Use undocumented APIs
190
+ email: david.calavera@gmail.com
191
+ executables:
192
+ - ey_cli
193
+ extensions: []
194
+
195
+ extra_rdoc_files:
196
+ - README.md
197
+ - LICENSE
198
+ files:
199
+ - Gemfile
200
+ - Gemfile.lock
201
+ - LICENSE
202
+ - README.md
203
+ - Rakefile
204
+ - bin/ey_cli
205
+ - ey_cli.gemspec
206
+ - history.md
207
+ - lib/ey_cli.rb
208
+ - lib/ey_cli/api.rb
209
+ - lib/ey_cli/cli.rb
210
+ - lib/ey_cli/command_manager.rb
211
+ - lib/ey_cli/commands/accounts.rb
212
+ - lib/ey_cli/commands/apps.rb
213
+ - lib/ey_cli/commands/base.rb
214
+ - lib/ey_cli/commands/console.rb
215
+ - lib/ey_cli/commands/create_app.rb
216
+ - lib/ey_cli/commands/create_env.rb
217
+ - lib/ey_cli/commands/deploy.rb
218
+ - lib/ey_cli/commands/help.rb
219
+ - lib/ey_cli/commands/show.rb
220
+ - lib/ey_cli/controllers/accounts.rb
221
+ - lib/ey_cli/controllers/apps.rb
222
+ - lib/ey_cli/controllers/environments.rb
223
+ - lib/ey_cli/git_utils.rb
224
+ - lib/ey_cli/models/account.rb
225
+ - lib/ey_cli/models/app.rb
226
+ - lib/ey_cli/models/base.rb
227
+ - lib/ey_cli/models/environment.rb
228
+ - lib/ey_cli/options_parser.rb
229
+ - lib/ey_cli/smarty_parser.rb
230
+ - lib/ey_cli/term.rb
231
+ - spec/auth_helper.rb
232
+ - spec/ey_cli/api_spec.rb
233
+ - spec/ey_cli/command_manager_spec.rb
234
+ - spec/ey_cli/commands/help_spec.rb
235
+ - spec/ey_cli/controllers/accounts_spec.rb
236
+ - spec/ey_cli/controllers/apps_spec.rb
237
+ - spec/ey_cli/controllers/environments_spec.rb
238
+ - spec/ey_cli/models/app_spec.rb
239
+ - spec/ey_cli/models/base_spec.rb
240
+ - spec/ey_cli/models/environment_spec.rb
241
+ - spec/ey_cli/options_parser_spec.rb
242
+ - spec/ey_cli/smarty_parser_spec.rb
243
+ - spec/spec_helper.rb
244
+ homepage: http://github.com/calavera/ey_cli
245
+ licenses: []
246
+
247
+ post_install_message:
248
+ rdoc_options:
249
+ - --charset=UTF-8
250
+ require_paths:
251
+ - lib
252
+ required_ruby_version: !ruby/object:Gem::Requirement
253
+ none: false
254
+ requirements:
255
+ - - ">="
256
+ - !ruby/object:Gem::Version
257
+ hash: 3
258
+ segments:
259
+ - 0
260
+ version: "0"
261
+ required_rubygems_version: !ruby/object:Gem::Requirement
262
+ none: false
263
+ requirements:
264
+ - - ">="
265
+ - !ruby/object:Gem::Version
266
+ hash: 3
267
+ segments:
268
+ - 0
269
+ version: "0"
270
+ requirements: []
271
+
272
+ rubyforge_project: ey_cli
273
+ rubygems_version: 1.8.6
274
+ signing_key:
275
+ specification_version: 2
276
+ summary: More user friendly CLI for Engine Yard cloud
277
+ test_files:
278
+ - spec/ey_cli/api_spec.rb
279
+ - spec/ey_cli/command_manager_spec.rb
280
+ - spec/ey_cli/commands/help_spec.rb
281
+ - spec/ey_cli/controllers/accounts_spec.rb
282
+ - spec/ey_cli/controllers/apps_spec.rb
283
+ - spec/ey_cli/controllers/environments_spec.rb
284
+ - spec/ey_cli/models/app_spec.rb
285
+ - spec/ey_cli/models/base_spec.rb
286
+ - spec/ey_cli/models/environment_spec.rb
287
+ - spec/ey_cli/options_parser_spec.rb
288
+ - spec/ey_cli/smarty_parser_spec.rb