608 lines
		
	
	
		
			17 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
		
		
			
		
	
	
			608 lines
		
	
	
		
			17 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
|   | require 'swagger/blocks' | ||
|  | 
 | ||
|  | require_relative 'devops_error' | ||
|  | require_relative 'devops_response' | ||
|  | 
 | ||
|  | module Devops | ||
|  |   module API3 | ||
|  |     module Docs | ||
|  |       class ProviderRoutes | ||
|  | 
 | ||
|  |         include Swagger::Blocks | ||
|  | 
 | ||
|  |         swagger_path "/providers/available" do | ||
|  |           operation :get do | ||
|  |             key :description, 'Get providers list from configuration file' | ||
|  |             key :operationId, 'getProvidersAvailable' | ||
|  |             key :tags, [ | ||
|  |               'provider' | ||
|  |             ] | ||
|  |             response 200 do | ||
|  |               key :description, 'Providers response' | ||
|  |               schema do | ||
|  |                 key :type, :array | ||
|  |                 items do | ||
|  |                   key :type, :string | ||
|  |                 end | ||
|  |               end | ||
|  |             end | ||
|  |             response :default do | ||
|  |               key :description, 'error' | ||
|  |               schema do | ||
|  |                 key :'$ref', :DevopsError | ||
|  |               end | ||
|  |             end | ||
|  |           end | ||
|  |         end | ||
|  | 
 | ||
|  |         swagger_path "/providers" do | ||
|  |           operation :get do | ||
|  |             key :description, 'Get providers list' | ||
|  |             key :operationId, 'getProviders' | ||
|  |             key :tags, [ | ||
|  |               'provider' | ||
|  |             ] | ||
|  |             response 200 do | ||
|  |               key :description, 'Providers response' | ||
|  |               schema do | ||
|  |                 key :type, :array | ||
|  |                 items do | ||
|  |                   key :type, :string | ||
|  |                 end | ||
|  |               end | ||
|  |             end | ||
|  |             response :default do | ||
|  |               key :description, 'error' | ||
|  |               schema do | ||
|  |                 key :'$ref', :DevopsError | ||
|  |               end | ||
|  |             end | ||
|  |           end | ||
|  |         end | ||
|  | 
 | ||
|  |         swagger_schema :CommonAccount do | ||
|  |           allOf do | ||
|  |             schema do | ||
|  |               key :'$ref', :CommonAccountInput | ||
|  |             end | ||
|  |             schema do | ||
|  |               property :provider do | ||
|  |                 key :type, :string | ||
|  |               end | ||
|  |               property :created_at do | ||
|  |                 key :type, :integer | ||
|  |                 key :format, :int64 | ||
|  |               end | ||
|  |             end | ||
|  |           end | ||
|  |         end | ||
|  | 
 | ||
|  |         swagger_schema :CommonAccountInput do | ||
|  |           key :required, [:account_name, :ssh_key] | ||
|  |           property :account_name do | ||
|  |             key :type, :string | ||
|  |             key :pattern, "^[a-z_][a-z0-9_-]{0,99}$" | ||
|  |             key :maxLength, 100
 | ||
|  |           end | ||
|  |           property :description do | ||
|  |             key :type, :string | ||
|  |             key :maxLength, 500
 | ||
|  |           end | ||
|  |           property :ssh_key do | ||
|  |             key :type, :string | ||
|  |             key :pattern, "^[a-z_][a-z0-9_-]{0,99}$" | ||
|  |             key :maxLength, 100
 | ||
|  |           end | ||
|  |         end | ||
|  | 
 | ||
|  |         ###### static provider - begin | ||
|  |         swagger_path "/provider/static/accounts" do | ||
|  |           operation :get do | ||
|  |             key :description, 'Get static provider accounts' | ||
|  |             key :operationId, 'getStaticProviderAccounts' | ||
|  |             key :tags, [ | ||
|  |               'provider' | ||
|  |             ] | ||
|  |             response 200 do | ||
|  |               key :description, 'Static provider account response' | ||
|  |               schema do | ||
|  |                 key :type, :array | ||
|  |                 items do | ||
|  |                   key :'$ref', :StaticProviderAccount | ||
|  |                 end | ||
|  |               end | ||
|  |             end | ||
|  |             response :default do | ||
|  |               key :description, 'error' | ||
|  |               schema do | ||
|  |                 key :'$ref', :DevopsError | ||
|  |               end | ||
|  |             end | ||
|  |           end | ||
|  |         end | ||
|  | 
 | ||
