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,178 @@
1
+ require "multi_json"
2
+
3
+ require "cfoundry/v1/model_magic"
4
+
5
+
6
+ module CFoundry::V1
7
+ class Model
8
+ @@objects = {}
9
+
10
+ extend ModelMagic
11
+
12
+ class << self
13
+ attr_writer :object_name, :base_object_name
14
+
15
+ def object_name
16
+ @object_name ||=
17
+ name.split("::").last.gsub(
18
+ /([a-z])([A-Z])/,
19
+ '\1_\2').downcase.to_sym
20
+ end
21
+
22
+ def base_object_name
23
+ @base_object_name ||= object_name
24
+ end
25
+
26
+ def plural_object_name
27
+ "#{object_name}s"
28
+ end
29
+
30
+ def plural_base_object_name
31
+ "#{base_object_name}s"
32
+ end
33
+
34
+ def objects
35
+ @@objects
36
+ end
37
+
38
+ def inherited(klass)
39
+ @@objects[klass.object_name] = klass
40
+ super
41
+ end
42
+ end
43
+
44
+ attr_accessor :guid, :changes
45
+
46
+ def initialize(guid, client, manifest = nil)
47
+ @guid = guid
48
+ @client = client
49
+ @manifest = manifest
50
+ @changes = {}
51
+ end
52
+
53
+ def manifest
54
+ @manifest ||= @client.base.send(base_object_name, @guid)
55
+ end
56
+
57
+ def changed?
58
+ !@changes.empty?
59
+ end
60
+
61
+ def inspect
62
+ "\#<#{self.class.name} '#@guid'>"
63
+ end
64
+
65
+ def object_name
66
+ @object_name ||= self.class.object_name
67
+ end
68
+
69
+ def base_object_name
70
+ @base_object_name ||= self.class.base_object_name
71
+ end
72
+
73
+ def guid_name
74
+ self.class.guid_name
75
+ end
76
+
77
+ def invalidate!
78
+ @manifest = nil
79
+ @changes = {}
80
+ end
81
+
82
+ def create!
83
+ @manifest = @client.base.send(:"create_#{base_object_name}", write_manifest)
84
+
85
+ @guid = read_manifest[guid_name]
86
+
87
+ true
88
+ end
89
+
90
+ def update!
91
+ @client.base.send(:"update_#{base_object_name}", @guid, write_manifest)
92
+
93
+ true
94
+ end
95
+
96
+ def delete!
97
+ @client.base.send(:"delete_#{base_object_name}", @guid)
98
+
99
+ @guid = nil
100
+
101
+ true
102
+ end
103
+
104
+ def exists?
105
+ invalidate!
106
+ manifest
107
+ true
108
+ rescue CFoundry::NotFound
109
+ false
110
+ end
111
+
112
+ def read_manifest
113
+ read = {}
114
+
115
+ self.class.read_locations.each do |name, where|
116
+ found, val = find_path(manifest, where)
117
+ read[name] = val if found
118
+ end
119
+
120
+ self.class.write_locations.each do |name, where|
121
+ next if self.class.read_only_attributes.include? name
122
+
123
+ found, val = find_path(manifest, where)
124
+ read[name] = val if found
125
+ end
126
+
127
+ read[guid_name] = @guid
128
+
129
+ read
130
+ end
131
+
132
+ def find_path(hash, path)
133
+ return [false, nil] unless hash
134
+
135
+ first, *rest = path
136
+ return [false, nil] unless hash.key?(first)
137
+
138
+ here = hash[first]
139
+
140
+ if rest.empty?
141
+ [true, here]
142
+ else
143
+ find_path(here, rest)
144
+ end
145
+ end
146
+
147
+ def write_manifest(body = read_manifest, onto = {})
148
+ onto[guid_name] = @guid if guid_name
149
+
150
+ self.class.write_locations.each do |name, where|
151
+ next if self.class.read_only_attributes.include? name
152
+ put(body[name], onto, where) if body.key?(name)
153
+ end
154
+
155
+ onto
156
+ end
157
+
158
+ def put(what, where, path)
159
+ if path.size == 1
160
+ where[path.last] = what
161
+ elsif name = path.first
162
+ where[name] ||= {}
163
+ put(what, where[name], path[1..-1])
164
+ end
165
+
166
+ nil
167
+ end
168
+
169
+ def eql?(other)
170
+ other.is_a?(self.class) && @guid == other.guid
171
+ end
172
+ alias :== :eql?
173
+
174
+ def hash
175
+ @guid.hash
176
+ end
177
+ end
178
+ end
@@ -0,0 +1,129 @@
1
+ require "cfoundry/validator"
2
+
3
+ module CFoundry::V1
4
+ module BaseClientMethods
5
+ end
6
+
7
+ module ClientMethods
8
+ end
9
+
10
+ module ModelMagic
11
+ attr_accessor :guid_name
12
+
13
+ def read_locations
14
+ @read_locations ||= {}
15
+ end
16
+
17
+ def write_locations
18
+ @write_locations ||= {}
19
+ end
20
+
21
+ def read_only_attributes
22
+ @read_only_attributes ||= []
23
+ end
24
+
25
+ def on_client(&blk)
26
+ ClientMethods.module_eval(&blk)
27
+ end
28
+
29
+ def on_base_client(&blk)
30
+ BaseClientMethods.module_eval(&blk)
31
+ end
32
+
33
+ def define_client_methods(klass = self)
34
+ singular = klass.object_name
35
+ plural = klass.plural_object_name
36
+
37
+ base_singular = klass.base_object_name
38
+ base_plural = klass.plural_base_object_name
39
+
40
+ on_base_client do
41
+ define_method(base_singular) do |guid|
42
+ get(base_plural, guid, :accept => :json)
43
+ end
44
+
45
+ define_method(:"create_#{base_singular}") do |payload|
46
+ post(base_plural, :content => :json, :accept => :json, :payload => payload)
47
+ end
48
+
49
+ define_method(:"delete_#{base_singular}") do |guid|
50
+ delete(base_plural, guid)
51
+ true
52
+ end
53
+
54
+ define_method(:"update_#{base_singular}") do |guid, payload|
55
+ put(base_plural, guid, :content => :json, :payload => payload)
56
+ end
57
+
58
+ define_method(base_plural) do |*args|
59
+ get(base_plural, :accept => :json)
60
+ end
61
+ end
62
+
63
+ on_client do
64
+ if klass.guid_name
65
+ define_method(:"#{singular}_by_#{klass.guid_name}") do |guid|
66
+ obj = send(singular, guid)
67
+ obj if obj.exists?
68
+ end
69
+ end
70
+
71
+ define_method(singular) do |*args|
72
+ guid, _ = args
73
+ klass.new(guid, self)
74
+ end
75
+
76
+ define_method(plural) do |*args|
77
+ options, _ = args
78
+ options ||= {}
79
+
80
+ @base.send(base_plural).collect do |json|
81
+ klass.new(json[klass.guid_name], self, json)
82
+ end
83
+ end
84
+ end
85
+ end
86
+
87
+ def attribute(name, type, opts = {})
88
+ default = opts[:default]
89
+ is_guid = opts[:guid]
90
+ read_only = opts[:read_only]
91
+ write_only = opts[:write_only]
92
+ has_default = opts.key?(:default)
93
+
94
+ read_locations[name] = Array(opts[:read] || opts[:at] || name) unless write_only
95
+ write_locations[name] = Array(opts[:write] || opts[:at] || name) unless read_only
96
+
97
+ read_only_attributes << name if read_only
98
+
99
+ self.guid_name = name if is_guid
100
+
101
+ define_method(name) do
102
+ return @guid if @guid && is_guid
103
+
104
+ read = read_manifest
105
+ read.key?(name) ? read[name] : default
106
+ end
107
+
108
+ define_method(:"#{name}=") do |val|
109
+ unless has_default && val == default
110
+ CFoundry::Validator.validate_type(val, type)
111
+ end
112
+
113
+ @guid = val if is_guid
114
+
115
+ @manifest ||= {}
116
+
117
+ old = read_manifest[name]
118
+ @changes[name] = [old, val] if old != val
119
+
120
+ write_to = read_only ? self.class.read_locations : self.class.write_locations
121
+
122
+ put(val, @manifest, write_to[name])
123
+ end
124
+
125
+ private name if write_only
126
+ private :"#{name}=" if read_only
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,24 @@
1
+ module CFoundry::V1
2
+ class Runtime
3
+ attr_accessor :name, :description, :debug_modes
4
+
5
+ def initialize(name, description = nil, debug_modes = nil)
6
+ @name = name
7
+ @description = description
8
+ @debug_modes = debug_modes
9
+ end
10
+
11
+ def eql?(other)
12
+ other.is_a?(self.class) && other.name == @name
13
+ end
14
+ alias :== :eql?
15
+
16
+ def apps
17
+ [] # not supported by v1
18
+ end
19
+
20
+ def debug_modes
21
+ @debug_modes || []
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,39 @@
1
+ module CFoundry::V1
2
+ class Service
3
+ attr_accessor :label, :version, :description, :type, :provider, :state, :service_plans
4
+
5
+ def initialize(label, version = nil, description = nil,
6
+ type = nil, provider = "core", state = nil,
7
+ service_plans = [])
8
+ @label = label
9
+ @description = description
10
+ @version = version
11
+ @type = type
12
+ @provider = provider
13
+ @state = state
14
+ @service_plans = service_plans
15
+ end
16
+
17
+ def eql?(other)
18
+ other.is_a?(self.class) && other.label == @label
19
+ end
20
+ alias :== :eql?
21
+
22
+ def active
23
+ true
24
+ end
25
+
26
+ def deprecated?
27
+ @state == :deprecated
28
+ end
29
+
30
+ def current?
31
+ @state == :current
32
+ end
33
+
34
+ def default_service_plan
35
+ service_plans.find(&:default?)
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,32 @@
1
+ require "cfoundry/v1/model"
2
+
3
+ module CFoundry::V1
4
+ class ServiceInstance < Model
5
+ self.base_object_name = :service
6
+
7
+ attribute :name, :string, :guid => true
8
+ attribute :created, :integer, :at => [:meta, :created]
9
+ attribute :updated, :integer, :at => [:meta, :updated]
10
+ attribute :tags, [:string], :at => [:meta, :tags]
11
+ attribute :type, :string
12
+ attribute :vendor, :string
13
+ attribute :version, :string
14
+ attribute :tier, :string
15
+ attribute :properties, :hash
16
+
17
+ define_client_methods
18
+
19
+ alias_method :created_unix, :created
20
+ alias_method :updated_unix, :updated
21
+
22
+ # Timestamp of when the service was created.
23
+ def created
24
+ Time.at(created_unix)
25
+ end
26
+
27
+ # Timestamp of when the service was last updated.
28
+ def updated
29
+ Time.at(updated_unix)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,19 @@
1
+ module CFoundry::V1
2
+
3
+ class ServicePlan
4
+
5
+ attr_accessor :name, :description
6
+
7
+ def initialize(name, description, is_default)
8
+ @name = name
9
+ @description = description
10
+ @is_default = is_default
11
+ end
12
+
13
+ def default?
14
+ @is_default
15
+ end
16
+
17
+ end
18
+
19
+ end
@@ -0,0 +1,22 @@
1
+ require "cfoundry/v1/model"
2
+
3
+ module CFoundry::V1
4
+ class User < Model
5
+ attribute :email, :string, :guid => true
6
+ attribute :password, :string, :write_only => true
7
+ attribute :admin, :boolean
8
+
9
+ define_client_methods
10
+
11
+ alias_method :admin?, :admin
12
+
13
+ def change_password!(new, old)
14
+ if @client.base.uaa
15
+ @client.base.uaa.change_password(guid, new, old)
16
+ else
17
+ self.password = new
18
+ update!
19
+ end
20
+ end
21
+ end
22
+ end