111 lines
3.4 KiB
Ruby
111 lines
3.4 KiB
Ruby
# encoding: UTF-8
|
|
|
|
require "providers/provider_factory"
|
|
|
|
module Devops
|
|
module API2_0
|
|
module Routes
|
|
module ProviderRoutes
|
|
|
|
def self.registered(app)
|
|
|
|
# Get devops providers
|
|
#
|
|
# * *Request*
|
|
# - method : GET
|
|
# - headers :
|
|
# - Accept: application/json
|
|
#
|
|
# * *Returns* :
|
|
# [
|
|
# "ec2",
|
|
# "openstack"
|
|
# ]
|
|
app.get_with_headers "/providers", :headers => [:accept] do#, &Devops::Version2_0::Handler::Provider.get_providers
|
|
check_privileges("provider", "r")
|
|
json Devops::API2_0::Handler::Provider.new(request).providers
|
|
end
|
|
|
|
# Get list of provider accounts
|
|
#
|
|
# * *Request*
|
|
# - method : GET
|
|
# - headers :
|
|
# - Accept: application/json
|
|
#
|
|
# * *Returns* : array of strings
|
|
# - ec2:
|
|
# {
|
|
# "account_name": "",
|
|
# "description": "",
|
|
# "access_key_id" : "",
|
|
# "ssh_key": "",
|
|
# "certificate" : "path to file",
|
|
# "availability_zone": ""
|
|
#
|
|
# }
|
|
# - openstack:
|
|
# {
|
|
# "account_name": "",
|
|
# "description": "",
|
|
# "username": "",
|
|
# "auth_url": "",
|
|
# "tenant": "",
|
|
# "ssh_key": "",
|
|
# "certificate" : "path to file"
|
|
# }
|
|
# - static:
|
|
# {
|
|
# "account_name": "",
|
|
# "description": "",
|
|
# "ssh_key": "",
|
|
# "certificate" : "path to file"
|
|
# }
|
|
app.get_with_headers "/provider/:provider/accounts", :headers => [:accept] do |provider|
|
|
check_privileges("provider", "r")
|
|
check_provider(provider)
|
|
json Devops::API2_0::Handler::Provider.new(request).accounts(provider)
|
|
end
|
|
|
|
# Create provider account for :provider
|
|
#
|
|
# * *Request*
|
|
# - method : POST
|
|
# - headers :
|
|
# - Accept: application/json
|
|
# - Content-Type: application/json
|
|
# - body :
|
|
# {
|
|
#
|
|
#
|
|
# }
|
|
#
|
|
# * *Returns* : 201
|
|
app.post_with_headers "/provider/:provider/account", :headers => [:accept, :content_type] do |provider|
|
|
check_privileges("provider", "w")
|
|
check_provider(provider)
|
|
create_response("Updated", {:account => Devops::API2_0::Handler::Provider.new(request).add_account(provider)}, 201)
|
|
end
|
|
|
|
# Delete account with name :account_name for :provider
|
|
#
|
|
# * *Request*
|
|
# - method : DELETE
|
|
# - headers :
|
|
# - Accept: application/json
|
|
# - Content-Type: application/json
|
|
#
|
|
# * *Returns* : 200
|
|
app.delete_with_headers "/provider/:provider/account/:account_name", :headers => [:accept, :content_type] do |provider, account_name|
|
|
check_privileges("provider", "w")
|
|
check_provider(provider)
|
|
create_response("Deleted", {:account => Devops::API2_0::Handler::Provider.new(request).delete_account(provider)})
|
|
end
|
|
|
|
puts "Provider routes initialized"
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|