cfoundry 0.3.57 → 0.3.58

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/Rakefile CHANGED
@@ -14,6 +14,7 @@ end
14
14
 
15
15
  task :install => :build do
16
16
  sh "gem install --local cfoundry-#{CFoundry::VERSION}"
17
+ sh "rm cfoundry-#{CFoundry::VERSION}.gem"
17
18
  end
18
19
 
19
20
  task :uninstall do
@@ -328,7 +328,10 @@ module CFoundry
328
328
  end
329
329
 
330
330
  when Net::HTTPNotFound
331
- raise CFoundry::NotFound
331
+ raise CFoundry::NotFound(response.code, response.body)
332
+
333
+ when Net::HTTPForbidden
334
+ raise CFoundry::Denied.new(response.code, response.body)
332
335
 
333
336
  else
334
337
  raise CFoundry::BadResponse.new(response.code, response.body)
@@ -15,39 +15,42 @@ module CFoundry
15
15
  end
16
16
  end
17
17
 
18
+ class TargetRefused < Error
19
+ # Error message.
20
+ attr_reader :message
21
+
22
+ # Message varies as this represents various network errors.
23
+ def initialize(message)
24
+ @message = message
25
+ end
26
+
27
+ # Exception message.
28
+ def to_s
29
+ "target refused connection (#@message)"
30
+ end
31
+ end
32
+
33
+
18
34
  # Exception representing errors returned by the API.
19
35
  class APIError < RuntimeError
20
36
  class << self
21
- # Generic error code for the exception.
22
- attr_reader :error_code
23
-
24
- # Generic description for the exception.
25
- attr_reader :description
26
-
27
- private
37
+ def v2_classes
38
+ @v2_classes ||= {}
39
+ end
28
40
 
29
- def setup(code, description = nil)
30
- @error_code = code
31
- @description = description
41
+ def v1_classes
42
+ @v1_classes ||= {}
32
43
  end
33
44
  end
34
45
 
46
+ attr_reader :error_code, :description
47
+
35
48
  # Create an APIError with a given error code and description.
36
49
  def initialize(error_code = nil, description = nil)
37
50
  @error_code = error_code
38
51
  @description = description
39
52
  end
40
53
 
41
- # A number representing the error.
42
- def error_code
43
- @error_code || self.class.error_code
44
- end
45
-
46
- # A description of the error.
47
- def description
48
- @description || self.class.description
49
- end
50
-
51
54
  # Exception message.
52
55
  def to_s
53
56
  if error_code
@@ -58,65 +61,161 @@ module CFoundry
58
61
  end
59
62
  end
60
63
 
61
- # Generic exception thrown when accessing something that doesn't exist (e.g.
62
- # getting info of unknown application).
63
- class NotFound < APIError
64
- setup(404, "entity not found or inaccessible")
65
- end
64
+ class NotFound < APIError; end
66
65
 
67
- # Lower-level exception for when we cannot connect to the target.
68
- class TargetRefused < APIError
69
- @description = "target refused connection"
66
+ class Denied < APIError; end
70
67
 
71
- # Error message.
72
- attr_reader :message
68
+ class BadResponse < APIError; end
73
69
 
74
- # Message varies as this represents various network errors.
75
- def initialize(message)
76
- @message = message
77
- end
78
70
 
79
- # Exception message.
80
- def to_s
81
- "#{description} (#{@message})"
71
+ def self.define_error(class_name, v2_code, v1_code = nil)
72
+ base =
73
+ case class_name
74
+ when /NotFound$/
75
+ NotFound
76
+ else
77
+ APIError
78
+ end
79
+
80
+ klass = Class.new(base) do
81
+ define_method(:initialize) do |*args|
82
+ super
83
+ end
82
84
  end
83
- end
84
85
 
85
- # Exception raised when an application payload fails to upload.
86
- class UploadFailed < APIError
87
- setup(402)
86
+ APIError.v1_classes[v1_code] = klass if v1_code
87
+ APIError.v2_classes[v2_code] = klass if v2_code
88
+
89
+ const_set(class_name, klass)
88
90
  end
89
91
 
90
- # Exception raised when access is denied to something, either because the
91
- # user is not logged in or is not an administrator.
92
- class Denied < APIError
93
- # Specific error code.
94
- attr_reader :error_code
95
92
 
96
- # Specific description.
97
- attr_reader :description
93
+ [
94
+ ["InvalidAuthToken", 100],
98
95
 
99
- # Initialize, with a default error code and message.
100
- def initialize(
101
- error_code = 200,
102
- description = "Operation not permitted")
103
- @error_code = error_code
104
- @description = description
105
- end
106
- end
96
+ ["QuotaDeclined", 1000],
97
+ ["MessageParseError", 1001],
98
+ ["InvalidRelation", 1002],
107
99
 
108
- # Exception raised when the response is unexpected; usually from a server
109
- # error.
110
- class BadResponse < StandardError
111
- # Initialize, with the HTTP response code and body.
112
- def initialize(code, body = nil)
113
- @code = code
114
- @body = body
115
- end
100
+ ["UserInvalid", 20001],
101
+ ["UaaIdTaken", 20002],
102
+ ["UserNotFound", 20003, 201],
116
103
 
117
- # Exception message.
118
- def to_s
119
- "target failed to handle our request due to an internal error (#{@code})"
120
- end
104
+ ["OrganizationInvalid", 30001],
105
+ ["OrganizationNameTaken", 30002],
106
+ ["OrganizationNotFound", 30003],
107
+
108
+ ["SpaceInvalid", 40001],
109
+ ["SpaceNameTaken", 40002],
110
+ ["SpaceUserNotInOrg", 40003],
111
+ ["SpaceNotFound", 40004],
112
+
113
+ ["ServiceAuthTokenInvalid", 50001],
114
+ ["ServiceAuthTokenLabelTaken", 50002],
115
+ ["ServiceAuthTokenNotFound", 50003],
116
+
117
+ ["ServiceInstanceNameInvalid", 60001],
118
+ ["ServiceInstanceNameTaken", 60002],
119
+ ["ServiceInstanceServiceBindingWrongSpace", 60003],
120
+ ["ServiceInstanceInvalid", 60003],
121
+ ["ServiceInstanceNotFound", 60004],
122
+
123
+ ["RuntimeInvalid", 70001],
124
+ ["RuntimeNameTaken", 70002],
125
+ ["RuntimeNotFound", 70003],
126
+
127
+ ["FrameworkInvalid", 80001],
128
+ ["FrameworkNameTaken", 80002],
129
+ ["FrameworkNotFound", 80003],
130
+
131
+ ["ServiceBindingInvalid", 90001],
132
+ ["ServiceBindingDifferentSpaces", 90002],
133
+ ["ServiceBindingAppServiceTaken", 90003],
134
+ ["ServiceBindingNotFound", 90004],
135
+
136
+ ["AppInvalid", 100001, 300],
137
+ ["AppNameTaken", 100002],
138
+ ["AppNotFound", 100004, 301],
139
+
140
+ ["ServicePlanInvalid", 110001],
141
+ ["ServicePlanNameTaken", 110002],
142
+ ["ServicePlanNotFound", 110003],
143
+
144
+ ["ServiceInvalid", 120001],
145
+ ["ServiceLabelTaken", 120002],
146
+ ["ServiceNotFound", 120003, 500],
147
+
148
+ ["DomainInvalid", 130001],
149
+ ["DomainNotFound", 130002],
150
+ ["DomainNameTaken", 130003],
151
+
152
+ ["LegacyApiWithoutDefaultSpace", 140001],
153
+
154
+ ["AppPackageInvalid", 150001],
155
+ ["AppPackageNotFound", 150002],
156
+
157
+ ["AppBitsUploadInvalid", 160001],
158
+
159
+ ["StagingError", 170001],
160
+
161
+ ["SnapshotNotFound", 180001],
162
+ ["ServiceGatewayError", 180002, 503],
163
+ ["ServiceNotImplemented", 180003],
164
+ ["SDSNotAvailable", 180004],
165
+
166
+ ["FileError", 190001],
167
+
168
+ ["StatsError", 200001],
169
+
170
+ ["RouteInvalid", 210001],
171
+ ["RouteNotFound", 210002],
172
+ ["RouteHostTaken", 210003],
173
+
174
+ ["InstancesError", 220001],
175
+
176
+ ["BillingEventQueryInvalid", 230001],
177
+
178
+ # V1 Errors
179
+ ["BadRequest", nil, 100],
180
+ ["DatabaseError", nil, 101],
181
+ ["LockingError", nil, 102],
182
+ ["SystemError", nil, 111],
183
+
184
+ ["Forbidden", nil, 200],
185
+ ["HttpsRequired", nil, 202],
186
+
187
+ ["AppNoResources", nil, 302],
188
+ ["AppFileNotFound", nil, 303],
189
+ ["AppInstanceNotFound", nil, 304],
190
+ ["AppStopped", nil, 305],
191
+ ["AppFileError", nil, 306],
192
+ ["AppInvalidRuntime", nil, 307],
193
+ ["AppInvalidFramework", nil, 308],
194
+ ["AppDebugDisallowed", nil, 309],
195
+ ["AppStagingError", nil, 310],
196
+
197
+ ["ResourcesUnknownPackageType", nil, 400],
198
+ ["ResourcesMissingResource", nil, 401],
199
+ ["ResourcesPackagingFailed", nil, 402],
200
+
201
+ ["BindingNotFound", nil, 501],
202
+ ["TokenNotFound", nil, 502],
203
+ ["AccountTooManyServices", nil, 504],
204
+ ["ExtensionNotImpl", nil, 505],
205
+ ["UnsupportedVersion", nil, 506],
206
+ ["SdsError", nil, 507],
207
+ ["SdsNotFound", nil, 508],
208
+
209
+ ["AccountNotEnoughMemory", nil, 600],
210
+ ["AccountAppsTooMany", nil, 601],
211
+ ["AccountAppTooManyUris", nil, 602],
212
+
213
+ ["UriInvalid", nil, 700],
214
+ ["UriAlreadyTaken", nil, 701],
215
+ ["UriNotAllowed", nil, 702],
216
+ ["StagingTimedOut", nil, 800],
217
+ ["StagingFailed", nil, 801]
218
+ ].each do |args|
219
+ define_error(*args)
121
220
  end
