cloulu 0.0.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (152) hide show
  1. data/bin/{cloulu → cl} +0 -0
  2. data/lib/cc_api_stub/applications.rb +53 -0
  3. data/lib/cc_api_stub/domains.rb +16 -0
  4. data/lib/cc_api_stub/frameworks.rb +22 -0
  5. data/lib/cc_api_stub/helper.rb +131 -0
  6. data/lib/cc_api_stub/login.rb +21 -0
  7. data/lib/cc_api_stub/organization_users.rb +21 -0
  8. data/lib/cc_api_stub/organizations.rb +70 -0
  9. data/lib/cc_api_stub/routes.rb +26 -0
  10. data/lib/cc_api_stub/runtimes.rb +22 -0
  11. data/lib/cc_api_stub/service_bindings.rb +22 -0
  12. data/lib/cc_api_stub/service_instances.rb +22 -0
  13. data/lib/cc_api_stub/services.rb +25 -0
  14. data/lib/cc_api_stub/spaces.rb +49 -0
  15. data/lib/cc_api_stub/users.rb +84 -0
  16. data/lib/cc_api_stub.rb +17 -0
  17. data/lib/cfoundry/auth_token.rb +63 -0
  18. data/lib/cfoundry/baseclient.rb +201 -0
  19. data/lib/cfoundry/chatty_hash.rb +46 -0
  20. data/lib/cfoundry/client.rb +46 -0
  21. data/lib/cfoundry/concerns/login_helpers.rb +13 -0
  22. data/lib/cfoundry/errors.rb +160 -0
  23. data/lib/cfoundry/rest_client.rb +299 -0
  24. data/lib/cfoundry/test_support.rb +3 -0
  25. data/lib/cfoundry/trace_helpers.rb +40 -0
  26. data/lib/cfoundry/uaaclient.rb +112 -0
  27. data/lib/cfoundry/upload_helpers.rb +187 -0
  28. data/lib/cfoundry/v1/app.rb +363 -0
  29. data/lib/cfoundry/v1/base.rb +72 -0
  30. data/lib/cfoundry/v1/client.rb +193 -0
  31. data/lib/cfoundry/v1/framework.rb +21 -0
  32. data/lib/cfoundry/v1/model.rb +178 -0
  33. data/lib/cfoundry/v1/model_magic.rb +129 -0
  34. data/lib/cfoundry/v1/runtime.rb +24 -0
  35. data/lib/cfoundry/v1/service.rb +39 -0
  36. data/lib/cfoundry/v1/service_instance.rb +32 -0
  37. data/lib/cfoundry/v1/service_plan.rb +19 -0
  38. data/lib/cfoundry/v1/user.rb +22 -0
  39. data/lib/cfoundry/v2/app.rb +392 -0
  40. data/lib/cfoundry/v2/base.rb +83 -0
  41. data/lib/cfoundry/v2/client.rb +138 -0
  42. data/lib/cfoundry/v2/domain.rb +11 -0
  43. data/lib/cfoundry/v2/framework.rb +14 -0
  44. data/lib/cfoundry/v2/model.rb +148 -0
  45. data/lib/cfoundry/v2/model_magic.rb +449 -0
  46. data/lib/cfoundry/v2/organization.rb +16 -0
  47. data/lib/cfoundry/v2/route.rb +15 -0
  48. data/lib/cfoundry/v2/runtime.rb +12 -0
  49. data/lib/cfoundry/v2/service.rb +19 -0
  50. data/lib/cfoundry/v2/service_auth_token.rb +9 -0
  51. data/lib/cfoundry/v2/service_binding.rb +10 -0
  52. data/lib/cfoundry/v2/service_instance.rb +14 -0
  53. data/lib/cfoundry/v2/service_plan.rb +12 -0
  54. data/lib/cfoundry/v2/space.rb +18 -0
  55. data/lib/cfoundry/v2/user.rb +64 -0
  56. data/lib/cfoundry/validator.rb +39 -0
  57. data/lib/cfoundry/version.rb +4 -0
  58. data/lib/cfoundry/zip.rb +56 -0
  59. data/lib/cfoundry.rb +2 -0
  60. data/lib/manifests-vmc-plugin/errors.rb +21 -0
  61. data/lib/manifests-vmc-plugin/loader/builder.rb +34 -0
  62. data/lib/manifests-vmc-plugin/loader/normalizer.rb +149 -0
  63. data/lib/manifests-vmc-plugin/loader/resolver.rb +79 -0
  64. data/lib/manifests-vmc-plugin/loader.rb +31 -0
  65. data/lib/manifests-vmc-plugin/plugin.rb +145 -0
  66. data/lib/manifests-vmc-plugin/version.rb +3 -0
  67. data/lib/manifests-vmc-plugin.rb +313 -0
  68. data/lib/mothership/base.rb +99 -0
  69. data/lib/mothership/callbacks.rb +85 -0
  70. data/lib/mothership/command.rb +146 -0
  71. data/lib/mothership/errors.rb +38 -0
  72. data/lib/mothership/help/commands.rb +53 -0
  73. data/lib/mothership/help/printer.rb +170 -0
  74. data/lib/mothership/help.rb +64 -0
  75. data/lib/mothership/inputs.rb +189 -0
  76. data/lib/mothership/parser.rb +182 -0
  77. data/lib/mothership/version.rb +3 -0
  78. data/lib/mothership.rb +64 -0
  79. data/lib/tunnel-vmc-plugin/plugin.rb +178 -0
  80. data/lib/tunnel-vmc-plugin/tunnel.rb +308 -0
  81. data/lib/tunnel-vmc-plugin/version.rb +3 -0
  82. data/lib/uaa/http.rb +168 -0
  83. data/lib/uaa/misc.rb +121 -0
  84. data/lib/uaa/scim.rb +292 -0
  85. data/lib/uaa/token_coder.rb +196 -0
  86. data/lib/uaa/token_issuer.rb +255 -0
  87. data/lib/uaa/util.rb +235 -0
  88. data/lib/uaa/version.rb +19 -0
  89. data/lib/uaa.rb +18 -0
  90. data/lib/vmc/cli/app/app.rb +45 -0
  91. data/lib/vmc/cli/app/apps.rb +99 -0
  92. data/lib/vmc/cli/app/base.rb +90 -0
  93. data/lib/vmc/cli/app/crashes.rb +42 -0
  94. data/lib/vmc/cli/app/delete.rb +95 -0
  95. data/lib/vmc/cli/app/deprecated.rb +11 -0
  96. data/lib/vmc/cli/app/env.rb +78 -0
  97. data/lib/vmc/cli/app/files.rb +137 -0
  98. data/lib/vmc/cli/app/health.rb +26 -0
  99. data/lib/vmc/cli/app/instances.rb +53 -0
  100. data/lib/vmc/cli/app/logs.rb +76 -0
  101. data/lib/vmc/cli/app/push/create.rb +165 -0
  102. data/lib/vmc/cli/app/push/interactions.rb +94 -0
  103. data/lib/vmc/cli/app/push/sync.rb +64 -0
  104. data/lib/vmc/cli/app/push.rb +109 -0
  105. data/lib/vmc/cli/app/rename.rb +35 -0
  106. data/lib/vmc/cli/app/restart.rb +20 -0
  107. data/lib/vmc/cli/app/scale.rb +71 -0
  108. data/lib/vmc/cli/app/start.rb +143 -0
  109. data/lib/vmc/cli/app/stats.rb +67 -0
  110. data/lib/vmc/cli/app/stop.rb +27 -0
  111. data/lib/vmc/cli/help.rb +11 -0
  112. data/lib/vmc/cli/interactive.rb +105 -0
  113. data/lib/vmc/cli/route/base.rb +12 -0
  114. data/lib/vmc/cli/route/map.rb +82 -0
  115. data/lib/vmc/cli/route/routes.rb +25 -0
  116. data/lib/vmc/cli/route/unmap.rb +94 -0
  117. data/lib/vmc/cli/service/base.rb +8 -0
  118. data/lib/vmc/cli/service/bind.rb +44 -0
  119. data/lib/vmc/cli/service/create.rb +126 -0
  120. data/lib/vmc/cli/service/delete.rb +86 -0
  121. data/lib/vmc/cli/service/rename.rb +35 -0
  122. data/lib/vmc/cli/service/service.rb +42 -0
  123. data/lib/vmc/cli/service/services.rb +114 -0
  124. data/lib/vmc/cli/service/unbind.rb +38 -0
  125. data/lib/vmc/cli/start/base.rb +94 -0
  126. data/lib/vmc/cli/start/colors.rb +13 -0
  127. data/lib/vmc/cli/start/info.rb +126 -0
  128. data/lib/vmc/cli/start/login.rb +97 -0
  129. data/lib/vmc/cli/start/logout.rb +17 -0
  130. data/lib/vmc/cli/start/target.rb +60 -0
  131. data/lib/vmc/cli/start/target_interactions.rb +37 -0
  132. data/lib/vmc/cli/start/targets.rb +16 -0
  133. data/lib/vmc/cli/user/base.rb +29 -0
  134. data/lib/vmc/cli/user/create.rb +39 -0
  135. data/lib/vmc/cli/user/delete.rb +27 -0
  136. data/lib/vmc/cli/user/passwd.rb +50 -0
  137. data/lib/vmc/cli/user/register.rb +42 -0
  138. data/lib/vmc/cli/user/users.rb +32 -0
  139. data/lib/vmc/cli/v2_check_cli.rb +16 -0
  140. data/lib/vmc/cli.rb +474 -0
  141. data/lib/vmc/constants.rb +13 -0
  142. data/lib/vmc/detect.rb +129 -0
  143. data/lib/vmc/errors.rb +19 -0
  144. data/lib/vmc/plugin.rb +56 -0
  145. data/lib/vmc/spacing.rb +89 -0
  146. data/lib/vmc/spec_helper.rb +1 -0
  147. data/lib/vmc/test_support.rb +6 -0
  148. data/lib/vmc/version.rb +3 -0
  149. data/lib/vmc.rb +8 -0
  150. data/vendor/errors/v1.yml +189 -0
  151. data/vendor/errors/v2.yml +360 -0
  152. metadata +303 -190
@@ -0,0 +1,148 @@
1
+ require "multi_json"
2
+
3
+ require "cfoundry/v2/model_magic"
4
+
5
+
6
+ module CFoundry::V2
7
+ class Model
8
+ @@objects = {}
9
+
10
+ extend ModelMagic
11
+
12
+ class << self
13
+ def objects
14
+ @@objects
15
+ end
16
+
17
+ def inherited(klass)
18
+ @@objects[klass.object_name] = klass
19
+ super
20
+ end
21
+ end
22
+
23
+ attr_accessor :guid, :cache, :changes
24
+
25
+ def initialize(guid, client, manifest = nil, partial = false)
26
+ @guid = guid
27
+ @client = client
28
+ @manifest = manifest
29
+ @partial = partial
30
+ @cache = {}
31
+ @diff = {}
32
+ @changes = {}
33
+ end
34
+
35
+ def manifest
36
+ @manifest ||= @client.base.send(object_name, @guid)
37
+ end
38
+
39
+ def partial?
40
+ @partial
41
+ end
42
+
43
+ def changed?
44
+ !@changes.empty?
45
+ end
46
+
47
+ def inspect
48
+ "\#<#{self.class.name} '#@guid'>"
49
+ end
50
+
51
+ def object_name
52
+ @object_name ||= self.class.object_name
53
+ end
54
+
55
+ def plural_object_name
56
+ @plural_object_name ||= self.class.plural_object_name
57
+ end
58
+
59
+ def invalidate!
60
+ @manifest = nil
61
+ @partial = false
62
+ @cache = {}
63
+ @diff = {}
64
+ @changes = {}
65
+ end
66
+
67
+ # this does a bit of extra processing to allow for
68
+ # `delete!' followed by `create!'
69
+ def create!
70
+ payload = {}
71
+
72
+ @manifest ||= {}
73
+ @manifest[:entity] ||= {}
74
+
75
+ @manifest[:entity].each do |k, v|
76
+ if v.is_a?(Hash) && v.key?(:metadata)
77
+ # skip; there's a _guid attribute already
78
+ elsif v.is_a?(Array) && !v.empty? && v.all? { |x|
79
+ x.is_a?(Hash) && x.key?(:metadata)
80
+ }
81
+ singular = k.to_s.sub(/s$/, "")
82
+
83
+ payload[:"#{singular}_guids"] = v.collect do |x|
84
+ if x.is_a?(Hash) && x.key?(:metadata)
85
+ x[:metadata][:guid]
86
+ else
87
+ x
88
+ end
89
+ end
90
+ elsif k.to_s.end_with?("_url")
91
+ else
92
+ payload[k] = v
93
+ end
94
+ end
95
+
96
+ @manifest = @client.base.send(:"create_#{object_name}", payload)
97
+
98
+ @guid = @manifest[:metadata][:guid]
99
+
100
+ @diff.clear
101
+
102
+ true
103
+ end
104
+
105
+ def update!
106
+ @manifest = @client.base.send(:"update_#{object_name}", @guid, @diff)
107
+
108
+ @diff.clear
109
+
110
+ true
111
+ end
112
+
113
+ def delete!
114
+ @client.base.send(:"delete_#{object_name}", @guid)
115
+
116
+ @guid = nil
117
+
118
+ @diff.clear
119
+
120
+ if @manifest
121
+ @manifest.delete :metadata
122
+ end
123
+
124
+ true
125
+ end
126
+
127
+ def exists?
128
+ invalidate!
129
+ manifest
130
+ true
131
+ rescue CFoundry::NotFound
132
+ false
133
+ end
134
+
135
+ def query_target(klass)
136
+ self
137
+ end
138
+
139
+ def eql?(other)
140
+ other.is_a?(self.class) && @guid == other.guid
141
+ end
142
+ alias :== :eql?
143
+
144
+ def hash
145
+ @guid.hash
146
+ end
147
+ end
148
+ end
@@ -0,0 +1,449 @@
1
+ require "cfoundry/validator"
2
+
3
+ module CFoundry::V2
4
+ # object name -> module containing query methods
5
+ #
6
+ # e.g. app -> { app_by_name, app_by_space_guid, ... }
7
+ QUERIES = Hash.new do |h, k|
8
+ h[k] = Module.new
9
+ end
10
+
11
+ module BaseClientMethods
12
+ end
13
+
14
+ module ClientMethods
15
+ end
16
+
17
+ module ModelMagic
18
+ attr_reader :scoped_organization, :scoped_space
19
+
20
+ def object_name
21
+ @object_name ||=
22
+ name.split("::").last.gsub(
23
+ /([a-z])([A-Z])/,
24
+ '\1_\2').downcase.to_sym
25
+ end
26
+
27
+ def plural_object_name
28
+ :"#{object_name}s"
29
+ end
30
+
31
+ def define_client_methods(&blk)
32
+ ClientMethods.module_eval(&blk)
33
+ end
34
+
35
+ def define_base_client_methods(&blk)
36
+ BaseClientMethods.module_eval(&blk)
37
+ end
38
+
39
+ def defaults
40
+ @defaults ||= {}
41
+ end
42
+
43
+ def attributes
44
+ @attributes ||= {}
45
+ end
46
+
47
+ def to_one_relations
48
+ @to_one_relations ||= {}
49
+ end
50
+
51
+ def to_many_relations
52
+ @to_many_relations ||= {}
53
+ end
54
+
55
+ def inherited(klass)
56
+ singular = klass.object_name
57
+ plural = klass.plural_object_name
58
+
59
+ define_base_client_methods do
60
+ define_method(singular) do |guid, *args|
61
+ get("v2", plural, guid, :accept => :json,
62
+ :params => ModelMagic.params_from(args))
63
+ end
64
+
65
+ define_method(:"create_#{singular}") do |payload|
66
+ post("v2", plural, :content => :json, :accept => :json, :payload => payload)
67
+ end
68
+
69
+ define_method(:"delete_#{singular}") do |guid|
70
+ delete("v2", plural, guid)
71
+ true
72
+ end
73
+
74
+ define_method(:"update_#{singular}") do |guid, payload|
75
+ put("v2", plural, guid, :content => :json, :accept => :json, :payload => payload)
76
+ end
77
+
78
+ define_method(plural) do |*args|
79
+ all_pages(
80
+ get("v2", plural, :accept => :json,
81
+ :params => ModelMagic.params_from(args)))
82
+ end
83
+ end
84
+
85
+ define_client_methods do
86
+ define_method(singular) do |*args|
87
+ guid, partial, _ = args
88
+
89
+ x = klass.new(guid, self, nil, partial)
90
+
91
+ # when creating an object, automatically set the org/space
92
+ unless guid
93
+ if klass.scoped_organization && current_organization
94
+ x.send(:"#{klass.scoped_organization}=", current_organization)
95
+ end
96
+
97
+ if klass.scoped_space && current_space
98
+ x.send(:"#{klass.scoped_space}=", current_space)
99
+ end
100
+ end
101
+
102
+ x
103
+ end
104
+
105
+ define_method(plural) do |*args|
106
+ # use current org/space
107
+ if klass.scoped_space && current_space
108
+ current_space.send(plural, *args)
109
+ elsif klass.scoped_organization && current_organization
110
+ current_organization.send(plural, *args)
111
+ else
112
+ @base.send(plural, *args).collect do |json|
113
+ send(:"make_#{singular}", json)
114
+ end
115
+ end
116
+ end
117
+
118
+ define_method(:"#{singular}_from") do |path, *args|
119
+ send(
120
+ :"make_#{singular}",
121
+ @base.get(
122
+ path,
123
+ :accept => :json,
124
+ :params => ModelMagic.params_from(args)))
125
+ end
126
+
127
+ define_method(:"#{plural}_from") do |path, *args|
128
+ objs = @base.all_pages(
129
+ @base.get(
130
+ path,
131
+ :accept => :json,
132
+ :params => ModelMagic.params_from(args)))
133
+
134
+ objs.collect do |json|
135
+ send(:"make_#{singular}", json)
136
+ end
137
+ end
138
+
139
+ define_method(:"make_#{singular}") do |json|
140
+ klass.new(
141
+ json[:metadata][:guid],
142
+ self,
143
+ json)
144
+ end
145
+ end
146
+
147
+ has_summary
148
+ end
149
+
150
+ def attribute(name, type, opts = {})
151
+ attributes[name] = opts
152
+ json_name = opts[:at] || name
153
+
154
+ default = opts[:default]
155
+
156
+ if has_default = opts.key?(:default)
157
+ defaults[name] = default
158
+ end
159
+
160
+ define_method(name) do
161
+ return @cache[name] if @cache.key?(name)
162
+
163
+ @cache[name] =
164
+ if manifest[:entity].key?(json_name)
165
+ manifest[:entity][json_name]
166
+ else
167
+ default
168
+ end
169
+ end
170
+
171
+ define_method(:"#{name}=") do |val|
172
+ unless has_default && val == default
173
+ CFoundry::Validator.validate_type(val, type)
174
+ end
175
+
176
+ @cache[name] = val
177
+
178
+ @manifest ||= {}
179
+ @manifest[:entity] ||= {}
180
+
181
+ old = @manifest[:entity][json_name]
182
+ @changes[name] = [old, val] if old != val
183
+ @manifest[:entity][json_name] = val
184
+
185
+ @diff[json_name] = val
186
+ end
187
+ end
188
+
189
+ def scoped_to_organization(relation = :organization)
190
+ @scoped_organization = relation
191
+ end
192
+
193
+ def scoped_to_space(relation = :space)
194
+ @scoped_space = relation
195
+ end
196
+
197
+ def to_one(name, opts = {})
198
+ to_one_relations[name] = opts
199
+
200
+ obj = opts[:as] || name
201
+ kls = obj.to_s.capitalize.gsub(/(.)_(.)/) do
202
+ $1 + $2.upcase
203
+ end
204
+
205
+ default = opts[:default]
206
+
207
+ if has_default = opts.key?(:default)
208
+ defaults[:"#{name}_guid"] = default
209
+ end
210
+
211
+ define_method(name) do
212
+ return @cache[name] if @cache.key?(name)
213
+
214
+ @cache[name] =
215
+ if @manifest && @manifest[:entity].key?(name)
216
+ @client.send(:"make_#{obj}", @manifest[:entity][name])
217
+ elsif url = send("#{name}_url")
218
+ @client.send(:"#{obj}_from", url)
219
+ else
220
+ default
221
+ end
222
+ end
223
+
224
+ define_method(:"#{name}_url") do
225
+ manifest[:entity][:"#{name}_url"]
226
+ end
227
+
228
+ define_method(:"#{name}=") do |val|
229
+ klass = self.class.objects[obj]
230
+
231
+ unless has_default && val == default
232
+ CFoundry::Validator.validate_type(val, klass)
233
+ end
234
+
235
+ @manifest ||= {}
236
+ @manifest[:entity] ||= {}
237
+
238
+ old = @manifest[:entity][:"#{name}_guid"]
239
+ if old != (val && val.guid)
240
+ old_obj =
241
+ @cache[name] || klass.new(@client, old, @manifest[:entity][name])
242
+
243
+ @changes[name] = [old_obj, val]
244
+ end
245
+
246
+ @cache[name] = val
247
+
248
+ @manifest[:entity][:"#{name}_guid"] =
249
+ @diff[:"#{name}_guid"] = val && val.guid
250
+ end
251
+ end
252
+
253
+ def to_many(plural, opts = {})
254
+ to_many_relations[plural] = opts
255
+
256
+ singular = plural.to_s.sub(/s$/, "").to_sym
257
+
258
+ include QUERIES[singular]
259
+
260
+ object = opts[:as] || singular
261
+
262
+ kls = object.to_s.capitalize.gsub(/(.)_(.)/) do
263
+ $1 + $2.upcase
264
+ end
265
+
266
+ define_method(plural) do |*args|
267
+ klass = CFoundry::V2.const_get(kls)
268
+
269
+ opts, _ = args
270
+ opts ||= {}
271
+
272
+ if opts.empty? && cache = @cache[plural]
273
+ return cache
274
+ end
275
+
276
+ if @manifest && @manifest[:entity].key?(plural) && opts.empty?
277
+ objs = @manifest[:entity][plural]
278
+
279
+ if query = opts[:query]
280
+ find_by, find_val = query
281
+ objs = objs.select { |o| o[:entity][find_by] == find_val }
282
+ end
283
+
284
+ res =
285
+ objs.collect do |json|
286
+ @client.send(:"make_#{object}", json)
287
+ end
288
+ else
289
+ res =
290
+ @client.send(
291
+ :"#{klass.plural_object_name}_from",
292
+ "/v2/#{plural_object_name}/#@guid/#{plural}",
293
+ opts)
294
+ end
295
+
296
+ if opts.empty?
297
+ @cache[plural] = res
298
+ end
299
+
300
+ res
301
+ end
302
+
303
+ define_method(:"#{plural}_url") do
304
+ manifest[:entity][:"#{plural}_url"]
305
+ end
306
+
307
+ define_method(:"add_#{singular}") do |x|
308
+ klass = self.class.objects[object]
309
+
310
+ CFoundry::Validator.validate_type(x, klass)
311
+
312
+ if cache = @cache[plural]
313
+ cache << x unless cache.include?(x)
314
+ end
315
+
316
+ @client.base.put("v2", plural_object_name, @guid, plural, x.guid, :accept => :json)
317
+ end
318
+
319
+ define_method(:"remove_#{singular}") do |x|
320
+ klass = self.class.objects[object]
321
+
322
+ CFoundry::Validator.validate_type(x, klass)
323
+
324
+ if cache = @cache[plural]
325
+ cache.delete(x)
326
+ end
327
+
328
+ @client.base.delete("v2", plural_object_name, @guid, plural, x.guid, :accept => :json)
329
+ end
330
+
331
+ define_method(:"#{plural}=") do |xs|
332
+ klass = self.class.objects[object]
333
+
334
+ CFoundry::Validator.validate_type(xs, [klass])
335
+
336
+ @manifest ||= {}
337
+ @manifest[:entity] ||= {}
338
+
339
+ old = @manifest[:entity][:"#{singular}_guids"]
340
+ if old != xs.collect(&:guid)
341
+ old_objs =
342
+ @cache[plural] ||
343
+ if all = @manifest[:entity][plural]
344
+ all.collect do |m|
345
+ klass.new(@client, m[:metadata][:guid], m)
346
+ end
347
+ elsif old
348
+ old.collect { |id| klass.new(@client, id) }
349
+ end
350
+
351
+ @changes[plural] = [old_objs, xs]
352
+ end
353
+
354
+ @cache[plural] = xs
355
+
356
+ @manifest[:entity][:"#{singular}_guids"] =
357
+ @diff[:"#{singular}_guids"] = xs.collect(&:guid)
358
+ end
359
+ end
360
+
361
+ def has_summary(actions = {})
362
+ define_method(:summary) do
363
+ @client.base.get("v2", plural_object_name, @guid, "summary", :accept => :json)
364
+ end
365
+
366
+ define_method(:summarize!) do |*args|
367
+ body, _ = args
368
+
369
+ body ||= summary
370
+
371
+ body.each do |key, val|
372
+ if act = actions[key]
373
+ instance_exec(val, &act)
374
+
375
+ elsif self.class.attributes[key]
376
+ self.send(:"#{key}=", val)
377
+
378
+ elsif self.class.to_many_relations[key]
379
+ singular = key.to_s.sub(/s$/, "").to_sym
380
+
381
+ vals = val.collect do |sub|
382
+ obj = @client.send(singular, sub[:guid], true)
383
+ obj.summarize! sub
384
+ obj
385
+ end
386
+
387
+ self.send(:"#{key}=", vals)
388
+
389
+ elsif self.class.to_one_relations[key]
390
+ obj = @client.send(key, val[:guid], true)
391
+ obj.summarize! val
392
+
393
+ self.send(:"#{key}=", obj)
394
+ end
395
+ end
396
+
397
+ nil
398
+ end
399
+ end
400
+
401
+ def queryable_by(*names)
402
+ klass = self
403
+ singular = object_name
404
+ plural = plural_object_name
405
+
406
+ query = QUERIES[singular]
407
+
408
+ query.module_eval do
409
+ names.each do |name|
410
+ define_method(:"#{singular}_by_#{name}") do |*args|
411
+ send(:"#{plural}_by_#{name}", *args).first
412
+ end
413
+
414
+ define_method(:"#{plural}_by_#{name}") do |val, *args|
415
+ options, _ = args
416
+ options ||= {}
417
+ options[:query] = [name, val]
418
+
419
+ query_target(klass).send(plural, options)
420
+ end
421
+ end
422
+ end
423
+
424
+ const_set(:Queries, query)
425
+
426
+ ClientMethods.module_eval do
427
+ include query
428
+ end
429
+ end
430
+
431
+ def self.params_from(args)
432
+ options, _ = args
433
+ options ||= {}
434
+ options[:depth] ||= 1
435
+
436
+ params = {}
437
+ options.each do |k, v|
438
+ case k
439
+ when :depth
440
+ params[:"inline-relations-depth"] = v
441
+ when :query
442
+ params[:q] = v.join(":")
443
+ end
444
+ end
445
+
446
+ params
447
+ end
448
+ end
449
+ end
@@ -0,0 +1,16 @@
1
+ require "cfoundry/v2/model"
2
+
3
+ module CFoundry::V2
4
+ class Organization < Model
5
+ attribute :name, :string
6
+ to_many :spaces
7
+ to_many :domains
8
+ to_many :users
9
+ to_many :managers, :as => :user
10
+ to_many :billing_managers, :as => :user
11
+ to_many :auditors, :as => :user
12
+
13
+ queryable_by :name, :space_guid, :user_guid, :manager_guid,
14
+ :billing_manager_guid, :auditor_guid
15
+ end
16
+ end
@@ -0,0 +1,15 @@
1
+ require "cfoundry/v2/model"
2
+
3
+ module CFoundry::V2
4
+ class Route < Model
5
+ attribute :host, :string
6
+ to_one :domain
7
+ to_one :space
8
+
9
+ queryable_by :host, :domain_guid
10
+
11
+ def name
12
+ "#{host}.#{domain.name}"
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,12 @@
1
+ require "cfoundry/v2/model"
2
+
3
+ module CFoundry::V2
4
+ class Runtime < Model
5
+ attribute :name, :string
6
+ attribute :description, :string
7
+ attribute :version, :string
8
+ to_many :apps
9
+
10
+ queryable_by :name, :app_guid
11
+ end
12
+ end
@@ -0,0 +1,19 @@
1
+ require "cfoundry/v2/model"
2
+
3
+ module CFoundry::V2
4
+ class Service < Model
5
+ attribute :label, String
6
+ attribute :provider, String
7
+ attribute :url, :url
8
+ attribute :description, String
9
+ attribute :version, String
10
+ attribute :info_url, :url
11
+ attribute :acls, { "users" => [String], "wildcards" => [String] },
12
+ :default => nil
13
+ attribute :timeout, Integer, :default => nil
14
+ attribute :active, :boolean, :default => false
15
+ to_many :service_plans
16
+
17
+ queryable_by :service_plan_guid
18
+ end
19
+ end
@@ -0,0 +1,9 @@
1
+ require "cfoundry/v2/model"
2
+
3
+ module CFoundry::V2
4
+ class ServiceAuthToken < Model
5
+ attribute :label, :string
6
+ attribute :provider, :string
7
+ attribute :token, :string
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ require "cfoundry/v2/model"
2
+
3
+ module CFoundry::V2
4
+ class ServiceBinding < Model
5
+ to_one :app
6
+ to_one :service_instance
7
+
8
+ queryable_by :app_guid, :service_instance_guid
9
+ end
10
+ end
@@ -0,0 +1,14 @@
1
+ require "cfoundry/v2/model"
2
+
3
+ module CFoundry::V2
4
+ class ServiceInstance < Model
5
+ attribute :name, :string
6
+ to_one :space
7
+ to_one :service_plan
8
+ to_many :service_bindings
9
+
10
+ scoped_to_space
11
+
12
+ queryable_by :name, :space_guid, :service_plan_guid, :service_binding_guid
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ require "cfoundry/v2/model"
2
+
3
+ module CFoundry::V2
4
+ class ServicePlan < Model
5
+ attribute :name, :string
6
+ attribute :description, :string
7
+ to_one :service
8
+ to_many :service_instances
9
+
10
+ queryable_by :service_guid, :service_instance_guid
11
+ end
12
+ end