| 
									
										
										
										
											2014-05-08 15:34:26 +04:00
										 |  |  | # encoding: UTF-8 | 
					
						
							| 
									
										
										
										
											2014-12-12 17:00:06 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-08 15:34:26 +04:00
										 |  |  | require "providers/provider_factory" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-15 14:26:54 +03:00
										 |  |  | module Devops | 
					
						
							| 
									
										
										
										
											2015-07-16 17:18:55 +03:00
										 |  |  |   module API2_0 | 
					
						
							| 
									
										
										
										
											2014-12-22 14:22:04 +03:00
										 |  |  |     module Routes | 
					
						
							| 
									
										
										
										
											2014-12-12 17:00:06 +03:00
										 |  |  |       module ProviderRoutes | 
					
						
							| 
									
										
										
										
											2014-05-08 15:34:26 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-12 17:00:06 +03:00
										 |  |  |         def self.registered(app) | 
					
						
							| 
									
										
										
										
											2014-05-08 15:34:26 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-12 17:00:06 +03:00
										 |  |  |           # Get devops providers | 
					
						
							|  |  |  |           # | 
					
						
							|  |  |  |           # * *Request* | 
					
						
							|  |  |  |           #   - method : GET | 
					
						
							|  |  |  |           #   - headers : | 
					
						
							|  |  |  |           #     - Accept: application/json | 
					
						
							|  |  |  |           # | 
					
						
							|  |  |  |           # * *Returns* : | 
					
						
							|  |  |  |           #   [ | 
					
						
							|  |  |  |           #     "ec2", | 
					
						
							|  |  |  |           #     "openstack" | 
					
						
							|  |  |  |           #   ] | 
					
						
							| 
									
										
										
										
											2015-07-16 17:18:55 +03:00
										 |  |  |           app.get_with_headers "/providers", :headers => [:accept] do#, &Devops::Version2_0::Handler::Provider.get_providers | 
					
						
							|  |  |  |             check_privileges("provider", "r") | 
					
						
							| 
									
										
										
										
											2015-07-30 15:37:43 +03:00
										 |  |  |             json Devops::API2_0::Handler::Provider.new(request).providers | 
					
						
							| 
									
										
										
										
											2015-07-16 17:18:55 +03:00
										 |  |  |           end | 
					
						
							| 
									
										
										
										
											2014-12-15 14:26:54 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-02 11:42:20 +03:00
										 |  |  |           # Get list of provider account fields | 
					
						
							|  |  |  |           # | 
					
						
							|  |  |  |           # * *Request* | 
					
						
							|  |  |  |           #   - method : GET | 
					
						
							|  |  |  |           #   - headers : | 
					
						
							|  |  |  |           #     - Accept: application/json | 
					
						
							|  |  |  |           # | 
					
						
							|  |  |  |           # * *Returns* : hash | 
					
						
							|  |  |  |           #   key - field | 
					
						
							|  |  |  |           #   value - description | 
					
						
							|  |  |  |           app.get_with_headers "/provider/:provider/account/fields", :headers => [:accept] do |provider| | 
					
						
							|  |  |  |             check_privileges("provider", "r") | 
					
						
							|  |  |  |             check_provider(provider) | 
					
						
							|  |  |  |             json Devops::API2_0::Handler::Provider.new(request).account_fields(provider) | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-22 12:39:22 +03:00
										 |  |  |           # 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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-26 12:04:01 +03:00
										 |  |  |           # 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| | 
					
						
							| 
									
										
										
										
											2015-10-22 12:39:22 +03:00
										 |  |  |             check_privileges("provider", "w") | 
					
						
							|  |  |  |             check_provider(provider) | 
					
						
							| 
									
										
										
										
											2015-10-28 17:27:02 +03:00
										 |  |  |             create_response("Created", {:account => Devops::API2_0::Handler::Provider.new(request).add_account(provider)}, 201) | 
					
						
							| 
									
										
										
										
											2015-10-26 12:04:01 +03:00
										 |  |  |           end | 
					
						
							| 
									
										
										
										
											2015-10-22 12:39:22 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-26 12:04:01 +03:00
										 |  |  |           # Delete account with name :account_name for :provider | 
					
						
							| 
									
										
										
										
											2015-10-22 12:39:22 +03:00
										 |  |  |           # | 
					
						
							|  |  |  |           # * *Request* | 
					
						
							|  |  |  |           #   - method : DELETE | 
					
						
							|  |  |  |           #   - headers : | 
					
						
							|  |  |  |           #     - Accept: application/json | 
					
						
							|  |  |  |           #     - Content-Type: application/json | 
					
						
							|  |  |  |           # | 
					
						
							| 
									
										
										
										
											2015-10-26 12:04:01 +03:00
										 |  |  |           # * *Returns* : 200 | 
					
						
							|  |  |  |           app.delete_with_headers "/provider/:provider/account/:account_name", :headers => [:accept, :content_type] do |provider, account_name| | 
					
						
							| 
									
										
										
										
											2015-10-22 12:39:22 +03:00
										 |  |  |             check_privileges("provider", "w") | 
					
						
							|  |  |  |             check_provider(provider) | 
					
						
							| 
									
										
										
										
											2015-10-26 12:04:01 +03:00
										 |  |  |             create_response("Deleted", {:account => Devops::API2_0::Handler::Provider.new(request).delete_account(provider)}) | 
					
						
							|  |  |  |           end | 
					
						
							| 
									
										
										
										
											2015-10-22 12:39:22 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-15 14:26:54 +03:00
										 |  |  |           puts "Provider routes initialized" | 
					
						
							| 
									
										
										
										
											2014-12-12 17:00:06 +03:00
										 |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2014-05-08 15:34:26 +04:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |