engineyard-cloud-client 1.0.8 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/ChangeLog.md CHANGED
@@ -4,6 +4,10 @@
4
4
 
5
5
  *
6
6
 
7
+ ## v1.0.9 (2013-02-20)
8
+
9
+ *
10
+
7
11
  ## v1.0.8 (2013-02-14)
8
12
 
9
13
  * Loosen the multi\_json gem version requirement to allow 1.0 compatible security fixes.
@@ -40,7 +40,7 @@ module EY
40
40
  unless String === value
41
41
  value = value.pretty_inspect.rstrip # remove trailing whitespace
42
42
  if value.index("\n") # if the inspect is multi-line
43
- value.gsub!(/[\r\n]./, "\n" + ' ' * (indent + 2)) # indent it
43
+ value = value.gsub(/^/, " "*(indent + 2)).lstrip # indent it
44
44
  end
45
45
  end
46
46
  @output << "#{name.to_s.rjust(indent)} #{value.rstrip}\n" # just one newline
@@ -118,11 +118,33 @@ module EY
118
118
  rescue RestClient::BadGateway
119
119
  raise RequestFailed, "EY Cloud API is temporarily unavailable. Please try again soon."
120
120
  rescue RestClient::RequestFailed => e
121
- raise RequestFailed, "#{e.message} #{e.response}"
121
+ raise RequestFailed, "Error: #{parse_error(e)}"
122
122
  rescue OpenSSL::SSL::SSLError
123
123
  raise RequestFailed, "SSL is misconfigured on your cloud"
124
124
  end
125
125
 
126
+ def parse_error(error)
127
+ resp = error.response
128
+ debug("Error", error.message)
129
+
130
+ if resp.body.empty?
131
+ debug("Response", '<<Response body is empty>>')
132
+ error.message
133
+ elsif resp.headers[:content_type] =~ /application\/json/
134
+ begin
135
+ data = MultiJson.load(resp.body)
136
+ debug("Response", data)
137
+ data['message'] ? data['message'] : "#{error.message} #{data.inspect}"
138
+ rescue MultiJson::DecodeError
139
+ debug("Response", resp.body)
140
+ "#{error.message} #{resp.body}"
141
+ end
142
+ else
143
+ debug("Response", resp.body)
144
+ "#{error.message} #{resp.body}"
145
+ end
146
+ end
147
+
126
148
  def parse_response(resp)
127
149
  if resp.body.empty?
128
150
  ''
@@ -11,9 +11,9 @@ module EY
11
11
  end
12
12
  end
13
13
 
14
- def set(klass, obj)
15
- if obj.respond_to?(:id) && obj.id
16
- @registry[klass][obj.id] = obj
14
+ def set(klass, id, obj)
15
+ if id && obj
16
+ @registry[klass][id] = obj
17
17
  end
18
18
  end
19
19
  end
@@ -24,7 +24,7 @@ module EY
24
24
  obj.attributes = attrs_or_struct
25
25
  else
26
26
  obj = new(api, attrs_or_struct)
27
- api.registry.set(self, obj)
27
+ api.registry.set(self, obj.id, obj)
28
28
  end
29
29
  obj
30
30
  end
@@ -110,6 +110,17 @@ module EY
110
110
  put_to_api({:successful => successful, :output => output.read})
111
111
  end
112
112
 
113
+ def cancel
114
+ if finished?
115
+ raise EY::CloudClient::Error, "Previous deployment is already finished. Aborting."
116
+ else
117
+ current_user_name = api.current_user.name
118
+ self.successful = false
119
+ err << "!> Marked as canceled by #{current_user_name}"
120
+ finished
121
+ end
122
+ end
123
+
113
124
  def finished?
114
125
  !finished_at.nil?
115
126
  end
@@ -97,7 +97,7 @@ class FakeAwsm < Sinatra::Base
97
97
  ""
98
98
  else
99
99
  status 404
100
- return {"message" => "Keypair not found with id #{params['id'].inspect}"}.to_json
100
+ json "message" => "Keypair not found with id #{params['id'].inspect}"
101
101
  end
102
102
  end
103
103
 
@@ -133,7 +133,7 @@ class FakeAwsm < Sinatra::Base
133
133
  end
134
134
 
135
135
  get "/api/v2/environments/:env_id/logs" do
136
- {
136
+ json(
137
137
  "logs" => [
138
138
  {
139
139
  "id" => 'i-12345678',
@@ -142,7 +142,7 @@ class FakeAwsm < Sinatra::Base
142
142
  "custom" => "CUSTOM LOG OUTPUT"
143
143
  }
144
144
  ]
145
- }.to_json
145
+ )
146
146
  end
147
147
 
148
148
  get "/api/v2/environments/:env_id/recipes" do
@@ -210,7 +210,7 @@ class FakeAwsm < Sinatra::Base
210
210
  render :rabl, :deployment, :format => "json"
211
211
  else
212
212
  status(404)
213
- {"message" => "Deployment not found: last"}.to_json
213
+ json "message" => "Deployment not found: last"
214
214
  end
215
215
  end
216
216
 
@@ -224,10 +224,10 @@ class FakeAwsm < Sinatra::Base
224
224
  post "/api/v2/authenticate" do
225
225
  user = User.first(:email => params[:email], :password => params[:password])
226
226
  if user
227
- {"api_token" => user.api_token, "ok" => true}.to_json
227
+ json "api_token" => user.api_token, "ok" => true
228
228
  else
229
229
  status(401)
230
- {"ok" => false}.to_json
230
+ json "ok" => false
231
231
  end
232
232
  end
233
233
 
@@ -15,7 +15,7 @@ module EY::CloudClient::Test
15
15
  unless system("ruby -c '#{config_ru}' > /dev/null")
16
16
  raise SyntaxError, "There is a syntax error in fake_awsm/config.ru! FIX IT!"
17
17
  end
18
- @server = RealWeb.start_server_in_fork(config_ru, :timeout => 5)
18
+ @server = RealWeb.start_server_in_fork(config_ru, :timeout => 10, :verbose => ENV['DEBUG'])
19
19
  @server.base_uri.to_s
20
20
  end
21
21
  end
@@ -1,7 +1,7 @@
1
1
  # This file is maintained by a herd of rabid monkeys with Rakes.
2
2
  module EY
3
3
  class CloudClient
4
- VERSION = '1.0.8'
4
+ VERSION = '1.0.9'
5
5
  end
6
6
  end
7
7
  # Please be aware that the monkeys like tho throw poo sometimes.
@@ -109,5 +109,37 @@ describe EY::CloudClient::AppEnvironment do
109
109
  deployment.finished
110
110
  EY::CloudClient::Deployment.last(@api, @app_env).should == deployment
111
111
  end
112
+
113
+ context "canceling" do
114
+ before do
115
+ deployment = @app_env.new_deployment({
116
+ :ref => 'master',
117
+ :migrate => true,
118
+ :migrate_command => 'rake migrate',
119
+ })
120
+ deployment.start
121
+ end
122
+
123
+ it "marks the deployment finish and unsuccessful with a message" do
124
+ deployment = EY::CloudClient::Deployment.last(@api, @app_env)
125
+ deployment.should_not be_finished
126
+ deployment.cancel
127
+ deployment.should be_finished
128
+ deployment.should_not be_successful
129
+ deployment.output.rewind
130
+ deployment.output.read.should =~ /Marked as canceled by Linked App/
131
+
132
+ EY::CloudClient::Deployment.last(@api, @app_env).should be_finished
133
+ end
134
+
135
+ it "raises if the deployment is already finished" do
136
+ deployment = EY::CloudClient::Deployment.last(@api, @app_env)
137
+ deployment.out << "Test output"
138
+ deployment.successful = true
139
+ deployment.finished
140
+ deployment.should be_finished
141
+ expect { deployment.cancel }.to raise_error(EY::CloudClient::Error, "Previous deployment is already finished. Aborting.")
142
+ end
143
+ end
112
144
  end
113
145
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe EY::CloudClient::ApiStruct do
4
- class Foo < EY::CloudClient::ApiStruct.new(:fruit, :veggie); end
4
+ class Foo < EY::CloudClient::ApiStruct.new(:id, :fruit, :veggie); end
5
5
 
6
6
  it "acts like a normal struct" do
7
7
  f = Foo.new(cloud_client, "fruit" => "banana")
@@ -16,7 +16,7 @@ describe EY::CloudClient::App do
16
16
  }
17
17
 
18
18
  FakeWeb.register_uri(:get, "https://cloud.engineyard.com/api/v2/apps?no_instances=true",
19
- :body => response.to_json, :content_type => "application/json")
19
+ :body => MultiJson.dump(response), :content_type => "application/json")
20
20
 
21
21
  apps = EY::CloudClient::App.all(cloud_client)
22
22
 
@@ -40,7 +40,7 @@ describe EY::CloudClient::App do
40
40
  }
41
41
 
42
42
  FakeWeb.register_uri(:post, "https://cloud.engineyard.com/api/v2/accounts/1234/apps",
43
- :body => response.to_json, :content_type => "application/json")
43
+ :body => MultiJson.dump(response), :content_type => "application/json")
44
44
 
45
45
  app = EY::CloudClient::App.create(cloud_client, {
46
46
  "account" => account,
@@ -36,7 +36,7 @@ describe EY::CloudClient::Environment do
36
36
  }
37
37
 
38
38
  FakeWeb.register_uri(:get, "https://cloud.engineyard.com/api/v2/environments?no_instances=true",
39
- :body => response.to_json, :content_type => "application/json")
39
+ :body => MultiJson.dump(response), :content_type => "application/json")
40
40
 
41
41
  environments = EY::CloudClient::Environment.all(cloud_client)
42
42
 
@@ -80,7 +80,7 @@ describe EY::CloudClient::Environment do
80
80
  "instance_status"=>"none"}}
81
81
 
82
82
  FakeWeb.register_uri(:post, "https://cloud.engineyard.com/api/v2/apps/12345/environments",
83
- :body => response.to_json, :content_type => "application/json")
83
+ :body => MultiJson.dump(response), :content_type => "application/json")
84
84
 
85
85
  env = EY::CloudClient::Environment.create(cloud_client, {
86
86
  "app" => app,
@@ -143,7 +143,7 @@ describe EY::CloudClient::Environment do
143
143
  "instance_status"=>"starting"}}
144
144
 
145
145
  FakeWeb.register_uri(:post, "https://cloud.engineyard.com/api/v2/apps/12345/environments",
146
- :body => response.to_json, :content_type => "application/json")
146
+ :body => MultiJson.dump(response), :content_type => "application/json")
147
147
 
148
148
  env = EY::CloudClient::Environment.create(cloud_client, {
149
149
  "app" => app,
@@ -218,7 +218,7 @@ describe EY::CloudClient::Environment do
218
218
 
219
219
  FakeWeb.register_uri(:get,
220
220
  "https://cloud.engineyard.com/api/v2/environments/#{env.id}/instances",
221
- :body => {"instances" => [instance_data]}.to_json,
221
+ :body => MultiJson.dump({"instances" => [instance_data]}),
222
222
  :content_type => 'application/json'
223
223
  )
224
224
 
data/spec/spec_helper.rb CHANGED
@@ -36,7 +36,6 @@ support.each{|helper| require helper }
36
36
  RSpec.configure do |config|
37
37
  config.treat_symbols_as_metadata_keys_with_true_values = true
38
38
  config.run_all_when_everything_filtered = true
39
- config.filter_run :focus
40
39
 
41
40
  config.include SpecHelpers
42
41
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: engineyard-cloud-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.8
4
+ version: 1.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-14 00:00:00.000000000 Z
12
+ date: 2013-02-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
@@ -251,6 +251,22 @@ dependencies:
251
251
  - - ! '>='
252
252
  - !ruby/object:Gem::Version
253
253
  version: '0'
254
+ - !ruby/object:Gem::Dependency
255
+ name: oj
256
+ requirement: !ruby/object:Gem::Requirement
257
+ none: false
258
+ requirements:
259
+ - - ! '>='
260
+ - !ruby/object:Gem::Version
261
+ version: '0'
262
+ type: :development
263
+ prerelease: false
264
+ version_requirements: !ruby/object:Gem::Requirement
265
+ none: false
266
+ requirements:
267
+ - - ! '>='
268
+ - !ruby/object:Gem::Version
269
+ version: '0'
254
270
  description: This gem connects to the EY Cloud API
255
271
  email: cloud@engineyard.com
256
272
  executables: []
@@ -338,7 +354,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
338
354
  version: '0'
339
355
  segments:
340
356
  - 0
341
- hash: -1071401773858451620
357
+ hash: -3697782236831721463
342
358
  required_rubygems_version: !ruby/object:Gem::Requirement
343
359
  none: false
344
360
  requirements:
@@ -347,7 +363,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
347
363
  version: '0'
348
364
  segments:
349
365
  - 0
350
- hash: -1071401773858451620
366
+ hash: -3697782236831721463
351
367
  requirements: []
352
368
  rubyforge_project:
353
369
  rubygems_version: 1.8.24