122
221
  end
@@ -85,13 +85,6 @@ module CFoundry
85
85
  info = parse_json(response.body)
86
86
  raise CFoundry::Denied.new(response.code, info[:message])
87
87
 
88
- when Net::HTTPServerError
89
- begin
90
- raise_error(parse_json(response.body))
91
- rescue MultiJson::DecodeError
92
- raise BadResponse.new(response.code, response.body)
93
- end
94
-
95
88
  else
96
89
  raise BadResponse.new(response.code, response.body)
97
90
  end
@@ -96,11 +96,15 @@ module CFoundry::V1
96
96
  @diff = {}
97
97
  end
98
98
 
99
+ def invalidate!
100
+ @manifest = nil
101
+ end
102
+
99
103
  # Check if the application exists on the target.
100
104
  def exists?
101
105
  @client.base.app(@name)
102
106
  true
103
- rescue CFoundry::NotFound
107
+ rescue CFoundry::AppNotFound
104
108
  false
105
109
  end
106
110
 
@@ -169,31 +169,20 @@ module CFoundry::V1
169
169
  response.body
170
170
  end
171
171
 
172
- when Net::HTTPBadRequest, Net::HTTPForbidden
173
- info = parse_json(response.body)
174
- raise CFoundry::Denied.new(403, info[:description])
175
-
176
- when Net::HTTPNotFound
177
- raise CFoundry::NotFound
178
-
179
- when Net::HTTPServerError
172
+ when Net::HTTPBadRequest, Net::HTTPForbidden, Net::HTTPNotFound,
173
+ Net::HTTPInternalServerError, Net::HTTPNotImplemented,
174
+ Net::HTTPBadGateWay
180
175
  begin
181
- raise_error(parse_json(response.body))
176
+ info = parse_json(response.body)
177
+ cls = CFoundry::APIError.v1_classes[info[:code]]
178
+
179
+ raise (cls || CFoundry::APIError).new(info[:code], info[:description])
182
180
  rescue MultiJson::DecodeError
183
- raise CFoundry::BadResponse.new(response.code, response.body)
181
+ super
184
182
  end
185
183
 
186
184
  else
187
- raise CFoundry::BadResponse.new(response.code, response.body)
188
- end
189
- end
190
-
191
- def raise_error(info)
192
- case info[:code]
193
- when 402
194
- raise CFoundry::UploadFailed.new(info[:description])
195
- else
196
- raise CFoundry::APIError.new(info[:code], info[:description])
185
+ super
197
186
  end
198
187
  end
199
188
  end
@@ -136,8 +136,8 @@ module CFoundry::V1
136
136
  frameworks = []
137
137
  fs.each do |name, meta|
138
138
  runtimes = meta[:runtimes].collect do |r|
139
- Runtime.new(r[:name], r[:description], nil, meta[:version],
140
- meta[:status], meta[:series], meta[:category])
139
+ Runtime.new(r[:name], r[:description], nil, r[:version],
140
+ r[:status], r[:series], r[:category])
141
141
  end
142
142
 
143
143
  frameworks <<
@@ -63,7 +63,7 @@ module CFoundry::V1
63
63
  def exists?
64
64
  @client.base.service(@name)
65
65
  true
66
- rescue CFoundry::NotFound
66
+ rescue CFoundry::AppNotFound
67
67
  false
68
68
  end
69
69
 
@@ -55,6 +55,10 @@ module CFoundry::V1
55
55
  false
56
56
  end
57
57
 
58
+ def invalidate!
59
+ @manifest = nil
60
+ end
61
+
58
62
  # Check if the user is an administrator.
