| 
									
										
										
										
											2014-05-08 15:34:26 +04:00
										 |  |  | require "json" | 
					
						
							|  |  |  | require "db/exceptions/invalid_record" | 
					
						
							|  |  |  | require "db/mongo/models/key" | 
					
						
							|  |  |  | require "fileutils" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-15 14:26:54 +03:00
										 |  |  | module Devops | 
					
						
							|  |  |  |   module Version2_0 | 
					
						
							| 
									
										
										
										
											2014-12-22 14:22:04 +03:00
										 |  |  |     module Routes | 
					
						
							| 
									
										
										
										
											2014-12-15 14:26:54 +03:00
										 |  |  |       module KeyRoutes | 
					
						
							| 
									
										
										
										
											2014-05-08 15:34:26 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-15 14:26:54 +03:00
										 |  |  |         def self.registered(app) | 
					
						
							|  |  |  |           # Get list of available ssh keys | 
					
						
							|  |  |  |           # | 
					
						
							|  |  |  |           # * *Request* | 
					
						
							|  |  |  |           #   - method : GET | 
					
						
							|  |  |  |           #   - headers : | 
					
						
							|  |  |  |           #     - Accept: application/json | 
					
						
							|  |  |  |           # | 
					
						
							|  |  |  |           # * *Returns* : array of strings | 
					
						
							|  |  |  |           #   [ | 
					
						
							|  |  |  |           #     { | 
					
						
							|  |  |  |           #       "scope": "system", -> 'system' - key was added by server, 'user' - key was added by user | 
					
						
							|  |  |  |           #       "id": "devops" | 
					
						
							|  |  |  |           #     } | 
					
						
							|  |  |  |           #   ] | 
					
						
							| 
									
										
										
										
											2015-02-19 11:27:56 +03:00
										 |  |  |           app.get_with_headers "/keys", :headers => [:accept], &Devops::Version2_0::Handler::Key.get_keys | 
					
						
							| 
									
										
										
										
											2014-05-08 15:34:26 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-15 14:26:54 +03:00
										 |  |  |           # Create ssh key on devops server | 
					
						
							|  |  |  |           # | 
					
						
							|  |  |  |           # * *Request* | 
					
						
							|  |  |  |           #   - method : POST | 
					
						
							|  |  |  |           #   - headers : | 
					
						
							|  |  |  |           #     - Accept: application/json | 
					
						
							|  |  |  |           #     - Content-Type: application/json | 
					
						
							|  |  |  |           #   - body : | 
					
						
							|  |  |  |           #     { | 
					
						
							|  |  |  |           #       "file_name": "key file name", | 
					
						
							|  |  |  |           #       "key_name": "key name", | 
					
						
							|  |  |  |           #       "content": "key content" | 
					
						
							|  |  |  |           #     } | 
					
						
							|  |  |  |           # | 
					
						
							|  |  |  |           # * *Returns* : | 
					
						
							|  |  |  |           #   201 - Created | 
					
						
							| 
									
										
										
										
											2015-02-19 11:27:56 +03:00
										 |  |  |           app.post_with_headers "/key", :headers => [:accept, :content_type], &Devops::Version2_0::Handler::Key.create_key | 
					
						
							| 
									
										
										
										
											2014-05-08 15:34:26 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-15 14:26:54 +03:00
										 |  |  |           # Delete ssh key from devops server | 
					
						
							|  |  |  |           # | 
					
						
							|  |  |  |           # * *Request* | 
					
						
							|  |  |  |           #   - method : DELETE | 
					
						
							|  |  |  |           #   - headers : | 
					
						
							|  |  |  |           #     - Accept: application/json | 
					
						
							|  |  |  |           # | 
					
						
							|  |  |  |           # * *Returns* : | 
					
						
							|  |  |  |           #   200 - Deleted | 
					
						
							| 
									
										
										
										
											2015-02-19 11:27:56 +03:00
										 |  |  |           app.delete_with_headers "/key/:key", :headers => [:accept], &Devops::Version2_0::Handler::Key.delete_key | 
					
						
							| 
									
										
										
										
											2014-12-15 14:26:54 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |           puts "Key routes initialized" | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2014-05-08 15:34:26 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |