| 
									
										
										
										
											2015-04-16 17:54:40 +03:00
										 |  |  | module Devops | 
					
						
							| 
									
										
										
										
											2015-07-27 11:14:01 +03:00
										 |  |  |   module API2_0 | 
					
						
							| 
									
										
										
										
											2015-04-16 17:54:40 +03:00
										 |  |  |     module Routes | 
					
						
							| 
									
										
										
										
											2015-07-08 13:43:31 +03:00
										 |  |  |       module StackTemplateRoutes | 
					
						
							| 
									
										
										
										
											2015-04-16 17:54:40 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |         def self.registered(app) | 
					
						
							| 
									
										
										
										
											2015-07-27 11:14:01 +03:00
										 |  |  |           app.get_with_headers '/stack_templates', :headers => [:accept] do | 
					
						
							|  |  |  |             check_privileges('stack_template', 'r') | 
					
						
							|  |  |  |             json Devops::API2_0::Handler::StackTemplate.new(request, params).stack_templates.map(&:to_hash) | 
					
						
							| 
									
										
										
										
											2015-04-16 17:54:40 +03:00
										 |  |  |           end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-27 11:14:01 +03:00
										 |  |  |           app.get_with_headers '/stack_templates/provider/:provider', :headers => [:accept] do |provider| | 
					
						
							|  |  |  |             check_privileges('stack_template', 'r') | 
					
						
							|  |  |  |             check_provider(provider) | 
					
						
							|  |  |  |             json Devops::API2_0::Handler::StackTemplate.new(request, params).stack_templates_for_provider(provider).map(&:to_hash) | 
					
						
							|  |  |  |           end | 
					
						
							| 
									
										
										
										
											2015-04-16 17:54:40 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-27 11:14:01 +03:00
										 |  |  |           app.post_with_headers "/stack_template", :headers => [:accept] do | 
					
						
							|  |  |  |             check_privileges('stack_template', 'w') | 
					
						
							|  |  |  |             body = create_object_from_json_body | 
					
						
							|  |  |  |             model = Devops::API2_0::Handler::StackTemplate.new(request, params).create_stack_template(body) | 
					
						
							|  |  |  |             create_response 'Created', model.to_hash, 201
 | 
					
						
							|  |  |  |           end | 
					
						
							| 
									
										
										
										
											2015-04-16 17:54:40 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |           hash = {} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-27 11:14:01 +03:00
										 |  |  |           hash['GET'] = lambda {|stack_template_id| | 
					
						
							|  |  |  |             check_privileges('stack_template', 'r') | 
					
						
							|  |  |  |             json Devops::API2_0::Handler::StackTemplate.new(request, params).stack_template(stack_template_id).to_hash | 
					
						
							|  |  |  |           } | 
					
						
							| 
									
										
										
										
											2015-04-16 17:54:40 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-27 11:14:01 +03:00
										 |  |  |           hash['DELETE'] = lambda {|stack_template_id| | 
					
						
							|  |  |  |             check_privileges('stack_template', 'w') | 
					
						
							|  |  |  |             Devops::API2_0::Handler::StackTemplate.new(request, params).delete_stack_template(stack_template_id) | 
					
						
							|  |  |  |             create_response("Template '#{stack_template_id}' has been removed") | 
					
						
							|  |  |  |           } | 
					
						
							| 
									
										
										
										
											2015-04-16 17:54:40 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |           app.multi_routes '/stack_template/:stack_template_id', {}, hash | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           puts "Stack_template routes initialized" | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2015-07-27 11:14:01 +03:00
										 |  |  | end |