|  |         swagger_path "/provider/static/account" do | ||
|  |           operation :post do | ||
|  |             key :description, 'Create static provider account' | ||
|  |             key :operationId, 'createStaticProviderAccount' | ||
|  |             key :tags, [ | ||
|  |               'provider' | ||
|  |             ] | ||
|  |             parameter do | ||
|  |               key :name, :account | ||
|  |               key :in, :body | ||
|  |               key :description, 'Account to add for static provider' | ||
|  |               key :required, true | ||
|  |               schema do | ||
|  |                 key :'$ref', :StaticProviderAccountInput | ||
|  |               end | ||
|  |             end | ||
|  |             response 200 do | ||
|  |               key :description, 'Static provider account response' | ||
|  |               schema do | ||
|  |                 key :'$ref', :StaticProviderAccountResponse | ||
|  |               end | ||
|  |             end | ||
|  |             response :default do | ||
|  |               key :description, 'error' | ||
|  |               schema do | ||
|  |                 key :'$ref', :DevopsError | ||
|  |               end | ||
|  |             end | ||
|  |           end | ||
|  |         end | ||
|  | 
 | ||
|  |         swagger_schema :StaticProviderAccount do | ||
|  |           allOf do | ||
|  |             schema do | ||
|  |               key :'$ref', :CommonAccount | ||
|  |             end | ||
|  |           end | ||
|  |         end | ||
|  | 
 | ||
|  |         swagger_schema :StaticProviderAccountResponse do | ||
|  |           allOf do | ||
|  |             schema do | ||
|  |               key :'$ref', :DevopsResponse | ||
|  |             end | ||
|  |             schema do | ||
|  |               property :account do | ||
|  |                 key :'$ref', :StaticProviderAccount | ||
|  |               end | ||
|  |             end | ||
|  |           end | ||
|  |         end | ||
|  | 
 | ||
|  |         swagger_schema :StaticProviderAccountInput do | ||
|  |           allOf do | ||
|  |             schema do | ||
|  |               key :'$ref', :CommonAccountInput | ||
|  |             end | ||
|  |           end | ||
|  |         end | ||
|  |         ###### static provider - end | ||
|  |         # | ||
|  |         ###### aws provider - begin | ||
|  |         swagger_path "/provider/aws/accounts" do | ||
|  |           operation :get do | ||
|  |             key :description, 'Get aws provider accounts' | ||
|  |             key :operationId, 'getAwsProviderAccounts' | ||
|  |             key :tags, [ | ||
|  |               'provider' | ||
|  |             ] | ||
|  |             response 200 do | ||
|  |               key :description, 'Aws provider accounts response' | ||
|  |               schema do | ||
|  |                 key :type, :array | ||
|  |                 items do | ||
|  |                   key :'$ref', :AwsProviderAccount | ||
|  |                 end | ||
|  |               end | ||
|  |             end | ||
|  |             response :default do | ||
|  |               key :description, 'error' | ||
|  |               schema do | ||
|  |                 key :'$ref', :DevopsError | ||
|  |               end | ||
|  |             end | ||
|  |           end | ||
|  |         end | ||
|  | 
 | ||
|  |         swagger_path "/provider/aws/account" do | ||
|  |           operation :post do | ||
|  |             key :description, 'Create aws provider account' | ||
|  |             key :operationId, 'createAwsProviderAccount' | ||
|  |             key :tags, [ | ||
|  |               'provider' | ||
|  |             ] | ||
|  |             parameter do | ||
|  |               key :name, :account | ||
|  |               key :in, :body | ||
|  |               key :description, 'Account to add for aws provider' | ||
|  |               key :required, true | ||
|  |               schema do | ||
|  |                 key :'$ref', :AwsProviderAccountInput | ||
|  |               end | ||
|  |             end | ||
|  |             response 200 do | ||
|  |               key :description, 'Aws provider accounts response' | ||
|  |               schema do | ||
|  |                 key :'$ref', :AwsProviderAccountResponse | ||
|  |               end | ||
|  |             end | ||
|  |             response :default do | ||
|  |               key :description, 'error' | ||
|  |               schema do | ||
|  |                 key :'$ref', :DevopsError | ||
|  |               end | ||
|  |             end | ||
|  |           end | ||
|  |         end | ||
|  | 
 | ||