59
63
  def admin?
60
64
  manifest[:admin]
@@ -180,12 +180,14 @@ module CFoundry::V2
180
180
 
181
181
  # Stop the application.
182
182
  def stop!
183
- update! :state => "STOPPED"
183
+ self.state = "STOPPED"
184
+ update!
184
185
  end
185
186
 
186
187
  # Start the application.
187
188
  def start!
188
- update! :state => "STARTED"
189
+ self.state = "STARTED"
190
+ update!
189
191
  end
190
192
 
191
193
  # Restart the application.
@@ -235,7 +237,7 @@ module CFoundry::V2
235
237
  # Check that all application instances are running.
236
238
  def healthy?
237
239
  # invalidate cache so the check is fresh
238
- @manifest = nil
240
+ invalidate!
239
241
  health == "RUNNING"
240
242
  end
241
243
  alias_method :running?, :healthy?
@@ -59,7 +59,7 @@ module CFoundry::V2
59
59
  end
60
60
 
61
61
  define_method(:"delete_#{obj}") do |guid|
62
- delete("v2", plural, guid, nil => nil)
62
+ delete("v2", plural, guid)
63
63
  true
64
64
  end
65
65
 
@@ -131,7 +131,7 @@ module CFoundry::V2
131
131
  payload = paginated[:resources]
132
132
 
133
133
  while next_page = paginated[:next_url]
134
- paginated = request_path(:get, next_page, nil => :json)
134
+ paginated = request_path(Net::HTTP::Get, next_page, :accept => :json)
135
135
  payload += paginated[:resources]
136
136
  end
137
137
 
@@ -159,27 +159,19 @@ module CFoundry::V2
159
159
  response.body
160
160
  end
161
161
 
162
- when Net::HTTPBadRequest
163
- info = parse_json(response.body)
164
- raise CFoundry::APIError.new(info[:code], info[:description])
165
-
166
- when Net::HTTPUnauthorized, Net::HTTPForbidden
167
- info = parse_json(response.body)
168
- raise CFoundry::Denied.new(info[:code], info[:description])
169
-
170
- when Net::HTTPNotFound
171
- raise CFoundry::NotFound
172
-
173
- when Net::HTTPServerError
162
+ when Net::HTTPBadRequest, Net::HTTPUnauthorized, Net::HTTPNotFound,
163
+ Net::HTTPNotImplemented, Net::HTTPServiceUnavailable
174
164
  begin
175
165
  info = parse_json(response.body)
176
- raise CFoundry::APIError.new(info[:code], info[:description])
166
+ cls = CFoundry::APIError.v2_classes[info[:code]]
167
+
168
+ raise (cls || CFoundry::APIError).new(info[:code], info[:description])
177
169
  rescue MultiJson::DecodeError
178
- raise CFoundry::BadResponse.new(response.code, response.body)
170
+ super
179
171
  end
180
172
 
181
173
  else
182
- raise CFoundry::BadResponse.new(response.code, response.body)
174
+ super
183
175
  end
184
176
  end
185
177
 
@@ -343,12 +343,10 @@ module CFoundry::V2
343
343
  true
344
344
  end
345
345
 
346
- def update!(diff = {})
347
- diff = @diff.merge(diff)
346
+ def update!
347
+ @manifest = @client.base.send(:"update_#{object_name}", @guid, @diff)
348
348
 
349
- @manifest = @client.base.send(:"update_#{object_name}", @guid, diff)
350
-
351
- @diff.clear if diff == @diff
349
+ @diff.clear
352
350
 
353
351
  true
354
352
  end
@@ -370,7 +368,7 @@ module CFoundry::V2
370
368
  def exists?
371
369
  @client.base.send(object_name, @guid)
372
370
  true
373
- rescue CFoundry::APIError # TODO: NotFound would be better
371
+ rescue CFoundry::NotFound
374
372
  false
375
373
  end
376
374
 
@@ -9,5 +9,7 @@ module CFoundry::V2
9
9
  to_many :managers, :as => :user
10
10
  to_many :billing_managers, :as => :user
11
11
  to_many :auditors, :as => :user
12
+
13
+ has_summary
12
14
  end
13
15
  end
@@ -1,4 +1,4 @@
1
1
  module CFoundry # :nodoc:
2
2
  # CFoundry library version number.
3
- VERSION = "0.3.57"
3
+ VERSION = "0.3.58"
4
4
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cfoundry
3
3
  version: !ruby/object:Gem::Version
4
- hash: 97
4
+ hash: 103
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 57
10
- version: 0.3.57
9
+ - 58
10
+ version: 0.3.58
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alex Suraci
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-11-11 00:00:00 -08:00
18
+ date: 2012-11-13 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency