cfoundry 0.3.61 → 0.4.0
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/lib/cfoundry/client.rb +15 -0
- data/lib/cfoundry/errors.rb +45 -48
- data/lib/cfoundry/v1/base.rb +4 -2
- data/lib/cfoundry/v1/client.rb +11 -9
- data/lib/cfoundry/v1/runtime.rb +4 -19
- data/lib/cfoundry/v1/service.rb +11 -2
- data/lib/cfoundry/v2/app.rb +3 -0
- data/lib/cfoundry/v2/base.rb +3 -50
- data/lib/cfoundry/v2/client.rb +9 -118
- data/lib/cfoundry/v2/domain.rb +2 -0
- data/lib/cfoundry/v2/framework.rb +2 -0
- data/lib/cfoundry/v2/model.rb +9 -270
- data/lib/cfoundry/v2/model_magic.rb +434 -0
- data/lib/cfoundry/v2/organization.rb +3 -0
- data/lib/cfoundry/v2/route.rb +2 -0
- data/lib/cfoundry/v2/runtime.rb +2 -0
- data/lib/cfoundry/v2/service.rb +2 -0
- data/lib/cfoundry/v2/service_binding.rb +2 -0
- data/lib/cfoundry/v2/service_instance.rb +2 -0
- data/lib/cfoundry/v2/service_plan.rb +2 -0
- data/lib/cfoundry/v2/space.rb +2 -0
- data/lib/cfoundry/v2/user.rb +4 -0
- data/lib/cfoundry/version.rb +1 -1
- metadata +6 -5
data/lib/cfoundry/client.rb
CHANGED
@@ -1,6 +1,21 @@
|
|
1
1
|
require "cfoundry/baseclient"
|
2
2
|
|
3
3
|
require "cfoundry/v1/client"
|
4
|
+
|
5
|
+
require "cfoundry/v2/app"
|
6
|
+
require "cfoundry/v2/framework"
|
7
|
+
require "cfoundry/v2/organization"
|
8
|
+
require "cfoundry/v2/runtime"
|
9
|
+
require "cfoundry/v2/service"
|
10
|
+
require "cfoundry/v2/service_binding"
|
11
|
+
require "cfoundry/v2/service_instance"
|
12
|
+
require "cfoundry/v2/service_plan"
|
13
|
+
require "cfoundry/v2/service_auth_token"
|
14
|
+
require "cfoundry/v2/space"
|
15
|
+
require "cfoundry/v2/user"
|
16
|
+
require "cfoundry/v2/domain"
|
17
|
+
require "cfoundry/v2/route"
|
18
|
+
require "cfoundry/v2/base"
|
4
19
|
require "cfoundry/v2/client"
|
5
20
|
|
6
21
|
module CFoundry
|
data/lib/cfoundry/errors.rb
CHANGED
@@ -34,12 +34,8 @@ module CFoundry
|
|
34
34
|
# Exception representing errors returned by the API.
|
35
35
|
class APIError < RuntimeError
|
36
36
|
class << self
|
37
|
-
def
|
38
|
-
@
|
39
|
-
end
|
40
|
-
|
41
|
-
def v1_classes
|
42
|
-
@v1_classes ||= {}
|
37
|
+
def error_classes
|
38
|
+
@error_classes ||= {}
|
43
39
|
end
|
44
40
|
end
|
45
41
|
|
@@ -70,7 +66,7 @@ module CFoundry
|
|
70
66
|
class BadResponse < APIError; end
|
71
67
|
|
72
68
|
|
73
|
-
def self.define_error(class_name,
|
69
|
+
def self.define_error(class_name, *codes)
|
74
70
|
base =
|
75
71
|
case class_name
|
76
72
|
when /NotFound$/
|
@@ -81,8 +77,9 @@ module CFoundry
|
|
81
77
|
|
82
78
|
klass = Class.new(base)
|
83
79
|
|
84
|
-
|
85
|
-
|
80
|
+
codes.each do |code|
|
81
|
+
APIError.error_classes[code] = klass
|
82
|
+
end
|
86
83
|
|
87
84
|
const_set(class_name, klass)
|
88
85
|
end
|
@@ -174,45 +171,45 @@ module CFoundry
|
|
174
171
|
["BillingEventQueryInvalid", 230001],
|
175
172
|
|
176
173
|
# V1 Errors
|
177
|
-
["BadRequest",
|
178
|
-
["DatabaseError",
|
179
|
-
["LockingError",
|
180
|
-
["SystemError",
|
181
|
-
|
182
|
-
["Forbidden",
|
183
|
-
["HttpsRequired",
|
184
|
-
|
185
|
-
["AppNoResources",
|
186
|
-
["AppFileNotFound",
|
187
|
-
["AppInstanceNotFound",
|
188
|
-
["AppStopped",
|
189
|
-
["AppFileError",
|
190
|
-
["AppInvalidRuntime",
|
191
|
-
["AppInvalidFramework",
|
192
|
-
["AppDebugDisallowed",
|
193
|
-
["AppStagingError",
|
194
|
-
|
195
|
-
["ResourcesUnknownPackageType",
|
196
|
-
["ResourcesMissingResource",
|
197
|
-
["ResourcesPackagingFailed",
|
198
|
-
|
199
|
-
["BindingNotFound",
|
200
|
-
["TokenNotFound",
|
201
|
-
["AccountTooManyServices",
|
202
|
-
["ExtensionNotImpl",
|
203
|
-
["UnsupportedVersion",
|
204
|
-
["SdsError",
|
205
|
-
["SdsNotFound",
|
206
|
-
|
207
|
-
["AccountNotEnoughMemory",
|
208
|
-
["AccountAppsTooMany",
|
209
|
-
["AccountAppTooManyUris",
|
210
|
-
|
211
|
-
["UriInvalid",
|
212
|
-
["UriAlreadyTaken",
|
213
|
-
["UriNotAllowed",
|
214
|
-
["StagingTimedOut",
|
215
|
-
["StagingFailed",
|
174
|
+
["BadRequest", 100],
|
175
|
+
["DatabaseError", 101],
|
176
|
+
["LockingError", 102],
|
177
|
+
["SystemError", 111],
|
178
|
+
|
179
|
+
["Forbidden", 200],
|
180
|
+
["HttpsRequired", 202],
|
181
|
+
|
182
|
+
["AppNoResources", 302],
|
183
|
+
["AppFileNotFound", 303],
|
184
|
+
["AppInstanceNotFound", 304],
|
185
|
+
["AppStopped", 305],
|
186
|
+
["AppFileError", 306],
|
187
|
+
["AppInvalidRuntime", 307],
|
188
|
+
["AppInvalidFramework", 308],
|
189
|
+
["AppDebugDisallowed", 309],
|
190
|
+
["AppStagingError", 310],
|
191
|
+
|
192
|
+
["ResourcesUnknownPackageType", 400],
|
193
|
+
["ResourcesMissingResource", 401],
|
194
|
+
["ResourcesPackagingFailed", 402],
|
195
|
+
|
196
|
+
["BindingNotFound", 501],
|
197
|
+
["TokenNotFound", 502],
|
198
|
+
["AccountTooManyServices", 504],
|
199
|
+
["ExtensionNotImpl", 505],
|
200
|
+
["UnsupportedVersion", 506],
|
201
|
+
["SdsError", 507],
|
202
|
+
["SdsNotFound", 508],
|
203
|
+
|
204
|
+
["AccountNotEnoughMemory", 600],
|
205
|
+
["AccountAppsTooMany", 601],
|
206
|
+
["AccountAppTooManyUris", 602],
|
207
|
+
|
208
|
+
["UriInvalid", 700],
|
209
|
+
["UriAlreadyTaken", 701],
|
210
|
+
["UriNotAllowed", 702],
|
211
|
+
["StagingTimedOut", 800],
|
212
|
+
["StagingFailed", 801]
|
216
213
|
].each do |args|
|
217
214
|
define_error(*args)
|
218
215
|
end
|
data/lib/cfoundry/v1/base.rb
CHANGED
@@ -171,10 +171,12 @@ module CFoundry::V1
|
|
171
171
|
|
172
172
|
when Net::HTTPBadRequest, Net::HTTPForbidden, Net::HTTPNotFound,
|
173
173
|
Net::HTTPInternalServerError, Net::HTTPNotImplemented,
|
174
|
-
Net::
|
174
|
+
Net::HTTPBadGateway
|
175
175
|
begin
|
176
176
|
info = parse_json(response.body)
|
177
|
-
|
177
|
+
return super unless info[:code]
|
178
|
+
|
179
|
+
cls = CFoundry::APIError.error_classes[info[:code]]
|
178
180
|
|
179
181
|
raise (cls || CFoundry::APIError).new(info[:code], info[:description])
|
180
182
|
rescue MultiJson::DecodeError
|
data/lib/cfoundry/v1/client.rb
CHANGED
@@ -98,11 +98,15 @@ module CFoundry::V1
|
|
98
98
|
|
99
99
|
@base.system_services.each do |type, vendors|
|
100
100
|
vendors.each do |vendor, providers|
|
101
|
-
providers.each do |provider,
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
101
|
+
providers.each do |provider, properties|
|
102
|
+
properties.each do |_, meta|
|
103
|
+
meta[:supported_versions].each do |ver|
|
104
|
+
state = meta[:version_aliases].find { |k, v| v == ver }
|
105
|
+
|
106
|
+
services <<
|
107
|
+
Service.new(vendor.to_s, ver.to_s, meta[:description],
|
108
|
+
type, provider.to_s, state && state.first)
|
109
|
+
end
|
106
110
|
end
|
107
111
|
end
|
108
112
|
end
|
@@ -117,8 +121,7 @@ module CFoundry::V1
|
|
117
121
|
|
118
122
|
@base.system_runtimes.each do |name, meta|
|
119
123
|
runtimes <<
|
120
|
-
Runtime.new(name.to_s, meta[:
|
121
|
-
meta[:version], meta[:status], meta[:series], meta[:category])
|
124
|
+
Runtime.new(name.to_s, meta[:version], meta[:debug_modes])
|
122
125
|
end
|
123
126
|
|
124
127
|
runtimes
|
@@ -136,8 +139,7 @@ module CFoundry::V1
|
|
136
139
|
frameworks = []
|
137
140
|
fs.each do |name, meta|
|
138
141
|
runtimes = meta[:runtimes].collect do |r|
|
139
|
-
Runtime.new(r[:name], r[:description]
|
140
|
-
r[:status], r[:series], r[:category])
|
142
|
+
Runtime.new(r[:name], r[:description])
|
141
143
|
end
|
142
144
|
|
143
145
|
frameworks <<
|
data/lib/cfoundry/v1/runtime.rb
CHANGED
@@ -1,18 +1,11 @@
|
|
1
1
|
module CFoundry::V1
|
2
2
|
class Runtime
|
3
|
-
attr_accessor :name, :description, :debug_modes
|
4
|
-
:version, :status, :series, :category
|
3
|
+
attr_accessor :name, :description, :debug_modes
|
5
4
|
|
6
|
-
def initialize(name, description = nil, debug_modes = nil
|
7
|
-
version = nil, status = nil, series = nil,
|
8
|
-
category = nil)
|
5
|
+
def initialize(name, description = nil, debug_modes = nil)
|
9
6
|
@name = name
|
10
7
|
@description = description
|
11
8
|
@debug_modes = debug_modes
|
12
|
-
@version = version
|
13
|
-
@status = status
|
14
|
-
@series = series
|
15
|
-
@category = category
|
16
9
|
end
|
17
10
|
|
18
11
|
def eql?(other)
|
@@ -24,16 +17,8 @@ module CFoundry::V1
|
|
24
17
|
[] # not supported by v1
|
25
18
|
end
|
26
19
|
|
27
|
-
def
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
def next?
|
32
|
-
status && status[:name] == "next"
|
33
|
-
end
|
34
|
-
|
35
|
-
def current?
|
36
|
-
status.nil? || status[:name] == "current"
|
20
|
+
def debug_modes
|
21
|
+
@debug_modes || []
|
37
22
|
end
|
38
23
|
end
|
39
24
|
end
|
data/lib/cfoundry/v1/service.rb
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
module CFoundry::V1
|
2
2
|
class Service
|
3
|
-
attr_accessor :label, :version, :description, :type, :provider
|
3
|
+
attr_accessor :label, :version, :description, :type, :provider, :state
|
4
4
|
|
5
5
|
def initialize(label, version = nil, description = nil,
|
6
|
-
type = nil, provider = "core")
|
6
|
+
type = nil, provider = "core", state = nil)
|
7
7
|
@label = label
|
8
8
|
@description = description
|
9
9
|
@version = version
|
10
10
|
@type = type
|
11
11
|
@provider = provider
|
12
|
+
@state = state
|
12
13
|
end
|
13
14
|
|
14
15
|
def eql?(other)
|
@@ -19,5 +20,13 @@ module CFoundry::V1
|
|
19
20
|
def active
|
20
21
|
true
|
21
22
|
end
|
23
|
+
|
24
|
+
def deprecated?
|
25
|
+
@state == :deprecated
|
26
|
+
end
|
27
|
+
|
28
|
+
def current?
|
29
|
+
@state == :current
|
30
|
+
end
|
22
31
|
end
|
23
32
|
end
|
data/lib/cfoundry/v2/app.rb
CHANGED
@@ -35,6 +35,9 @@ module CFoundry::V2
|
|
35
35
|
|
36
36
|
scoped_to_space
|
37
37
|
|
38
|
+
queryable_by :name, :space_guid, :organization_guid, :framework_guid,
|
39
|
+
:runtime_guid
|
40
|
+
|
38
41
|
has_summary :urls => proc { |x| self.cache[:uris] = x },
|
39
42
|
:running_instances => proc { |x|
|
40
43
|
self.cache[:running_instances] = x
|
data/lib/cfoundry/v2/base.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require "multi_json"
|
2
|
-
require "base64"
|
3
2
|
|
4
3
|
require "cfoundry/baseclient"
|
5
4
|
require "cfoundry/uaaclient"
|
@@ -8,6 +7,8 @@ require "cfoundry/errors"
|
|
8
7
|
|
9
8
|
module CFoundry::V2
|
10
9
|
class Base < CFoundry::BaseClient
|
10
|
+
include BaseClientMethods
|
11
|
+
|
11
12
|
attr_accessor :target, :token, :proxy, :trace, :backtrace, :log
|
12
13
|
|
13
14
|
def initialize(
|
@@ -38,41 +39,6 @@ module CFoundry::V2
|
|
38
39
|
get("info", :accept => :json)
|
39
40
|
end
|
40
41
|
|
41
|
-
|
42
|
-
[ :app, :organization, :space, :user, :runtime, :framework, :service,
|
43
|
-
:domain, :route, :service_plan, :service_binding, :service_instance,
|
44
|
-
:service_auth_token
|
45
|
-
].each do |obj|
|
46
|
-
plural = "#{obj}s"
|
47
|
-
|
48
|
-
define_method(obj) do |guid, *args|
|
49
|
-
depth, _ = args
|
50
|
-
depth ||= 1
|
51
|
-
|
52
|
-
params = { :"inline-relations-depth" => depth }
|
53
|
-
|
54
|
-
get("v2", plural, guid, :accept => :json, :params => params)
|
55
|
-
end
|
56
|
-
|
57
|
-
define_method(:"create_#{obj}") do |payload|
|
58
|
-
post(payload, "v2", plural, :content => :json, :accept => :json)
|
59
|
-
end
|
60
|
-
|
61
|
-
define_method(:"delete_#{obj}") do |guid|
|
62
|
-
delete("v2", plural, guid)
|
63
|
-
true
|
64
|
-
end
|
65
|
-
|
66
|
-
define_method(:"update_#{obj}") do |guid, payload|
|
67
|
-
put(payload, "v2", plural, guid, :content => :json, :accept => :json)
|
68
|
-
end
|
69
|
-
|
70
|
-
define_method(plural) do |*args|
|
71
|
-
all_pages(
|
72
|
-
get("v2", plural, :accept => :json, :params => params_from(args)))
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
42
|
def resource_match(fingerprints)
|
77
43
|
put(fingerprints, "v2", "resource_match",
|
78
44
|
:content => :json, :accept => :json)
|
@@ -139,19 +105,6 @@ module CFoundry::V2
|
|
139
105
|
end
|
140
106
|
|
141
107
|
|
142
|
-
def params_from(args)
|
143
|
-
depth, query = args
|
144
|
-
depth ||= 1
|
145
|
-
|
146
|
-
params = { :"inline-relations-depth" => depth }
|
147
|
-
|
148
|
-
if query
|
149
|
-
params[:q] = "#{query.keys.first}:#{query.values.first}"
|
150
|
-
end
|
151
|
-
|
152
|
-
params
|
153
|
-
end
|
154
|
-
|
155
108
|
def all_pages(paginated)
|
156
109
|
payload = paginated[:resources]
|
157
110
|
|
@@ -190,7 +143,7 @@ module CFoundry::V2
|
|
190
143
|
info = parse_json(response.body)
|
191
144
|
return super unless info[:code]
|
192
145
|
|
193
|
-
cls = CFoundry::APIError.
|
146
|
+
cls = CFoundry::APIError.error_classes[info[:code]]
|
194
147
|
|
195
148
|
raise (cls || CFoundry::APIError).new(info[:code], info[:description])
|
196
149
|
rescue MultiJson::DecodeError
|
data/lib/cfoundry/v2/client.rb
CHANGED
@@ -1,27 +1,10 @@
|
|
1
|
-
require "multi_json"
|
2
|
-
require "base64"
|
3
|
-
|
4
|
-
require "cfoundry/v2/base"
|
5
|
-
|
6
|
-
require "cfoundry/v2/app"
|
7
|
-
require "cfoundry/v2/framework"
|
8
|
-
require "cfoundry/v2/organization"
|
9
|
-
require "cfoundry/v2/runtime"
|
10
|
-
require "cfoundry/v2/service"
|
11
|
-
require "cfoundry/v2/service_binding"
|
12
|
-
require "cfoundry/v2/service_instance"
|
13
|
-
require "cfoundry/v2/service_plan"
|
14
|
-
require "cfoundry/v2/service_auth_token"
|
15
|
-
require "cfoundry/v2/space"
|
16
|
-
require "cfoundry/v2/user"
|
17
|
-
require "cfoundry/v2/domain"
|
18
|
-
require "cfoundry/v2/route"
|
19
|
-
|
20
1
|
module CFoundry::V2
|
21
2
|
# The primary API entrypoint. Wraps a BaseClient to provide nicer return
|
22
3
|
# values. Initialize with the target and, optionally, an auth token. These
|
23
4
|
# are the only two internal states.
|
24
5
|
class Client
|
6
|
+
include ClientMethods
|
7
|
+
|
25
8
|
# Internal BaseClient instance. Normally won't be touching this.
|
26
9
|
attr_reader :base
|
27
10
|
|
@@ -147,105 +130,13 @@ module CFoundry::V2
|
|
147
130
|
!!@base.token
|
148
131
|
end
|
149
132
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
classname = singular.to_s.capitalize.gsub(/(.)_(.)/) do
|
158
|
-
$1 + $2.upcase
|
159
|
-
end
|
160
|
-
|
161
|
-
klass = CFoundry::V2.const_get(classname)
|
162
|
-
|
163
|
-
scoped_organization = klass.scoped_organization
|
164
|
-
scoped_space = klass.scoped_space
|
165
|
-
|
166
|
-
has_name = klass.method_defined? :name
|
167
|
-
|
168
|
-
define_method(singular) do |*args|
|
169
|
-
guid, partial, _ = args
|
170
|
-
|
171
|
-
x = klass.new(guid, self, nil, partial)
|
172
|
-
|
173
|
-
# when creating an object, automatically set the org/space
|
174
|
-
unless guid
|
175
|
-
if scoped_organization && current_organization
|
176
|
-
x.send(:"#{scoped_organization}=", current_organization)
|
177
|
-
end
|
178
|
-
|
179
|
-
if scoped_space && current_space
|
180
|
-
x.send(:"#{scoped_space}=", current_space)
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
x
|
185
|
-
end
|
186
|
-
|
187
|
-
define_method(plural) do |*args|
|
188
|
-
depth, query = args
|
189
|
-
depth ||= 1
|
190
|
-
|
191
|
-
# use current org/space
|
192
|
-
if scoped_space && current_space
|
193
|
-
query ||= {}
|
194
|
-
query[:"#{scoped_space}_guid"] ||= current_space.guid
|
195
|
-
elsif scoped_organization && current_organization
|
196
|
-
query ||= {}
|
197
|
-
query[:"#{scoped_organization}_guid"] ||= current_organization.guid
|
198
|
-
end
|
199
|
-
|
200
|
-
@base.send(plural, depth, query).collect do |json|
|
201
|
-
send(:"make_#{singular}", json)
|
202
|
-
end
|
203
|
-
end
|
204
|
-
|
205
|
-
if has_name
|
206
|
-
define_method(:"#{singular}_by_name") do |name, *args|
|
207
|
-
depth, _ = args
|
208
|
-
depth ||= 1
|
209
|
-
|
210
|
-
# use current org/space
|
211
|
-
if scoped_space && current_space
|
212
|
-
current_space.send(plural, depth, :name => name).first
|
213
|
-
elsif scoped_organization && current_organization
|
214
|
-
current_organization.send(plural, depth, :name => name).first
|
215
|
-
else
|
216
|
-
send(plural, depth, :name => name).first
|
217
|
-
end
|
218
|
-
end
|
219
|
-
end
|
220
|
-
|
221
|
-
define_method(:"#{singular}_from") do |path, *args|
|
222
|
-
send(
|
223
|
-
:"make_#{singular}",
|
224
|
-
@base.request_path(
|
225
|
-
Net::HTTP::Get,
|
226
|
-
path,
|
227
|
-
:accept => :json,
|
228
|
-
:params => @base.params_from(args)))
|
229
|
-
end
|
230
|
-
|
231
|
-
define_method(:"#{plural}_from") do |path, *args|
|
232
|
-
objs = @base.all_pages(
|
233
|
-
@base.request_path(
|
234
|
-
Net::HTTP::Get,
|
235
|
-
path,
|
236
|
-
:accept => :json,
|
237
|
-
:params => @base.params_from(args)))
|
238
|
-
|
239
|
-
objs.collect do |json|
|
240
|
-
send(:"make_#{singular}", json)
|
241
|
-
end
|
242
|
-
end
|
243
|
-
|
244
|
-
define_method(:"make_#{singular}") do |json|
|
245
|
-
klass.new(
|
246
|
-
json[:metadata][:guid],
|
247
|
-
self,
|
248
|
-
json)
|
133
|
+
def query_target(klass)
|
134
|
+
if klass.scoped_space && space = current_space
|
135
|
+
space
|
136
|
+
elsif klass.scoped_organization && org = current_org
|
137
|
+
org
|
138
|
+
else
|
139
|
+
self
|
249
140
|
end
|
250
141
|
end
|
251
142
|
end
|