|  |         swagger_path "/provider/aws/account/{account_name}/vpcs" do | ||
|  |           operation :get do | ||
|  |             key :description, 'Get aws provider vpcs for account' | ||
|  |             key :operationId, 'getAwsProviderVpcs' | ||
|  |             key :tags, [ | ||
|  |               'provider' | ||
|  |             ] | ||
|  |             parameter do | ||
|  |               key :name, :account_name | ||
|  |               key :in, :path | ||
|  |               key :description, 'Aws provider account name' | ||
|  |               key :required, true | ||
|  |               key :type, :string | ||
|  |             end | ||
|  |             response 200 do | ||
|  |               key :description, 'Aws provider account vpcs response' | ||
|  |               schema do | ||
|  |                 key :type, :array | ||
|  |                 items do | ||
|  |                   key :'$ref', :AwsProviderVpcResponse | ||
|  |                 end | ||
|  |               end | ||
|  |             end | ||
|  |             response :default do | ||
|  |               key :description, 'error' | ||
|  |               schema do | ||
|  |                 key :'$ref', :DevopsError | ||
|  |               end | ||
|  |             end | ||
|  |           end | ||
|  |         end | ||
|  | 
 | ||
|  |         swagger_schema :AwsProviderVpcResponse do | ||
|  |           property :vpc_id do | ||
|  |             key :type, :string | ||
|  |           end | ||
|  |           property :cidr do | ||
|  |             key :type, :string | ||
|  |           end | ||
|  |         end | ||
|  | 
 | ||
|  |         swagger_schema :AwsProviderAccount do | ||
|  |           allOf do | ||
|  |             schema do | ||
|  |               key :'$ref', :CommonAccount | ||
|  |             end | ||
|  |             schema do | ||
|  |               key :'$ref', :AwsProviderAccountInput | ||
|  |             end | ||
|  |           end | ||
|  |         end | ||
|  | 
 | ||
|  |         swagger_schema :AwsProviderAccountResponse do | ||
|  |           allOf do | ||
|  |             schema do | ||
|  |               key :'$ref', :DevopsResponse | ||
|  |             end | ||
|  |             schema do | ||
|  |               property :account do | ||
|  |                 key :'$ref', :AwsProviderAccount | ||
|  |               end | ||
|  |             end | ||
|  |           end | ||
|  |         end | ||
|  | 
 | ||
|  |         swagger_schema :AwsProviderAccountInput do | ||
|  |           allOf do | ||
|  |             schema do | ||
|  |               key :'$ref', :CommonAccountInput | ||
|  |             end | ||
|  |             schema do | ||
|  |               key :required, [:account_name, :ssh_key, :use_iam_profile] | ||
|  |               property :access_key_id do | ||
|  |                 key :type, :string | ||
|  |               end | ||
|  |               property :secret_access_key do | ||
|  |                 key :type, :string | ||
|  |               end | ||
|  |               property :use_iam_profile do | ||
|  |                 key :type, :boolean | ||
|  |               end | ||
|  |               property :storage_bucket_name do | ||
|  |                 key :type, :string | ||
|  |               end | ||
|  |             end | ||
|  |           end | ||
|  |         end | ||
|  |         ###### aws provider - end | ||
|  | 
 | ||
|  |         swagger_path "/provider/{provider}/account/{account_name}" do | ||
|  |           operation :delete do | ||
|  |             key :description, 'Delete provider account' | ||
|  |             key :operationId, 'deleteProviderAccount' | ||
|  |             key :tags, [ | ||
|  |               'provider' | ||
|  |             ] | ||
|  |             parameter do | ||
|  |               key :name, :provider | ||
|  |               key :in, :path | ||
|  |               key :description, 'Provider name' | ||
|  |               key :required, true | ||
|  |               key :type, :string | ||
|  |             end | ||
|  |             parameter do | ||
|  |               key :name, :account_name | ||
|  |               key :in, :path | ||
|  |               key :description, 'Provider account name' | ||
|  |               key :required, true | ||
|  |               key :type, :string | ||
|  |             end | ||
|  |             response 200 do | ||
|  |               key :description, 'Provider account response' | ||
|  |               schema do | ||
|  |                 key :'$ref', :DevopsResponse | ||
|  |               end | ||
|  |             end | ||
|  |             response :default do | ||
|  |               key :description, 'error' | ||
|  |               schema do | ||
|  |                 key :'$ref', :DevopsError | ||
|  |               end | ||
|  |             end | ||
|  |           end | ||
|  |         end | ||
|  | 
 | ||
|  |         swagger_path "/provider/{provider}/account/{account_name}/images" do | ||
|  |           operation :get do | ||
|  |             key :description, 'Get provider account images' | ||
|  |             key :operationId, 'getProviderImages' | ||
|  |             key :tags, [ | ||
|  |               'provider' | ||
|  |             ] | ||
|  |             parameter do | ||
|  |               key :name, :provider | ||
|  |               key :in, :path | ||
|  |               key :description, 'Provider name' | ||
|  |               key :required, true | ||
|  |               key :type, :string | ||
|  |             end | ||
|  |             parameter do | ||
|  |               key :name, :account_name | ||
|  |               key :in, :path | ||
|  |               key :description, 'Aws provider account name' | ||
|  |               key :required, true | ||
|  |               key :type, :string | ||
|  |             end | ||
|  |             response 200 do | ||
|  |               key :description, 'Provider images response' | ||
|  |               schema do | ||
|  |                 key :type, :array | ||
|  |                 items do | ||
|  |                   key :'$ref', :ProviderImageResponse | ||
|  |                 end | ||
|  |               end | ||
|  |             end | ||
|  |             response :default do | ||
|  |               key :description, 'error' | ||
|  |               schema do | ||
|  |                 key :'$ref', :DevopsError | ||
|  |               end | ||
|  |             end | ||
|  |           end | ||
|  |         end | ||
|  | 
 | ||
|  |         swagger_schema :ProviderImageResponse do | ||
|  |           property :id do | ||
|  |             key :type, :string | ||
|  |           end | ||
|  |           property :name do | ||
|  |             key :type, :string | ||
|  |           end | ||
|  |           property :status do | ||
|  |             key :type, :string | ||
|  |           end | ||
|  |         end | ||
|  | 
 | ||
|  |         swagger_path "/provider/{provider}/account/{account_name}/networks" do | ||
|  |           operation :get do | ||
|  |             key :description, 'Get provider account networks' | ||
|  |             key :operationId, 'getProviderNetworks' | ||
|  |             key :tags, [ | ||
|  |               'provider' | ||
|  |             ] | ||
|  |             parameter do | ||
|  |               key :name, :provider | ||
|  |               key :in, :path | ||
|  |               key :description, 'Provider name' | ||
|  |               key :required, true | ||
|  |               key :type, :string | ||
|  |             end | ||
|  |             parameter do | ||
|  |               key :name, :account_name | ||
|  |               key :in, :path | ||
|  |               key :description, 'Aws provider account name' | ||
|  |               key :required, true | ||
|  |               key :type, :string | ||
|  |             end | ||
|  |             response 200 do | ||
|  |               key :description, 'Provider networks response' | ||
|  |               schema do | ||
|  |                 key :type, :array | ||
|  |                 items do | ||
|  |                   key :'$ref', :ProviderNetworksResponse | ||
|  |                 end | ||
|  |               end | ||
|  |             end | ||
|  |             response :default do | ||
|  |               key :description, 'error' | ||
|  |               schema do | ||
|  |                 key :'$ref', :DevopsError | ||
|  |               end | ||
|  |             end | ||
|  |           end | ||
|  |         end | ||
|  | 
 | ||
|  |         swagger_schema :ProviderNetworksResponse do | ||
|  |           property :cidr do | ||
|  |             key :type, :string | ||
|  |           end | ||
|  |           property :vpcId do | ||
|  |             key :type, :string | ||
|  |           end | ||
|  |           property :subnetId do | ||
|  |             key :type, :string | ||
|  |           end | ||
|  |           property :name do | ||
|  |             key :type, :string | ||
|  |           end | ||
|  |           property :zone do | ||
|  |             key :type, :string | ||
|  |           end | ||
|  |         end | ||
|  | 
 | ||
|  |         swagger_path "/provider/{provider}/account/{account_name}/flavors" do | ||
|  |           operation :get do | ||
|  |             key :description, 'Get provider account flavors' | ||
|  |             key :operationId, 'getProviderFlavors' | ||
|  |             key :tags, [ | ||
|  |               'provider' | ||
|  |             ] | ||
|  |             parameter do | ||
|  |               key :name, :provider | ||
|  |               key :in, :path | ||
|  |               key :description, 'Provider name' | ||
|  |               key :required, true | ||
|  |               key :type, :string | ||
|  |             end | ||
|  |             parameter do | ||
|  |               key :name, :account_name | ||
|  |               key :in, :path | ||
|  |               key :description, 'Aws provider account name' | ||
|  |               key :required, true | ||
|  |               key :type, :string | ||
|  |             end | ||
|  |             response 200 do | ||
|  |               key :description, 'Provider flavors response' | ||
|  |               schema do | ||
|  |                 key :type, :array | ||
|  |                 items do | ||
|  |                   key :'$ref', :ProviderFlavorsResponse | ||
|  |                 end | ||
|  |               end | ||
|  |             end | ||
|  |             response :default do | ||
|  |               key :description, 'error' | ||
|  |               schema do | ||
|  |                 key :'$ref', :DevopsError | ||
|  |               end | ||
|  |             end | ||
|  |           end | ||
|  |         end | ||
|  | 
 | ||
|  |         swagger_schema :ProviderFlavorsResponse do | ||
|  |           property :id do | ||
|  |             key :type, :string | ||
|  |           end | ||
|  |           property :cores do | ||
|  |             key :type, :integer | ||
|  |           end | ||
|  |           property :disk do | ||
|  |             key :type, :integer | ||
|  |           end | ||
|  |           property :name do | ||
|  |             key :type, :string | ||
|  |           end | ||
|  |           property :ram do | ||
|  |             key :type, :integer | ||
|  |           end | ||
|  |         end | ||
|  | 
 | ||
|  |         swagger_path "/provider/{provider}/account/{account_name}/security_groups" do | ||
|  |           operation :get do | ||
|  |             key :description, 'Get provider account security_groups' | ||
|  |             key :operationId, 'getProviderSecurityGroups' | ||
|  |             key :tags, [ | ||
|  |               'provider' | ||
|  |             ] | ||
|  |             parameter do | ||
|  |               key :name, :provider | ||
|  |               key :in, :path | ||
|  |               key :description, 'Provider name' | ||
|  |               key :required, true | ||
|  |               key :type, :string | ||
|  |             end | ||
|  |             parameter do | ||
|  |               key :name, :account_name | ||
|  |               key :in, :path | ||
|  |               key :description, 'Aws provider account name' | ||
|  |               key :required, true | ||
|  |               key :type, :string | ||
|  |             end | ||
|  |             response 200 do | ||
|  |               key :description, 'Provider security groups response' | ||
|  |               schema do | ||
|  |                 key :'$ref', :ProviderSecurityGroupsResponse | ||
|  |               end | ||
|  |             end | ||
|  |             response :default do | ||
|  |               key :description, 'error' | ||
|  |               schema do | ||
|  |                 key :'$ref', :DevopsError | ||
|  |               end | ||
|  |             end | ||
|  |           end | ||
|  |         end | ||
|  | 
 | ||
|  |         swagger_schema :ProviderSecurityGroupsResponse do | ||
|  |           property :name_key do | ||
|  |             key :'$ref', :ProviderSecurityGroupsElem | ||
|  |           end | ||
|  |         end | ||
|  | 
 | ||
|  |         swagger_schema :ProviderSecurityGroupsElem do | ||
|  |           property :id do | ||
|  |             key :type, :string | ||
|  |           end | ||
|  |           property :description do | ||
|  |             key :type, :string | ||
|  |           end | ||
|  |           property :rules do | ||
|  |             key :type, :array | ||
|  |             items do | ||
|  |               key :'$ref', :ProviderSecurityGroupsRule | ||
|  |             end | ||
|  |           end | ||
|  |         end | ||
|  | 
 | ||
|  |         swagger_schema :ProviderSecurityGroupsRule do | ||
|  |           property :protocol do | ||
|  |             key :type, :string | ||
|  |           end | ||
|  |           property :from do | ||
|  |             key :type, :integer | ||
|  |           end | ||
|  |           property :to do | ||
|  |             key :type, :integer | ||
|  |           end | ||
|  |           property :cidr do | ||
|  |             key :type, :string | ||
|  |           end | ||
|  |         end | ||
|  | 
 | ||
|  |       end | ||
|  |     end | ||
|  |   end | ||
|  | end |