openshift-origin-console 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (291) hide show
  1. data/COPYRIGHT +1 -0
  2. data/Gemfile +21 -0
  3. data/LICENSE +203 -0
  4. data/README.md +123 -0
  5. data/Rakefile +44 -0
  6. data/app/assets/images/cartridge-edge.gif +0 -0
  7. data/app/assets/images/console/arrow-down.png +0 -0
  8. data/app/assets/images/console/console-sprite.png +0 -0
  9. data/app/assets/images/favicon-32.png +0 -0
  10. data/app/assets/images/loader-dark.gif +0 -0
  11. data/app/assets/images/loader.gif +0 -0
  12. data/app/assets/images/sprite-vert.png +0 -0
  13. data/app/assets/javascripts/console.js +10 -0
  14. data/app/assets/javascripts/console/form.js.coffee +51 -0
  15. data/app/assets/stylesheets/_alerts.scss +84 -0
  16. data/app/assets/stylesheets/_breadcrumbs.scss +31 -0
  17. data/app/assets/stylesheets/_buttons.scss +229 -0
  18. data/app/assets/stylesheets/_code.scss +86 -0
  19. data/app/assets/stylesheets/_custom.scss +207 -0
  20. data/app/assets/stylesheets/_footer.scss +54 -0
  21. data/app/assets/stylesheets/_forms.scss +710 -0
  22. data/app/assets/stylesheets/_grid.scss +28 -0
  23. data/app/assets/stylesheets/_input-prepend-append.scss +138 -0
  24. data/app/assets/stylesheets/_labels.scss +40 -0
  25. data/app/assets/stylesheets/_mixins.scss +76 -0
  26. data/app/assets/stylesheets/_override-variables.scss +1 -0
  27. data/app/assets/stylesheets/_responsive.scss +438 -0
  28. data/app/assets/stylesheets/_ribbon.scss +57 -0
  29. data/app/assets/stylesheets/_type.scss +306 -0
  30. data/app/assets/stylesheets/_utilities.scss +10 -0
  31. data/app/assets/stylesheets/_variables.scss +131 -0
  32. data/app/assets/stylesheets/common.css.scss +82 -0
  33. data/app/assets/stylesheets/console/_application.scss +194 -0
  34. data/app/assets/stylesheets/console/_base.scss +26 -0
  35. data/app/assets/stylesheets/console/_breadcrumbs.scss +32 -0
  36. data/app/assets/stylesheets/console/_buttons.scss +214 -0
  37. data/app/assets/stylesheets/console/_core.scss +1002 -0
  38. data/app/assets/stylesheets/console/_dropdowns.scss +63 -0
  39. data/app/assets/stylesheets/console/_help.scss +54 -0
  40. data/app/assets/stylesheets/console/_mixins.scss +11 -0
  41. data/app/assets/stylesheets/console/_navbar.scss +415 -0
  42. data/app/assets/stylesheets/console/_ribbon.scss +82 -0
  43. data/app/assets/stylesheets/console/_tile.scss +122 -0
  44. data/app/assets/stylesheets/origin.css.scss +37 -0
  45. data/app/controllers/account/dashboard.rb +13 -0
  46. data/app/controllers/account_controller.rb +3 -0
  47. data/app/controllers/application_types_controller.rb +80 -0
  48. data/app/controllers/applications_controller.rb +183 -0
  49. data/app/controllers/building_controller.rb +81 -0
  50. data/app/controllers/capability_aware.rb +18 -0
  51. data/app/controllers/cartridge_types_controller.rb +53 -0
  52. data/app/controllers/cartridges_controller.rb +43 -0
  53. data/app/controllers/console/auth/basic.rb +65 -0
  54. data/app/controllers/console/auth/none.rb +5 -0
  55. data/app/controllers/console/auth/remote_user.rb +69 -0
  56. data/app/controllers/console/rescue.rb +48 -0
  57. data/app/controllers/console_controller.rb +19 -0
  58. data/app/controllers/console_index_controller.rb +14 -0
  59. data/app/controllers/domain_aware.rb +26 -0
  60. data/app/controllers/domain_session_sweeper.rb +29 -0
  61. data/app/controllers/domains_controller.rb +30 -0
  62. data/app/controllers/keys_controller.rb +43 -0
  63. data/app/controllers/scaling_controller.rb +46 -0
  64. data/app/controllers/sshkey_aware.rb +23 -0
  65. data/app/controllers/sshkey_session_sweeper.rb +29 -0
  66. data/app/controllers/user_session_sweeper.rb +29 -0
  67. data/app/helpers/console/community_helper.rb +78 -0
  68. data/app/helpers/console/console_helper.rb +26 -0
  69. data/app/helpers/console/help_helper.rb +270 -0
  70. data/app/helpers/console/html5_boilerplate_helper.rb +63 -0
  71. data/app/helpers/console/layout_helper.rb +277 -0
  72. data/app/helpers/console/model_helper.rb +106 -0
  73. data/app/helpers/console/secured_helper.rb +5 -0
  74. data/app/models/alias.rb +10 -0
  75. data/app/models/application.rb +148 -0
  76. data/app/models/application_associations.rb +36 -0
  77. data/app/models/application_template.rb +90 -0
  78. data/app/models/application_type.rb +258 -0
  79. data/app/models/async_aware.rb +60 -0
  80. data/app/models/capabilities.rb +62 -0
  81. data/app/models/cartridge.rb +122 -0
  82. data/app/models/cartridge_type.rb +140 -0
  83. data/app/models/domain.rb +44 -0
  84. data/app/models/domain_associations.rb +33 -0
  85. data/app/models/embedded.rb +11 -0
  86. data/app/models/gear.rb +13 -0
  87. data/app/models/gear_group.rb +104 -0
  88. data/app/models/key.rb +87 -0
  89. data/app/models/quickstart.rb +135 -0
  90. data/app/models/rest_api.rb +130 -0
  91. data/app/models/rest_api/base.rb +781 -0
  92. data/app/models/rest_api/cacheable.rb +91 -0
  93. data/app/models/rest_api/environment.rb +13 -0
  94. data/app/models/rest_api/info.rb +34 -0
  95. data/app/models/rest_api/log_subscriber.rb +29 -0
  96. data/app/models/rest_api/railties/controller_runtime.rb +37 -0
  97. data/app/models/user.rb +27 -0
  98. data/app/models/user_associations.rb +6 -0
  99. data/app/views/account/_domain.html.haml +14 -0
  100. data/app/views/account/_keys.html.haml +20 -0
  101. data/app/views/account/_user.html.haml +5 -0
  102. data/app/views/account/show.html.haml +15 -0
  103. data/app/views/application_templates/_application_template.html.haml +5 -0
  104. data/app/views/application_types/_application_type.html.haml +19 -0
  105. data/app/views/application_types/_custom.html.haml +19 -0
  106. data/app/views/application_types/_persisted.html.haml +26 -0
  107. data/app/views/application_types/_tile.html.haml +9 -0
  108. data/app/views/application_types/index.html.haml +87 -0
  109. data/app/views/application_types/search.html.haml +67 -0
  110. data/app/views/application_types/show.html.haml +219 -0
  111. data/app/views/applications/_application.html.haml +34 -0
  112. data/app/views/applications/_applications_filter.html.haml +8 -0
  113. data/app/views/applications/_footer.html.haml +0 -0
  114. data/app/views/applications/_name.html.haml +28 -0
  115. data/app/views/applications/delete.html.haml +19 -0
  116. data/app/views/applications/get_started.html.haml +145 -0
  117. data/app/views/applications/index.html.haml +55 -0
  118. data/app/views/applications/show.html.haml +193 -0
  119. data/app/views/building/delete.html.haml +22 -0
  120. data/app/views/building/new.html.haml +57 -0
  121. data/app/views/building/show.html.haml +12 -0
  122. data/app/views/cartridge_types/_cartridge_type.html.haml +61 -0
  123. data/app/views/cartridge_types/index.html.haml +37 -0
  124. data/app/views/cartridge_types/show.html.haml +21 -0
  125. data/app/views/cartridges/next_steps.html.haml +58 -0
  126. data/app/views/cartridges/show.html.haml +1 -0
  127. data/app/views/console/error.html.haml +58 -0
  128. data/app/views/console/help.html.haml +90 -0
  129. data/app/views/console/not_found.html.haml +69 -0
  130. data/app/views/console/unauthorized.html.haml +7 -0
  131. data/app/views/domains/_domain.html.haml +14 -0
  132. data/app/views/domains/_form.html.haml +13 -0
  133. data/app/views/domains/edit.html.haml +5 -0
  134. data/app/views/domains/new.html.haml +6 -0
  135. data/app/views/keys/_form.html.haml +14 -0
  136. data/app/views/keys/_simple_form.html.haml +14 -0
  137. data/app/views/keys/new.html.haml +2 -0
  138. data/app/views/layouts/_footer.html.haml +38 -0
  139. data/app/views/layouts/_head.html.haml +35 -0
  140. data/app/views/layouts/console.html.haml +60 -0
  141. data/app/views/layouts/console/_header.html.haml +44 -0
  142. data/app/views/layouts/console/_identity.html.haml +7 -0
  143. data/app/views/layouts/console/_javascripts.html.haml +5 -0
  144. data/app/views/layouts/console/_stylesheets.html.haml +6 -0
  145. data/app/views/scaling/delete.html.haml +17 -0
  146. data/app/views/scaling/new.html.haml +24 -0
  147. data/app/views/scaling/show.html.haml +81 -0
  148. data/app/views/shared/_tracking.html.haml +0 -0
  149. data/conf/console.conf.example +108 -0
  150. data/conf/openshift_console.conf +10 -0
  151. data/config/cartridge_types.yml +54 -0
  152. data/config/initializers/barista_config.rb +86 -0
  153. data/config/initializers/cartridge_types.rb +5 -0
  154. data/config/initializers/console_security.rb +1 -0
  155. data/config/initializers/date_helper.rb +5 -0
  156. data/config/initializers/extended_logger.rb +51 -0
  157. data/config/initializers/formtastic.rb +100 -0
  158. data/config/initializers/inflections.rb +38 -0
  159. data/config/initializers/rdiscount.rb +8 -0
  160. data/config/initializers/rest_api.rb +22 -0
  161. data/config/initializers/sass.rb +30 -0
  162. data/config/initializers/session_trace.rb +32 -0
  163. data/config/initializers/x_frame_options.rb +53 -0
  164. data/config/locales/en.yml +12 -0
  165. data/lib/active_resource/associations.rb +107 -0
  166. data/lib/active_resource/associations/builder/association.rb +35 -0
  167. data/lib/active_resource/associations/builder/belongs_to.rb +5 -0
  168. data/lib/active_resource/associations/builder/has_many.rb +5 -0
  169. data/lib/active_resource/associations/builder/has_one.rb +5 -0
  170. data/lib/active_resource/persistent_connection.rb +341 -0
  171. data/lib/active_resource/persistent_http_mock.rb +68 -0
  172. data/lib/active_resource/reflection.rb +78 -0
  173. data/lib/console.rb +8 -0
  174. data/lib/console/config_file.rb +13 -0
  175. data/lib/console/configuration.rb +163 -0
  176. data/lib/console/engine.rb +28 -0
  177. data/lib/console/formtastic/bootstrap_form_builder.rb +369 -0
  178. data/lib/console/rails/app_redirector.rb +40 -0
  179. data/lib/console/rails/filter_hash.rb +15 -0
  180. data/lib/console/rails/routes.rb +51 -0
  181. data/lib/console/version.rb +5 -0
  182. data/lib/tasks/assets.rake +79 -0
  183. data/lib/tasks/stats.rake +18 -0
  184. data/lib/tasks/test_suites.rake +73 -0
  185. data/test/coverage_helper.rb +27 -0
  186. data/test/fixtures/cartridges.json +1 -0
  187. data/test/fixtures/quickstarts.csv +3 -0
  188. data/test/functional/account_controller_test.rb +14 -0
  189. data/test/functional/application_types_controller_test.rb +251 -0
  190. data/test/functional/applications_controller_sanity_test.rb +26 -0
  191. data/test/functional/applications_controller_test.rb +365 -0
  192. data/test/functional/building_controller_test.rb +203 -0
  193. data/test/functional/cartridge_types_controller_isolation_test.rb +68 -0
  194. data/test/functional/cartridge_types_controller_test.rb +48 -0
  195. data/test/functional/cartridges_controller_test.rb +83 -0
  196. data/test/functional/console_auth_basic_controller_test.rb +82 -0
  197. data/test/functional/console_auth_remote_user_controller_test.rb +90 -0
  198. data/test/functional/console_index_controller_test.rb +22 -0
  199. data/test/functional/domains_controller_test.rb +194 -0
  200. data/test/functional/keys_controller_test.rb +163 -0
  201. data/test/functional/quickstarts.json +18 -0
  202. data/test/functional/scaling_controller_test.rb +153 -0
  203. data/test/integration/assets_test.rb +34 -0
  204. data/test/integration/help_link_test.rb +43 -0
  205. data/test/integration/quickstarts_test.rb +24 -0
  206. data/test/integration/rescue_from_test.rb +25 -0
  207. data/test/integration/rest_api/application_test.rb +115 -0
  208. data/test/integration/rest_api/cartridge_test.rb +44 -0
  209. data/test/integration/rest_api/cartridge_type_test.rb +143 -0
  210. data/test/integration/rest_api/domain_test.rb +91 -0
  211. data/test/integration/rest_api/info_test.rb +9 -0
  212. data/test/integration/rest_api/key_test.rb +85 -0
  213. data/test/integration/static_pages_test.rb +44 -0
  214. data/test/rails_app/Rakefile +7 -0
  215. data/test/rails_app/app/controllers/application_controller.rb +5 -0
  216. data/test/rails_app/config.ru +4 -0
  217. data/test/rails_app/config/application.rb +48 -0
  218. data/test/rails_app/config/boot.rb +10 -0
  219. data/test/rails_app/config/database.yml +25 -0
  220. data/test/rails_app/config/environment.rb +5 -0
  221. data/test/rails_app/config/environments/development.rb +38 -0
  222. data/test/rails_app/config/environments/production.rb +70 -0
  223. data/test/rails_app/config/environments/test.rb +43 -0
  224. data/test/rails_app/config/initializers/auth.rb +0 -0
  225. data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
  226. data/test/rails_app/config/initializers/inflections.rb +10 -0
  227. data/test/rails_app/config/initializers/mime_types.rb +5 -0
  228. data/test/rails_app/config/initializers/secret_token.rb +7 -0
  229. data/test/rails_app/config/initializers/session_store.rb +8 -0
  230. data/test/rails_app/config/locales/en.yml +5 -0
  231. data/test/rails_app/config/routes.rb +4 -0
  232. data/test/rails_app/script/rails +6 -0
  233. data/test/support/auth.rb +111 -0
  234. data/test/support/base.rb +142 -0
  235. data/test/support/errors.rb +28 -0
  236. data/test/support/rest_api.rb +189 -0
  237. data/test/test_helper.rb +14 -0
  238. data/test/unit/active_model_compliance_test.rb +23 -0
  239. data/test/unit/async_aware_test.rb +55 -0
  240. data/test/unit/configuration_test.rb +158 -0
  241. data/test/unit/filter_hash_test.rb +64 -0
  242. data/test/unit/helpers/model_helper_test.rb +61 -0
  243. data/test/unit/overrides_test.rb +9 -0
  244. data/test/unit/rest_api_test.rb +1590 -0
  245. data/vendor/assets/javascripts/MIT-LICENSE.txt +20 -0
  246. data/vendor/assets/javascripts/bootstrap-collapse.js +157 -0
  247. data/vendor/assets/javascripts/bootstrap-dropdown.js +100 -0
  248. data/vendor/assets/javascripts/bootstrap-tab.js +135 -0
  249. data/vendor/assets/javascripts/bootstrap-transition.js +61 -0
  250. data/vendor/assets/javascripts/jquery.spin.js +47 -0
  251. data/vendor/assets/javascripts/jquery.ui.widget.js +16 -0
  252. data/vendor/assets/javascripts/jquery_cookie.js +41 -0
  253. data/vendor/assets/javascripts/jquery_validate_min.js +51 -0
  254. data/vendor/assets/javascripts/modernizr.min.js +2 -0
  255. data/vendor/assets/javascripts/plugins.js +16 -0
  256. data/vendor/assets/stylesheets/bootstrap/_accordion.scss +28 -0
  257. data/vendor/assets/stylesheets/bootstrap/_alerts.scss +70 -0
  258. data/vendor/assets/stylesheets/bootstrap/_breadcrumbs.scss +22 -0
  259. data/vendor/assets/stylesheets/bootstrap/_button-groups.scss +147 -0
  260. data/vendor/assets/stylesheets/bootstrap/_buttons.scss +183 -0
  261. data/vendor/assets/stylesheets/bootstrap/_carousel.scss +121 -0
  262. data/vendor/assets/stylesheets/bootstrap/_close.scss +18 -0
  263. data/vendor/assets/stylesheets/bootstrap/_code.scss +57 -0
  264. data/vendor/assets/stylesheets/bootstrap/_component-animations.scss +18 -0
  265. data/vendor/assets/stylesheets/bootstrap/_dropdowns.scss +130 -0
  266. data/vendor/assets/stylesheets/bootstrap/_forms.scss +522 -0
  267. data/vendor/assets/stylesheets/bootstrap/_grid.scss +8 -0
  268. data/vendor/assets/stylesheets/bootstrap/_hero-unit.scss +20 -0
  269. data/vendor/assets/stylesheets/bootstrap/_labels.scss +32 -0
  270. data/vendor/assets/stylesheets/bootstrap/_layouts.scss +17 -0
  271. data/vendor/assets/stylesheets/bootstrap/_mixins.scss +602 -0
  272. data/vendor/assets/stylesheets/bootstrap/_modals.scss +84 -0
  273. data/vendor/assets/stylesheets/bootstrap/_navbar.scss +299 -0
  274. data/vendor/assets/stylesheets/bootstrap/_navs.scss +353 -0
  275. data/vendor/assets/stylesheets/bootstrap/_pager.scss +30 -0
  276. data/vendor/assets/stylesheets/bootstrap/_pagination.scss +55 -0
  277. data/vendor/assets/stylesheets/bootstrap/_popovers.scss +49 -0
  278. data/vendor/assets/stylesheets/bootstrap/_progress-bars.scss +95 -0
  279. data/vendor/assets/stylesheets/bootstrap/_reset.scss +126 -0
  280. data/vendor/assets/stylesheets/bootstrap/_scaffolding.scss +33 -0
  281. data/vendor/assets/stylesheets/bootstrap/_sprites.scss +158 -0
  282. data/vendor/assets/stylesheets/bootstrap/_tables.scss +150 -0
  283. data/vendor/assets/stylesheets/bootstrap/_thumbnails.scss +35 -0
  284. data/vendor/assets/stylesheets/bootstrap/_tooltip.scss +35 -0
  285. data/vendor/assets/stylesheets/bootstrap/_type.scss +218 -0
  286. data/vendor/assets/stylesheets/bootstrap/_utilities.scss +23 -0
  287. data/vendor/assets/stylesheets/bootstrap/_variables.scss +107 -0
  288. data/vendor/assets/stylesheets/bootstrap/_wells.scss +17 -0
  289. data/vendor/assets/stylesheets/bootstrap/bootstrap.scss +66 -0
  290. data/vendor/assets/stylesheets/bootstrap/responsive.scss +334 -0
  291. metadata +506 -0
@@ -0,0 +1,11 @@
1
+ class Embedded < RestApi::Base
2
+ def info(cart)
3
+ @attributes[cart].info rescue nil
4
+ end
5
+
6
+ #FIXME: Bug 820651 should make this cleaner to retrieve
7
+ def jenkins_build_url
8
+ client = info('jenkins-client-1.4')
9
+ ((client || '').chomp)[/Job URL: ([^\s]*)\s*/, 1]
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ class Gear < RestApi::Base
2
+ schema do
3
+ string :id, :gear_profile, :state
4
+ end
5
+ #custom_id :id
6
+
7
+ belongs_to :application
8
+ has_many :components, :class_name => 'rest_api/base/attribute_hash'
9
+
10
+ def state
11
+ (super || :unknown).to_sym
12
+ end
13
+ end
@@ -0,0 +1,104 @@
1
+ class GearGroup < RestApi::Base
2
+ schema do
3
+ string :name, :gear_profile
4
+ integer :scales_from, :scales_to
5
+ integer :supported_scales_from, :supported_scales_to
6
+ end
7
+ custom_id :name
8
+
9
+ belongs_to :application
10
+
11
+ has_many :gears
12
+ has_many :cartridges
13
+
14
+ def gears
15
+ @attributes['gears'] ||= []
16
+ end
17
+ def cartridges
18
+ @attributes['cartridges'] ||= []
19
+ end
20
+
21
+ def gear_profile
22
+ (@attributes['gear_profile'] || :small).to_sym
23
+ end
24
+
25
+ def states
26
+ gears.map{ |g| g.state }
27
+ end
28
+
29
+ def exposes
30
+ @exposes ||= cartridges.inject({}) { |h, c| h[c.name] = c; h }
31
+ end
32
+ def exposes?(cart=nil, &block)
33
+ if cart
34
+ exposes.has_key? cart
35
+ elsif block_given?
36
+ cartridges.any? &block
37
+ end
38
+ end
39
+
40
+ def cartridge_names
41
+ exposes.keys
42
+ end
43
+
44
+ def scales?
45
+ supported_scales_to != supported_scales_from
46
+ end
47
+ def builds?
48
+ @builds
49
+ end
50
+
51
+ def supported_scales_from
52
+ super || 1
53
+ end
54
+
55
+ def supported_scales_to
56
+ super || -1
57
+ end
58
+
59
+ def ==(other)
60
+ super && other.gears == gears && other.cartridges == cartridges
61
+ end
62
+
63
+ def merge_gears(others)
64
+ Array(others).select{ |o| !(cartridges & o.cartridges).empty? }.each{ |o| gears.concat(o.gears) }
65
+ gears.uniq!
66
+ self
67
+ end
68
+
69
+ def self.infer(cartridges, application)
70
+ groups = cartridges.group_by(&:grouping).map do |a|
71
+ GearGroup.new({
72
+ :cartridges => a[1].sort!,
73
+ :gear_profile => a[1].first.gear_profile
74
+ }, true)
75
+ end
76
+ groups.delete_if{ |g| g.send(:move_features, groups[0]) }
77
+ groups.sort!{ |a,b| a.cartridges.first <=> b.cartridges.first }
78
+
79
+ if groups.first
80
+ cart = groups.first.cartridges.first
81
+ cart.git_url = application.git_url
82
+ cart.ssh_url = application.ssh_url
83
+ cart.ssh_string = application.ssh_string
84
+ end
85
+ groups
86
+ end
87
+
88
+ protected
89
+ #
90
+ # Return true if the group is now empty
91
+ #
92
+ def move_features(to)
93
+ cartridges.delete_if do |c|
94
+ if c.tags.include?(:ci_builder) and not c.tags.include?(:web_framework)
95
+ to.cartridges.select{ |d| d.tags.include?(:web_framework) }.each{ |d| d.builds_with(c, self) }.present?
96
+ end
97
+ end
98
+ cartridges.delete_if{ |c| cartridges.any?{ |other| other != c && other.scales_with == c.name } }
99
+ if self != to && cartridges.empty?
100
+ to.gears.concat(gears)
101
+ gears.clear
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,87 @@
1
+ #
2
+ # The REST API model object representing an SSH public key.
3
+ #
4
+ class Key < RestApi::Base
5
+ #self.element_name = 'key'
6
+ #self.primary_key = 'name'
7
+
8
+ class DuplicateName < ActiveResource::ResourceConflict ; end
9
+ on_exit_code 120, DuplicateName
10
+
11
+ schema do
12
+ string :name, 'type', :content, :raw_content
13
+ end
14
+ custom_id :name, true
15
+ def id # support ID for legacy code which retrieves keys by .id
16
+ name
17
+ end
18
+
19
+ # type is a method on Object in 1.8.7 and must be overriden so that the attribute
20
+ # will be read (method_missing is how ActiveResource attributes are looked up)
21
+ def type
22
+ @attributes[:type]
23
+ end
24
+
25
+ belongs_to :user
26
+
27
+ attr_alters :raw_content, [:content, :type]
28
+ # Raw content is decomposed into content and type
29
+ def raw_content=(contents)
30
+ if contents
31
+ parts = contents.split
32
+ case parts.length
33
+ when 0
34
+ self.type = self.content = nil
35
+ when 1
36
+ self.type = nil
37
+ self.content = parts[0]
38
+ else
39
+ self.type, self.content = parts
40
+ end
41
+ end
42
+ super
43
+ end
44
+
45
+ validates :name, :presence => true, :allow_blank => false
46
+ #validates_format_of 'type',
47
+ # :with => /^ssh-(rsa|dss)$/,
48
+ # :message => "is not ssh-rsa or ssh-dss"
49
+ validates :content, :presence => true, :allow_blank => false
50
+
51
+ Inf = 1.0/0.0 # Replace with Float::INFINITY in 1.9 ruby
52
+ def make_unique!(format='key %s')
53
+ unless persisted?
54
+ keys = Key.find(:all, :as => as)
55
+ if keys.any? {|k| k.name == name }
56
+ self.name = format % (2..keys.length+2).find do |i|
57
+ not keys.any? {|k| k.name == format % i}
58
+ end
59
+ end
60
+ end
61
+ self
62
+ end
63
+
64
+ def display_content
65
+ if content.length > 20
66
+ "#{content[1..8]}..#{content[-8..-1]}"
67
+ else
68
+ content
69
+ end
70
+ end
71
+
72
+ #
73
+ # Until the empty default key is attached from domain, ignore in lists
74
+ #
75
+ def default?
76
+ 'default' == name
77
+ end
78
+ def empty_default?
79
+ default? and (!content or content.blank? or 'nossh' == content)
80
+ end
81
+
82
+ class << self
83
+ def default(options=nil)
84
+ Key.find('default', options)
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,135 @@
1
+ class Quickstart < RestApi::Base
2
+ include RestApi::Cacheable
3
+ allow_anonymous
4
+
5
+ instance_variable_set(:@connection, nil)
6
+
7
+ schema do
8
+ string :id, :name, :href, :initial_git_url, :initial_git_branch
9
+ string :website
10
+ string :body, :summary
11
+ integer :priority
12
+ end
13
+
14
+ Disabled = Class.new(StandardError)
15
+ SearchDisabled = Class.new(StandardError)
16
+
17
+ alias_attribute :display_name, :name
18
+ alias_attribute :description, :summary
19
+
20
+ def name
21
+ entity_decoded(super)
22
+ end
23
+
24
+ def priority
25
+ super.to_i rescue 0
26
+ end
27
+
28
+ def learn_more_url
29
+ URI.join(self.class.site, href).to_s if href
30
+ end
31
+
32
+ def tags
33
+ @tags ||= ApplicationType.user_tags(tags_from(attributes[:tags])) + admin_tags + (3.days.ago < updated ? [:new] : [])
34
+ end
35
+
36
+ def updated
37
+ @updated ||= Time.at(attributes[:updated].to_i)
38
+ end
39
+
40
+ def cartridges_spec
41
+ entity_decoded(attributes[:cartridges])
42
+ end
43
+
44
+ # This is a short-term fix for BZ877849
45
+ # The drupal quickstart nodes need to be augmented with a flag to
46
+ # indicate whether or not they can be scaled.
47
+ NON_SCALABLE = Regexp.new(['wordpress','drupal','spring','capedwarf','javaee'].join('|'),true)
48
+ def scalable
49
+ retval = !self.name.match(NON_SCALABLE)
50
+ ensure
51
+ Rails.logger.debug("Handling #{self.name} quickstart as non-scalable") unless retval
52
+ end
53
+ alias_method :scalable?, :scalable
54
+
55
+ def >>(application)
56
+ #application.cartridges = cartridges
57
+ application.initial_git_url = initial_git_url
58
+ application
59
+ end
60
+
61
+ cache_method :find_every, :expires_in => 10.minutes
62
+
63
+ class << self
64
+ def promoted(opts={})
65
+ all({:from => (api_links[:list] or raise Disabled)}.merge(opts))
66
+ rescue Disabled
67
+ []
68
+ end
69
+
70
+ def search(terms, opts={})
71
+ all(opts.merge(
72
+ :from => (api_links[:search] or raise SearchDisabled),
73
+ :params => {
74
+ (api_links[:search_param] or raise SearchDisabled) => terms
75
+ }
76
+ ))
77
+ rescue SearchDisabled
78
+ terms.downcase!
79
+ promoted(opts).select do |q|
80
+ q.description.downcase.include?(terms) or
81
+ q.display_name.downcase.include?(terms) or
82
+ (q.tags.include?(terms.to_sym) rescue false)
83
+ end
84
+ end
85
+
86
+ def disabled?
87
+ !api_links[:list] rescue true
88
+ end
89
+
90
+ def site
91
+ api_links[:site] or RestApi::Info.site
92
+ end
93
+ def prefix_parameters
94
+ {}
95
+ end
96
+
97
+ def reset!
98
+ @api_links = nil
99
+ end
100
+
101
+ protected
102
+ def collection_path(*args)
103
+ api_links[:list] rescue super
104
+ end
105
+ def element_path(id, prefix_options = {}, query_options = nil)
106
+ api_links[:get].gsub(/:id/, id.to_s) rescue super
107
+ end
108
+ def api_links
109
+ @api_links ||= begin
110
+ info = RestApi::Info.cached.find :one
111
+ {
112
+ :site => (URI.join(info.link("LIST_QUICKSTARTS"), '/') rescue nil),
113
+ :list => (info.link("LIST_QUICKSTARTS").path rescue nil),
114
+ :get => (info.link("SHOW_QUICKSTART").path rescue nil),
115
+ :search => (info.link("SEARCH_QUICKSTARTS").path rescue nil),
116
+ :search_param => (info.required_params('SEARCH_QUICKSTARTS').first[:name] rescue nil),
117
+ }
118
+ end
119
+ end
120
+
121
+ def instantiate_record(record, *args)
122
+ super record.is_a?(Array) ? record.first : record, *args
123
+ end
124
+ end
125
+
126
+ protected
127
+ def admin_tags
128
+ @admin_tags ||= tags_from(attributes[:admin_tags])
129
+ end
130
+
131
+ private
132
+ def tags_from(s)
133
+ (s.is_a?(Array) ? s : ((s || '').split(','))).map(&:strip).map(&:downcase).map(&:to_sym)
134
+ end
135
+ end
@@ -0,0 +1,130 @@
1
+ module RestApi
2
+ #
3
+ # An Authorization object should expose:
4
+ #
5
+ # login - method returning an identifier for the user
6
+ #
7
+ # and one of:
8
+ #
9
+ # ticket - the unique ticket for the session
10
+ # password - a user password
11
+ #
12
+ class Authorization
13
+ attr_reader :login, :ticket, :password
14
+ def initialize(login,ticket=nil,password=nil)
15
+ @login = login
16
+ @ticket = ticket
17
+ @password = password
18
+ end
19
+ def cache_key
20
+ login
21
+ end
22
+ end
23
+
24
+ # During retrieval of info about the API, an error occurred
25
+ class ApiNotAvailable < StandardError ; end
26
+
27
+ # Raised when the authorization context is missing
28
+ class MissingAuthorizationError < StandardError ; end
29
+
30
+ # Raised when a newly created resource exists with the same unique primary key
31
+ class ResourceExistsError < StandardError ; end
32
+
33
+ class ResourceNotFound < ActiveResource::ResourceNotFound
34
+ attr_reader :id
35
+ def initialize(model, id, response=nil)
36
+ @id, @model = id, model
37
+ super(response)
38
+ end
39
+ def model
40
+ @model.constantize rescue RestApi::Base
41
+ end
42
+ def domain_missing?
43
+ @model == 'Domain' || RestApi::Base.remote_errors_for(response).any?{ |m| m[0] == 127 } rescue false
44
+ end
45
+ def to_s
46
+ "#{model.to_s.titleize}#{ " '#{id}'" unless id.nil?} does not exist"
47
+ end
48
+ end
49
+
50
+ # The server did not return the response we were expecting, possibly a server bug
51
+ class BadServerResponseError < StandardError ; end
52
+
53
+ class << self
54
+ #
55
+ # All code in the block will dump detailed HTTP logs
56
+ #
57
+ def debug(set=true,&block)
58
+ @debug = set
59
+ if block_given?
60
+ begin
61
+ yield block
62
+ ensure
63
+ @debug = false
64
+ end
65
+ end
66
+ end
67
+ def debug?
68
+ @debug || ENV['REST_API_DEBUG']
69
+ end
70
+ def force_http_debug
71
+ unless ActiveResource::Connection.respond_to? :configure_http_with_debug
72
+ ActiveResource::Connection.class_eval do
73
+ def configure_http_with_debug(http)
74
+ configure_http_without_debug(http)
75
+ http.set_debug_output $stderr
76
+ http
77
+ end
78
+ alias_method_chain :configure_http, :debug
79
+ end
80
+ end
81
+ end
82
+
83
+ #
84
+ # Is the API reachable?
85
+ #
86
+ def test?
87
+ info.present? rescue false
88
+ end
89
+
90
+ #
91
+ # Return the version information about the REST API
92
+ #
93
+ def info
94
+ RestApi::Info.cached.find :one
95
+ rescue Exception => e
96
+ raise ApiNotAvailable, <<-EXCEPTION, e.backtrace
97
+
98
+ The REST API could not be reached at #{RestApi::Base.site}
99
+
100
+ Rails environment: #{Rails.env}
101
+ Current configuration: #{config.inspect} #{config[:symbol] ? "(via :#{config[:symbol]})" : ''}
102
+
103
+ #{e.message}
104
+ #{e.backtrace.join("\n ")}
105
+ EXCEPTION
106
+ end
107
+
108
+ def reset!
109
+ @info = nil
110
+ end
111
+
112
+ # FIXME: May be desirable to replace this with a standard ActiveSupport config object
113
+ def config
114
+ RestApi::Base.instance_variable_get("@last_config") || {}
115
+ end
116
+
117
+ def application_domain_suffix
118
+ @application_domain_suffix ||= RestApi::Environment.cached.find(:one).domain_suffix
119
+ end
120
+
121
+ def site
122
+ RestApi::Base.site
123
+ end
124
+
125
+ private
126
+ def symbol
127
+ RestApi::Base.instance_variable_get('@symbol')
128
+ end
129
+ end
130
+ end