109 lines
		
	
	
		
			3.2 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
			
		
		
	
	
			109 lines
		
	
	
		
			3.2 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
| module Devops
 | |
|   module Version2_0
 | |
|     module Routes
 | |
|       module UserRoutes
 | |
| 
 | |
|         def self.registered(app)
 | |
| 
 | |
|           # Get users list
 | |
|           #
 | |
|           # * *Request*
 | |
|           #   - method : GET
 | |
|           #   - headers :
 | |
|           #     - Accept: application/json
 | |
|           #
 | |
|           # * *Returns* :
 | |
|           #   [
 | |
|           #     {
 | |
|           #       "email": "test@test.test",
 | |
|           #       "privileges": {
 | |
|           #         "flavor": "r",
 | |
|           #         "group": "r",
 | |
|           #         "image": "r",
 | |
|           #         "project": "r",
 | |
|           #         "server": "r",
 | |
|           #         "key": "r",
 | |
|           #         "user": "",
 | |
|           #         "filter": "r",
 | |
|           #         "network": "r",
 | |
|           #         "provider": "r",
 | |
|           #         "script": "r",
 | |
|           #         "templates": "r"
 | |
|           #       },
 | |
|           #       "id": "test"
 | |
|           #     }
 | |
|           #   ]
 | |
|           app.get_with_headers "/users", :headers => [:accept], &Devops::Version2_0::Handler::User.get_users
 | |
| 
 | |
|           # Create user
 | |
|           #
 | |
|           # * *Request*
 | |
|           #   - method : POST
 | |
|           #   - headers :
 | |
|           #     - Accept: application/json
 | |
|           #     - Content-Type: application/json
 | |
|           #   - body :
 | |
|           #   {
 | |
|           #     "username": "user name",
 | |
|           #     "email": "user email",
 | |
|           #     "password": "user password"
 | |
|           #   }
 | |
|           #
 | |
|           # * *Returns* :
 | |
|           #   201 - Created
 | |
|           app.post_with_headers "/user", :headers => [:accept, :content_type], &Devops::Version2_0::Handler::User.create_user
 | |
| 
 | |
|           hash = {}
 | |
|           # Delete user
 | |
|           #
 | |
|           # * *Request*
 | |
|           #   - method : DELETE
 | |
|           #   - headers :
 | |
|           #     - Accept: application/json
 | |
|           #
 | |
|           # * *Returns* :
 | |
|           #   200 - Deleted
 | |
|           hash["DELETE"] = Devops::Version2_0::Handler::User.delete_user
 | |
| 
 | |
|           # Change user privileges
 | |
|           #
 | |
|           # * *Request*
 | |
|           #   - method : PUT
 | |
|           #   - headers :
 | |
|           #     - Accept: application/json
 | |
|           #     - Content-Type: application/json
 | |
|           #   - body :
 | |
|           #   {
 | |
|           #     "cmd": "command or all", -> if empty, set default privileges
 | |
|           #     "privileges": "priv" -> 'rwx' or ''
 | |
|           #   }
 | |
|           #
 | |
|           # * *Returns* :
 | |
|           #   200 - Updated
 | |
|           hash["PUT"] = Devops::Version2_0::Handler::User.change_user_privileges
 | |
|           app.multi_routes "/user/:user", {:headers => [:accept, :content_type]}, hash
 | |
| 
 | |
|           # Change user email/password
 | |
|           #
 | |
|           # * *Request*
 | |
|           #   - method : PUT
 | |
|           #   - headers :
 | |
|           #     - Accept: application/json
 | |
|           #     - Content-Type: application/json
 | |
|           #   - body :
 | |
|           #   {
 | |
|           #     "email/password": "new user email/password",
 | |
|           #   }
 | |
|           #
 | |
|           # * *Returns* :
 | |
|           #   200 - Updated
 | |
|           app.put_with_headers %r{\A/user/#{DevopsConfig::OBJECT_NAME}/(email|password)\z}, :headers => [:accept, :content_type], &Devops::Version2_0::Handler::User.change_user_email_or_password
 | |
| 
 | |
|           puts "User routes initialized"
 | |
|         end
 | |
| 
 | |
|       end
 | |
|     end
 | |
|   end
 | |
| end
 | 
