openshift-origin-controller 1.3.2

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.
Files changed (180) hide show
  1. data/COPYRIGHT +1 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE +12 -0
  4. data/README.md +3 -0
  5. data/Rakefile +9 -0
  6. data/app/controllers/app_events_controller.rb +115 -0
  7. data/app/controllers/application_templates_controller.rb +19 -0
  8. data/app/controllers/applications_controller.rb +214 -0
  9. data/app/controllers/base_controller.rb +367 -0
  10. data/app/controllers/cartridges_controller.rb +48 -0
  11. data/app/controllers/descriptors_controller.rb +23 -0
  12. data/app/controllers/dns_resolvable_controller.rb +35 -0
  13. data/app/controllers/domains_controller.rb +156 -0
  14. data/app/controllers/emb_cart_controller.rb +276 -0
  15. data/app/controllers/emb_cart_events_controller.rb +52 -0
  16. data/app/controllers/environment_controller.rb +11 -0
  17. data/app/controllers/estimates_controller.rb +71 -0
  18. data/app/controllers/gear_groups_controller.rb +53 -0
  19. data/app/controllers/gears_controller.rb +70 -0
  20. data/app/controllers/keys_controller.rb +96 -0
  21. data/app/controllers/legacy_broker_controller.rb +510 -0
  22. data/app/controllers/quickstarts_controller.rb +29 -0
  23. data/app/controllers/user_controller.rb +38 -0
  24. data/app/helpers/cartridge_helper.rb +25 -0
  25. data/app/helpers/legacy_broker_helper.rb +21 -0
  26. data/app/helpers/user_action_logger.rb +38 -0
  27. data/app/models/application.rb +1718 -0
  28. data/app/models/application_template.rb +27 -0
  29. data/app/models/cartridge_cache.rb +51 -0
  30. data/app/models/cloud_user.rb +334 -0
  31. data/app/models/component_instance.rb +228 -0
  32. data/app/models/connection_endpoint.rb +10 -0
  33. data/app/models/district.rb +210 -0
  34. data/app/models/domain.rb +234 -0
  35. data/app/models/gear.rb +376 -0
  36. data/app/models/group_instance.rb +306 -0
  37. data/app/models/key.rb +20 -0
  38. data/app/models/legacy_reply.rb +15 -0
  39. data/app/models/legacy_request.rb +126 -0
  40. data/app/models/link.rb +11 -0
  41. data/app/models/message.rb +10 -0
  42. data/app/models/name_server_cache.rb +46 -0
  43. data/app/models/optional_param.rb +12 -0
  44. data/app/models/param.rb +13 -0
  45. data/app/models/remote_job.rb +57 -0
  46. data/app/models/rest_application.rb +126 -0
  47. data/app/models/rest_application10.rb +106 -0
  48. data/app/models/rest_application12.rb +124 -0
  49. data/app/models/rest_application_estimate.rb +12 -0
  50. data/app/models/rest_application_template.rb +20 -0
  51. data/app/models/rest_cartridge10.rb +41 -0
  52. data/app/models/rest_cartridge11.rb +151 -0
  53. data/app/models/rest_domain.rb +43 -0
  54. data/app/models/rest_domain10.rb +42 -0
  55. data/app/models/rest_estimates.rb +16 -0
  56. data/app/models/rest_gear.rb +14 -0
  57. data/app/models/rest_gear_group.rb +26 -0
  58. data/app/models/rest_key.rb +24 -0
  59. data/app/models/rest_reply.rb +31 -0
  60. data/app/models/rest_user.rb +43 -0
  61. data/app/models/result_io.rb +67 -0
  62. data/app/models/usage_record.rb +37 -0
  63. data/app/models/validators/app_validator.rb +30 -0
  64. data/app/models/validators/key_validator.rb +30 -0
  65. data/app/models/validators/namespace_validator.rb +18 -0
  66. data/config/routes.rb +36 -0
  67. data/lib/controller_engine.rb +7 -0
  68. data/lib/openshift-origin-controller.rb +14 -0
  69. data/lib/openshift/application_container_proxy.rb +241 -0
  70. data/lib/openshift/auth_service.rb +101 -0
  71. data/lib/openshift/data_store.rb +33 -0
  72. data/lib/openshift/dns_service.rb +41 -0
  73. data/lib/openshift/mongo_data_store.rb +671 -0
  74. data/openshift-origin-controller.gemspec +42 -0
  75. data/rubygem-openshift-origin-controller.spec +274 -0
  76. data/test/cucumber/application-estimate.feature +25 -0
  77. data/test/cucumber/cartridge-10gen-mms-agent.feature +28 -0
  78. data/test/cucumber/cartridge-cron.feature +32 -0
  79. data/test/cucumber/cartridge-haproxy.feature +31 -0
  80. data/test/cucumber/cartridge-jenkins-build.feature +12 -0
  81. data/test/cucumber/cartridge-jenkins-client.feature +10 -0
  82. data/test/cucumber/cartridge-lifecycle-diy.feature +21 -0
  83. data/test/cucumber/cartridge-lifecycle-jbossas.feature +61 -0
  84. data/test/cucumber/cartridge-lifecycle-jbosseap.feature +61 -0
  85. data/test/cucumber/cartridge-lifecycle-jbossews10.feature +61 -0
  86. data/test/cucumber/cartridge-lifecycle-jenkins.feature +41 -0
  87. data/test/cucumber/cartridge-lifecycle-nodejs.feature +59 -0
  88. data/test/cucumber/cartridge-lifecycle-perl.feature +40 -0
  89. data/test/cucumber/cartridge-lifecycle-php.feature +106 -0
  90. data/test/cucumber/cartridge-lifecycle-python.feature +40 -0
  91. data/test/cucumber/cartridge-lifecycle-ruby18.feature +49 -0
  92. data/test/cucumber/cartridge-lifecycle-ruby19.feature +41 -0
  93. data/test/cucumber/cartridge-mongodb.feature +31 -0
  94. data/test/cucumber/cartridge-mysql.feature +30 -0
  95. data/test/cucumber/cartridge-php.feature +14 -0
  96. data/test/cucumber/cartridge-phpmyadmin.feature +32 -0
  97. data/test/cucumber/cartridge-postgresql.feature +32 -0
  98. data/test/cucumber/cartridge-runtime-extended-db.feature +64 -0
  99. data/test/cucumber/cartridge-runtime-extended-jboss.feature +24 -0
  100. data/test/cucumber/cartridge-runtime-extended-nodejs.feature +21 -0
  101. data/test/cucumber/cartridge-runtime-extended-perl.feature +18 -0
  102. data/test/cucumber/cartridge-runtime-extended-php.feature +19 -0
  103. data/test/cucumber/cartridge-runtime-extended-python.feature +18 -0
  104. data/test/cucumber/cartridge-runtime-extended-ruby.feature +22 -0
  105. data/test/cucumber/cartridge-runtime-standard-diy.feature +6 -0
  106. data/test/cucumber/cartridge-runtime-standard-jbossas.feature +7 -0
  107. data/test/cucumber/cartridge-runtime-standard-jbosseap.feature +7 -0
  108. data/test/cucumber/cartridge-runtime-standard-jbossews10.feature +7 -0
  109. data/test/cucumber/cartridge-runtime-standard-jenkins.feature +8 -0
  110. data/test/cucumber/cartridge-runtime-standard-nodejs.feature +7 -0
  111. data/test/cucumber/cartridge-runtime-standard-perl.feature +6 -0
  112. data/test/cucumber/cartridge-runtime-standard-php.feature +6 -0
  113. data/test/cucumber/cartridge-runtime-standard-python.feature +6 -0
  114. data/test/cucumber/cartridge-runtime-standard-ruby.feature +19 -0
  115. data/test/cucumber/cartridge-switchyard.feature +36 -0
  116. data/test/cucumber/descriptor.feature +40 -0
  117. data/test/cucumber/embedded.feature +44 -0
  118. data/test/cucumber/idler.feature +75 -0
  119. data/test/cucumber/misc/descriptor/manifest.yml +22 -0
  120. data/test/cucumber/misc/php/db_test.php +21 -0
  121. data/test/cucumber/openshift-node.feature +21 -0
  122. data/test/cucumber/rest-application-templates.feature +31 -0
  123. data/test/cucumber/rest-applications.feature +431 -0
  124. data/test/cucumber/rest-cartridge-types.feature +16 -0
  125. data/test/cucumber/rest-domains.feature +276 -0
  126. data/test/cucumber/rest-gears.feature +38 -0
  127. data/test/cucumber/rest-keys.feature +247 -0
  128. data/test/cucumber/rest-quickstarts.feature +27 -0
  129. data/test/cucumber/rest-workflow.feature +64 -0
  130. data/test/cucumber/step_definitions/api_steps.rb +369 -0
  131. data/test/cucumber/step_definitions/application-estimate-steps.rb +51 -0
  132. data/test/cucumber/step_definitions/application_steps.rb +215 -0
  133. data/test/cucumber/step_definitions/cartridge-10gen-mms-agent_steps.rb +11 -0
  134. data/test/cucumber/step_definitions/cartridge-cron_steps.rb +51 -0
  135. data/test/cucumber/step_definitions/cartridge-haproxy_steps.rb +30 -0
  136. data/test/cucumber/step_definitions/cartridge-jenkins_steps.rb +93 -0
  137. data/test/cucumber/step_definitions/cartridge-lifecycle-nodejs_steps.rb +30 -0
  138. data/test/cucumber/step_definitions/cartridge-mongodb_steps.rb +60 -0
  139. data/test/cucumber/step_definitions/cartridge-mysql_steps.rb +56 -0
  140. data/test/cucumber/step_definitions/cartridge-php_steps.rb +72 -0
  141. data/test/cucumber/step_definitions/cartridge-postgresql_steps.rb +59 -0
  142. data/test/cucumber/step_definitions/cartridge-switchyard_steps.rb +29 -0
  143. data/test/cucumber/step_definitions/client_steps.rb +12 -0
  144. data/test/cucumber/step_definitions/descriptor_step.rb +32 -0
  145. data/test/cucumber/step_definitions/idler_steps.rb +37 -0
  146. data/test/cucumber/step_definitions/node_steps.rb +203 -0
  147. data/test/cucumber/step_definitions/runtime_steps.rb +547 -0
  148. data/test/cucumber/step_definitions/runtime_url_steps.rb +46 -0
  149. data/test/cucumber/step_definitions/trap-user-extended_steps.rb +14 -0
  150. data/test/cucumber/step_definitions/trap-user_steps.rb +58 -0
  151. data/test/cucumber/support/00_setup_helper.rb +106 -0
  152. data/test/cucumber/support/app_helper.rb +243 -0
  153. data/test/cucumber/support/assertions.rb +52 -0
  154. data/test/cucumber/support/command_helper.rb +453 -0
  155. data/test/cucumber/support/dns_helper.rb +54 -0
  156. data/test/cucumber/support/env.rb +5 -0
  157. data/test/cucumber/support/process_helper.rb +44 -0
  158. data/test/cucumber/support/runtime_support.rb +440 -0
  159. data/test/cucumber/support/unused.rb +27 -0
  160. data/test/cucumber/support/user_helper.rb +37 -0
  161. data/test/cucumber/trap-user-extended.feature +53 -0
  162. data/test/cucumber/trap-user.feature +34 -0
  163. data/test/ddns/1.168.192-rev.db.init +13 -0
  164. data/test/ddns/HOWTO.txt +207 -0
  165. data/test/ddns/Kexample.com.+157+06142.key +1 -0
  166. data/test/ddns/Kexample.com.+157+06142.private +7 -0
  167. data/test/ddns/authconfig.rb +14 -0
  168. data/test/ddns/example.com.db.init +23 -0
  169. data/test/ddns/example.com.key +4 -0
  170. data/test/ddns/named.ca +52 -0
  171. data/test/ddns/named.conf +48 -0
  172. data/test/ddns/named.empty +10 -0
  173. data/test/ddns/named.localhost +10 -0
  174. data/test/ddns/named.loopback +11 -0
  175. data/test/ddns/named.rfc1912.zones +42 -0
  176. data/test/ddns/named.root.key +5 -0
  177. data/test/ddns/named_service.rb +127 -0
  178. data/test/unit/bind_dns_service_test.rb +167 -0
  179. data/test/unit/broker_auth_test.rb +28 -0
  180. metadata +545 -0
@@ -0,0 +1,43 @@
1
+ class RestDomain < OpenShift::Model
2
+ attr_accessor :id, :suffix, :links
3
+ include LegacyBrokerHelper
4
+
5
+ def initialize(domain, url, nolinks=false)
6
+ self.id = domain.namespace
7
+ self.suffix = Rails.application.config.openshift[:domain_suffix]
8
+
9
+ unless nolinks
10
+ valid_sizes = OpenShift::ApplicationContainerProxy.valid_gear_sizes(domain.user)
11
+ blacklisted_words = OpenShift::ApplicationContainerProxy.get_blacklisted
12
+
13
+ carts = get_cached("cart_list_standalone", :expires_in => 21600.seconds) do
14
+ Application.get_available_cartridges("standalone")
15
+ end
16
+
17
+ self.links = {
18
+ "GET" => Link.new("Get domain", "GET", URI::join(url, "domains/#{id}")),
19
+ "LIST_APPLICATIONS" => Link.new("List applications", "GET", URI::join(url, "domains/#{id}/applications")),
20
+ "ADD_APPLICATION" => Link.new("Create new application", "POST", URI::join(url, "domains/#{id}/applications"),
21
+ [Param.new("name", "string", "Name of the application",nil,blacklisted_words)],
22
+ [OptionalParam.new("cartridges", "array", "Array of one or more cartridge names. i.e. [\"php-5.3\", \"mongodb-2.2\"]", carts),
23
+ OptionalParam.new("template", "string", "UUID of the application template"),
24
+ OptionalParam.new("scale", "boolean", "Mark application as scalable", [true, false], false),
25
+ OptionalParam.new("gear_profile", "string", "The size of the gear", valid_sizes, valid_sizes[0]),
26
+ OptionalParam.new("init_git_url", "string", "Initial git URL"),
27
+ ]),
28
+ "UPDATE" => Link.new("Update domain", "PUT", URI::join(url, "domains/#{id}"),[
29
+ Param.new("id", "string", "Name of the domain")
30
+ ]),
31
+ "DELETE" => Link.new("Delete domain", "DELETE", URI::join(url, "domains/#{id}"),nil,[
32
+ OptionalParam.new("force", "boolean", "Force delete domain. i.e. delete any applications under this domain", [true, false], false)
33
+ ])
34
+ }
35
+ end
36
+ end
37
+
38
+ def to_xml(options={})
39
+ options[:tag_name] = "domain"
40
+ super(options)
41
+ end
42
+
43
+ end
@@ -0,0 +1,42 @@
1
+ class RestDomain10 < OpenShift::Model
2
+ attr_accessor :id, :suffix, :links
3
+ include LegacyBrokerHelper
4
+
5
+ def initialize(domain, url, nolinks=false)
6
+ self.id = domain.namespace
7
+ self.suffix = Rails.application.config.openshift[:domain_suffix]
8
+
9
+ unless nolinks
10
+ valid_sizes = OpenShift::ApplicationContainerProxy.valid_gear_sizes(domain.user)
11
+ blacklisted_words = OpenShift::ApplicationContainerProxy.get_blacklisted
12
+
13
+ carts = get_cached("cart_list_standalone", :expires_in => 21600.seconds) do
14
+ Application.get_available_cartridges("standalone")
15
+ end
16
+
17
+ self.links = {
18
+ "GET" => Link.new("Get domain", "GET", URI::join(url, "domains/#{id}")),
19
+ "LIST_APPLICATIONS" => Link.new("List applications", "GET", URI::join(url, "domains/#{id}/applications")),
20
+ "ADD_APPLICATION" => Link.new("Create new application", "POST", URI::join(url, "domains/#{id}/applications"),
21
+ [Param.new("name", "string", "Name of the application",nil,blacklisted_words)],
22
+ [OptionalParam.new("cartridge", "string", "framework-type, e.g: php-5.3", carts),
23
+ OptionalParam.new("template", "string", "UUID of the application template"),
24
+ OptionalParam.new("scale", "boolean", "Mark application as scalable", [true, false], false),
25
+ OptionalParam.new("gear_profile", "string", "The size of the gear", valid_sizes, valid_sizes[0])
26
+ ]),
27
+ "UPDATE" => Link.new("Update domain", "PUT", URI::join(url, "domains/#{id}"),[
28
+ Param.new("id", "string", "Name of the domain")
29
+ ]),
30
+ "DELETE" => Link.new("Delete domain", "DELETE", URI::join(url, "domains/#{id}"),nil,[
31
+ OptionalParam.new("force", "boolean", "Force delete domain. i.e. delete any applications under this domain", [true, false], false)
32
+ ])
33
+ }
34
+ end
35
+ end
36
+
37
+ def to_xml(options={})
38
+ options[:tag_name] = "domain"
39
+ super(options)
40
+ end
41
+
42
+ end
@@ -0,0 +1,16 @@
1
+ class RestEstimates < OpenShift::Model
2
+ attr_accessor :links
3
+
4
+ def initialize(url, nolinks=false)
5
+ self.links = {
6
+ "GET_ESTIMATE" => Link.new("Get application estimate", "GET", URI::join(url, "estimates/application"), [
7
+ Param.new("descriptor", "string", "application requirements")
8
+ ])
9
+ } unless nolinks
10
+ end
11
+
12
+ def to_xml(options={})
13
+ options[:tag_name] = "estimates"
14
+ super(options)
15
+ end
16
+ end
@@ -0,0 +1,14 @@
1
+ class RestGear < OpenShift::Model
2
+ attr_accessor :uuid, :components
3
+ include LegacyBrokerHelper
4
+
5
+ def initialize(uuid, components)
6
+ self.uuid = uuid
7
+ self.components = components
8
+ end
9
+
10
+ def to_xml(options={})
11
+ options[:tag_name] = "gear"
12
+ super(options)
13
+ end
14
+ end
@@ -0,0 +1,26 @@
1
+ class RestGearGroup < OpenShift::Model
2
+ attr_accessor :uuid, :name, :gear_profile, :cartridges, :gears, :scales_from, :scales_to, :links, :base_gear_storage, :additional_gear_storage
3
+
4
+ def initialize(group_instance, gear_states, url, nolinks=false)
5
+ app = group_instance.app
6
+ self.uuid = group_instance.uuid
7
+ self.name = group_instance.name
8
+ self.gear_profile = group_instance.node_profile
9
+ self.gears = group_instance.gears.map{ |gear| {:id => gear.uuid, :state => gear_states[gear.uuid] || 'unknown'} }
10
+ self.cartridges = group_instance.component_instances.map { |comp_inst| app.comp_instance_map[comp_inst].cart_properties.merge({:name => app.comp_instance_map[comp_inst].parent_cart_name}) }
11
+ self.cartridges.delete_if{ |comp| comp[:name] == app.name }
12
+ storage = group_instance.get_quota
13
+ self.base_gear_storage = storage["base_gear_storage"]
14
+ self.additional_gear_storage = storage["additional_gear_storage"]
15
+ self.scales_to = group_instance.max
16
+ self.scales_from = group_instance.min
17
+ self.links = {
18
+ "GET" => Link.new("Get gear group", "GET", URI::join(url, "domains/#{app.domain.namespace}/applications/#{app.name}/gear_groups/#{uuid}"))
19
+ } unless nolinks
20
+ end
21
+
22
+ def to_xml(options={})
23
+ options[:tag_name] = "gear_group"
24
+ super(options)
25
+ end
26
+ end
@@ -0,0 +1,24 @@
1
+ class RestKey < OpenShift::Model
2
+ attr_accessor :name, :content, :type, :links
3
+
4
+ def initialize(name, content, type, url, nolinks=false)
5
+ self.name= name
6
+ self.content = content
7
+ self.type = type || Key::DEFAULT_SSH_KEY_TYPE
8
+
9
+ self.links = {
10
+ "GET" => Link.new("Get SSH key", "GET", URI::join(url, "user/keys/#{name}")),
11
+ "UPDATE" => Link.new("Update SSH key", "PUT", URI::join(url, "user/keys/#{name}"), [
12
+ Param.new("type", "string", "Type of Key", Key::VALID_SSH_KEY_TYPES),
13
+ Param.new("content", "string", "The key portion of an ssh key (excluding ssh type and comment)"),
14
+ ]),
15
+ "DELETE" => Link.new("Delete SSH key", "DELETE", URI::join(url, "user/keys/#{name}"))
16
+ } unless nolinks
17
+ end
18
+
19
+ def to_xml(options={})
20
+ options[:tag_name] = "key"
21
+ super(options)
22
+ end
23
+
24
+ end
@@ -0,0 +1,31 @@
1
+ class RestReply < OpenShift::Model
2
+ attr_accessor :version, :status, :type, :data, :messages, :supported_api_versions
3
+
4
+
5
+ def initialize(status=nil, type=nil, data=nil)
6
+ self.status = status
7
+ self.type = type
8
+ self.data = data
9
+ self.messages = []
10
+ self.version = $requested_api_version.to_s
11
+ self.supported_api_versions = BaseController::SUPPORTED_API_VERSIONS
12
+ end
13
+
14
+ def process_result_io(result_io)
15
+ unless result_io.nil?
16
+ messages.push(Message.new(:debug, result_io.debugIO.string)) unless result_io.debugIO.string.empty?
17
+ messages.push(Message.new(:info, result_io.messageIO.string)) unless result_io.messageIO.string.empty?
18
+ messages.push(Message.new(:error, result_io.errorIO.string)) unless result_io.errorIO.string.empty?
19
+ messages.push(Message.new(:result, result_io.resultIO.string)) unless result_io.resultIO.string.empty?
20
+ end
21
+ end
22
+
23
+ def to_xml(options={})
24
+ options[:tag_name] = "response"
25
+ if not self.data.kind_of?Enumerable
26
+ new_data = self.data
27
+ self.data = [new_data]
28
+ end
29
+ super(options)
30
+ end
31
+ end
@@ -0,0 +1,43 @@
1
+ class RestUser < OpenShift::Model
2
+ attr_accessor :login, :consumed_gears, :max_gears, :capabilities, :plan_id, :usage_account_id, :links, :consumed_gear_sizes
3
+
4
+ def initialize(cloud_user, url, nolinks=false)
5
+ self.login = cloud_user.login
6
+ self.consumed_gears = cloud_user.consumed_gears
7
+ self.max_gears = cloud_user.max_gears
8
+ self.capabilities = cloud_user.capabilities
9
+ self.plan_id = cloud_user.plan_id
10
+ self.usage_account_id = cloud_user.usage_account_id
11
+
12
+ unless nolinks
13
+ @links = {
14
+ "LIST_KEYS" => Link.new("Get SSH keys", "GET", URI::join(url, "user/keys")),
15
+ "ADD_KEY" => Link.new("Add new SSH key", "POST", URI::join(url, "user/keys"), [
16
+ Param.new("name", "string", "Name of the key"),
17
+ Param.new("type", "string", "Type of Key", Key::VALID_SSH_KEY_TYPES),
18
+ Param.new("content", "string", "The key portion of an ssh key (excluding ssh type and comment)"),
19
+ ])
20
+ }
21
+ @links["DELETE_USER"] = Link.new("Delete user. Only applicable for subaccount users.", "DELETE", URI::join(url, "user"), nil, [
22
+ OptionalParam.new("force", "boolean", "Force delete user. i.e. delete any domains and applications under this user", [true, false], false)
23
+ ]) if cloud_user.parent_user_login
24
+ end
25
+
26
+ consumed_map = {}
27
+ if cloud_user.applications
28
+ cloud_user.applications.each { |a|
29
+ a.gears.each { |g|
30
+ size = g.node_profile || Application.DEFAULT_NODE_PROFILE
31
+ consumed_map[size] = 0 if not consumed_map.has_key? size
32
+ consumed_map[size] = consumed_map[size] +1
33
+ }
34
+ }
35
+ end
36
+ self.consumed_gear_sizes = consumed_map
37
+ end
38
+
39
+ def to_xml(options={})
40
+ options[:tag_name] = "user"
41
+ super(options)
42
+ end
43
+ end
@@ -0,0 +1,67 @@
1
+ class ResultIO
2
+ attr_accessor :debugIO, :resultIO, :messageIO, :errorIO, :appInfoIO, :exitcode, :data, :cart_commands, :cart_properties, :hasUserActionableError
3
+
4
+ def initialize
5
+ @debugIO = StringIO.new
6
+ @resultIO = StringIO.new
7
+ @messageIO = StringIO.new
8
+ @errorIO = StringIO.new
9
+ @appInfoIO = StringIO.new
10
+ @data = ""
11
+ @exitcode = 0
12
+ @cart_commands = []
13
+ @cart_properties = {}
14
+ @hasUserActionableError = false
15
+ end
16
+
17
+ def append(resultIO)
18
+ self.debugIO << resultIO.debugIO.string
19
+ self.resultIO << resultIO.resultIO.string
20
+ self.messageIO << resultIO.messageIO.string
21
+ self.errorIO << resultIO.errorIO.string
22
+ self.appInfoIO << resultIO.appInfoIO.string
23
+ self.cart_commands += resultIO.cart_commands
24
+ self.cart_properties = resultIO.cart_properties.merge(self.cart_properties)
25
+ self.exitcode = resultIO.exitcode
26
+ self.data += resultIO.data
27
+
28
+ if resultIO.exitcode != 0
29
+ if resultIO.hasUserActionableError
30
+ unless (!self.hasUserActionableError) && self.exitcode != 0
31
+ self.hasUserActionableError = true
32
+ end
33
+ else
34
+ self.hasUserActionableError = false
35
+ end
36
+ end
37
+
38
+ self
39
+ end
40
+
41
+ def to_s
42
+ str = "--DEBUG--\n#{@debugIO.string}\n" +
43
+ "--RESULT--\n#{@resultIO.string}\n" +
44
+ "--MESSAGE--\n#{@messageIO.string}\n" +
45
+ "--ERROR--\n#{@errorIO.string}\n" +
46
+ "--APP INFO--\n#{@appInfoIO.string}\n" +
47
+ "--CART COMMANDS--\n#{@cart_commands.join("\n")}\n" +
48
+ "--CART PROPERTIES--\n#{@cart_properties.inspect}\n" +
49
+ "--DATA--\n#{@data}\n" +
50
+ "--EXIT CODE--\n#{@exitcode}\n" +
51
+ "--USER ACTIONABLE--\n#{@hasUserActionableError}\n"
52
+ end
53
+
54
+ def to_json(*args)
55
+ reply = LegacyReply.new
56
+ reply.debug = @debugIO.string
57
+ reply.messages = @messageIO.string
58
+ if !@errorIO.string.empty?
59
+ reply.result = @errorIO.string
60
+ else
61
+ reply.result = @resultIO.string
62
+ end
63
+ reply.data = @data
64
+ reply.exit_code = @exitcode
65
+ reply.to_json(*args)
66
+ end
67
+ end
@@ -0,0 +1,37 @@
1
+ class UsageRecord < OpenShift::UserModel
2
+
3
+ EVENTS = { :begin => "begin",
4
+ :end => "end",
5
+ :continue => "continue" }
6
+
7
+ USAGE_TYPES = { :gear_usage => "GEAR_USAGE",
8
+ :addtl_fs_gb => "ADDTL_FS_GB" }
9
+
10
+ attr_accessor :uuid, :event, :time, :sync_time, :user, :usage_type, :gear_uuid, :gear_size, :addtl_fs_gb
11
+ primary_key :uuid
12
+ exclude_attributes :user
13
+
14
+ def initialize(event=nil, user=nil, time=nil, uuid=nil, usage_type=nil)
15
+ self.uuid = uuid ? uuid : OpenShift::Model.gen_uuid
16
+ self.event = event
17
+ self.time = time ? time : Time.now.utc
18
+ self.user = user
19
+ self.usage_type = usage_type
20
+ self.sync_time = nil
21
+ end
22
+
23
+ # Deletes the usage record from the datastore
24
+ def delete
25
+ super(user.login)
26
+ end
27
+
28
+ # Saves the usage record to the datastore
29
+ def save
30
+ super(user.login)
31
+ end
32
+
33
+ def delete_by_gear_uuid
34
+ OpenShift::DataStore.instance.delete_usage_record_by_gear_uuid(user.login, gear_uuid, usage_type)
35
+ end
36
+
37
+ end
@@ -0,0 +1,30 @@
1
+ class AppValidator < ActiveModel::Validator
2
+ APP_NAME_MAX_LENGTH = 32 unless defined? APP_NAME_MAX_LENGTH
3
+ APP_NAME_MIN_LENGTH = 1 unless defined? APP_NAME_MIN_LENGTH
4
+ def validate(record)
5
+ attributes.each do |attribute|
6
+ value = record.read_attribute_for_validation(attribute)
7
+ if attribute == "name"
8
+ validate_name(record, attribute, valuse)
9
+ end
10
+ end
11
+ end
12
+
13
+ def validate_name(record, attribute, val)
14
+ if val.nil?
15
+ record.errors.add(attribute, {:message => "Name is required and cannot be blank.", :exit_code => 105})
16
+ end
17
+ if !(val =~ /\A[A-Za-z0-9]+\z/)
18
+ record.errors.add(attribute, {:message => "Invalid name. Name must only contain alphanumeric characters.", :exit_code => 105})
19
+ end
20
+ if val and val.length > APP_NAME_MAX_LENGTH
21
+ record.errors.add(attribute, {:message => "Name is too long. Maximum length is #{APP_NAME_MAX_LENGTH} characters.", :exit_code => 105})
22
+ end
23
+ if val and val.length < APP_NAME_MIN_LENGTH
24
+ record.errors.add(attribute, {:message => "Name is too short. Minimum length is #{APP_NAME_MIN_LENGTH} characters.", :exit_code => 105})
25
+ end
26
+ if val and OpenShift::ApplicationContainerProxy.blacklisted? val
27
+ record.errors.add(attribute, {:message => "Name is not allowed. Please choose another.", :exit_code => 105})
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ class KeyValidator < ActiveModel::Validator
2
+ KEY_NAME_MAX_LENGTH = 256 unless defined? KEY_NAME_MAX_LENGTH
3
+ KEY_NAME_MIN_LENGTH = 1 unless defined? KEY_NAME_MIN_LENGTH
4
+ def validate(record)
5
+ if !record.content
6
+ record.errors.add("content", {:message => "Key content is required and cannot be blank.", :exit_code => 108})
7
+ end
8
+ if record.content and !(record.content=~ /\A[A-Za-z0-9\+\/=]+\z/)
9
+ record.errors.add("content", {:message => "Invalid key content.", :exit_code => 108})
10
+ end
11
+ if !record.name
12
+ record.errors.add("name", {:message => "Key name is required and cannot be blank.", :exit_code => 117})
13
+ end
14
+ if record.name and !(record.name =~ /\A[A-Za-z0-9]+\z/)
15
+ record.errors.add("name", {:message => "Invalid key name. Name must only contain alphanumeric characters.", :exit_code => 117})
16
+ end
17
+ if record.name and record.name.length > KEY_NAME_MAX_LENGTH
18
+ record.errors.add("name", {:message => "Key name is too long. Maximum length is #{KEY_NAME_MAX_LENGTH} characters.", :exit_code => 117})
19
+ end
20
+ if record.name and record.name.length < KEY_NAME_MIN_LENGTH
21
+ record.errors.add("name", {:message => "Key name is too short. Minimum length is #{KEY_NAME_MIN_LENGTH} characters.", :exit_code => 117})
22
+ end
23
+ if !record.type
24
+ record.errors.add("type", {:message => "Key type is required and cannot be blank.", :exit_code => 116})
25
+ end
26
+ if record.type and !Key::VALID_SSH_KEY_TYPES.include?(record.type)
27
+ record.errors.add("type", {:message => "Invalid key type. Valid types are #{Key::VALID_SSH_KEY_TYPES.join(',')}", :exit_code => 116})
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,18 @@
1
+ class NamespaceValidator < ActiveModel::EachValidator
2
+ NAMESPACE_MAX_LENGTH = 16 unless defined? NAMESPACE_MAX_LENGTH
3
+ NAMESPACE_MIN_LENGTH = 1 unless defined? NAMESPACE_MIN_LENGTH
4
+
5
+ def validate_each(record, attribute, val)
6
+ if !val
7
+ record.errors.add(attribute, {:message => "Namespace is required and cannot be blank.", :exit_code => 106})
8
+ elsif val and val.length < NAMESPACE_MIN_LENGTH
9
+ record.errors.add(attribute, {:message => "Namespace is too short. Minimum length is #{NAMESPACE_MIN_LENGTH} characters.", :exit_code => 106})
10
+ elsif val and val.length > NAMESPACE_MAX_LENGTH
11
+ record.errors.add(attribute, {:message => "Namespace is too long. Maximum length is #{NAMESPACE_MAX_LENGTH} characters.", :exit_code => 106})
12
+ elsif val and !(val =~ /\A[A-Za-z0-9]+\z/)
13
+ record.errors.add(attribute, {:message => "Invalid namespace. Namespace must only contain alphanumeric characters.", :exit_code => 106})
14
+ elsif val and OpenShift::ApplicationContainerProxy.blacklisted? val
15
+ record.errors.add(attribute, {:message => "Namespace is not allowed. Please choose another.", :exit_code => 106})
16
+ end
17
+ end
18
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,36 @@
1
+ Rails.application.routes.draw do
2
+ match 'cartridge' => 'legacy_broker#cartridge_post', :via => [:post]
3
+ match 'embed_cartridge' => 'legacy_broker#embed_cartridge_post', :via => [:post]
4
+ match 'domain' => 'legacy_broker#domain_post', :via => [:post]
5
+ match 'userinfo' => 'legacy_broker#user_info_post', :via => [:post]
6
+ match 'cartlist' => 'legacy_broker#cart_list_post', :via => [:post]
7
+ match 'ssh_keys' => 'legacy_broker#ssh_keys_post', :via => [:post]
8
+ scope "/rest" do
9
+ resource :api, :only => [:show], :controller => :base
10
+ resource :environment, :only => [:show], :controller => :environment
11
+ resource :user, :only => [:show, :destroy], :controller => :user do
12
+ resources :keys, :controller => :keys, :constraints => { :id => /[\w]+/ }
13
+ end
14
+ resources :cartridges, :only => [:index, :show], :constraints => { :id => /standalone|embedded/ }
15
+ resources :quickstarts, :only => [:index, :show]
16
+ resources :application_templates
17
+ #keeping for backward compatibility
18
+ resources :application_template, :controller => :application_templates
19
+ resources :estimates, :constraints => { :id => /[\w]+/ }, :only => [:index, :show]
20
+
21
+ # Allow restful update of the domain name via the standard id parameter
22
+ match "domains/:existing_id" => "domains#update", :via => :put, :existing_id => /[A-Za-z0-9]+/
23
+ resources :domains, :constraints => { :id => /[A-Za-z0-9]+/ } do
24
+ resources :applications, :constraints => { :id => /[\w]+/ } do
25
+ resource :descriptor, :only => [:show]
26
+ resource :gears, :only => [:show]
27
+ resources :gear_groups, :constraints => { :id => /[A-Za-z0-9]+/ }, :only => [:index, :show]
28
+ resources :cartridges, :controller => :emb_cart, :only => [:index, :show, :create, :update, :destroy], :constraints => { :id => /([\w\-]+(-)([\d]+(\.[\d]+)*)+)/ } do
29
+ resources :events, :controller => :emb_cart_events, :only => [:create]
30
+ end
31
+ resources :events, :controller => :app_events, :only => [:create]
32
+ resource :dns_resolvable, :only => [:show], :controller => :dns_resolvable
33
+ end
34
+ end
35
+ end
36
+ end