fluke/devops-service/app/api2/routes/stack_template.rb
2015-07-30 15:37:43 +03:00

46 lines
1.7 KiB
Ruby

module Devops
module API2_0
module Routes
module StackTemplateRoutes
def self.registered(app)
app.get_with_headers '/stack_templates', :headers => [:accept] do
check_privileges('stack_template', 'r')
json Devops::API2_0::Handler::StackTemplate.new(request).stack_templates.map(&:to_hash)
end
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).stack_templates_for_provider(provider).map(&:to_hash)
end
app.post_with_headers "/stack_template", :headers => [:accept] do
check_privileges('stack_template', 'w')
model = Devops::API2_0::Handler::StackTemplate.new(request).create_stack_template()
create_response 'Created', model.to_hash, 201
end
hash = {}
hash['GET'] = lambda {|stack_template_id|
check_privileges('stack_template', 'r')
json Devops::API2_0::Handler::StackTemplate.new(request).stack_template(stack_template_id).to_hash
}
hash['DELETE'] = lambda {|stack_template_id|
check_privileges('stack_template', 'w')
Devops::API2_0::Handler::StackTemplate.new(request).delete_stack_template(stack_template_id)
create_response("Template '#{stack_template_id}' has been removed")
}
app.multi_routes '/stack_template/:stack_template_id', {}, hash
puts "Stack_template routes initialized"
end
end
end
end
end