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 UserRoutes
|
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 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"
|
|
|
|
|
# }
|
|
|
|
|
# ]
|
2015-07-30 15:37:43 +03:00
|
|
|
app.get_with_headers "/users", :headers => [:accept] do
|
2015-07-16 17:18:55 +03:00
|
|
|
check_privileges("user", "r")
|
2015-07-30 15:37:43 +03:00
|
|
|
json Devops::API2_0::Handler::User.new(request).users.map(&:to_hash)
|
2015-07-16 17:18:55 +03:00
|
|
|
end
|
2014-05-08 15:34:26 +04:00
|
|
|
|
2014-12-12 17:00:06 +03:00
|
|
|
# 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
|
2015-07-30 15:37:43 +03:00
|
|
|
app.post_with_headers "/user", :headers => [:accept, :content_type] do
|
2015-07-16 17:18:55 +03:00
|
|
|
check_privileges("user", "w")
|
2015-07-30 15:37:43 +03:00
|
|
|
Devops::API2_0::Handler::User.new(request).create
|
2015-07-16 17:18:55 +03:00
|
|
|
create_response("Created", nil, 201)
|
|
|
|
|
end
|
2014-12-12 17:00:06 +03:00
|
|
|
|
2015-02-19 11:27:56 +03:00
|
|
|
hash = {}
|
2014-12-12 17:00:06 +03:00
|
|
|
# Delete user
|
|
|
|
|
#
|
|
|
|
|
# * *Request*
|
|
|
|
|
# - method : DELETE
|
|
|
|
|
# - headers :
|
|
|
|
|
# - Accept: application/json
|
|
|
|
|
#
|
|
|
|
|
# * *Returns* :
|
|
|
|
|
# 200 - Deleted
|
2015-07-30 15:37:43 +03:00
|
|
|
hash["DELETE"] = lambda {|user|
|
2015-07-16 17:18:55 +03:00
|
|
|
check_privileges("user", "w")
|
2015-07-30 15:37:43 +03:00
|
|
|
Devops::API2_0::Handler::User.new(request).delete(user)
|
|
|
|
|
create_response("User '#{user}' removed")
|
2015-07-16 17:18:55 +03:00
|
|
|
}
|
2014-05-08 15:34:26 +04:00
|
|
|
|
2014-12-12 17:00:06 +03:00
|
|
|
# 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
|
2015-07-30 15:37:43 +03:00
|
|
|
hash["PUT"] = lambda {|user|
|
2015-07-16 17:18:55 +03:00
|
|
|
check_privileges("user", "w")
|
2015-07-30 15:37:43 +03:00
|
|
|
Devops::API2_0::Handler::User.new(request).change_user_privileges(user)
|
2015-07-16 17:18:55 +03:00
|
|
|
create_response("Updated")
|
|
|
|
|
}
|
2015-02-19 11:27:56 +03:00
|
|
|
app.multi_routes "/user/:user", {:headers => [:accept, :content_type]}, hash
|
2014-05-08 15:34:26 +04:00
|
|
|
|
2015-07-30 15:37:43 +03:00
|
|
|
# Change user email
|
2014-12-12 17:00:06 +03:00
|
|
|
#
|
|
|
|
|
# * *Request*
|
|
|
|
|
# - method : PUT
|
|
|
|
|
# - headers :
|
|
|
|
|
# - Accept: application/json
|
|
|
|
|
# - Content-Type: application/json
|
|
|
|
|
# - body :
|
|
|
|
|
# {
|
2015-07-30 15:37:43 +03:00
|
|
|
# "email": "new user email",
|
2014-12-12 17:00:06 +03:00
|
|
|
# }
|
|
|
|
|
#
|
|
|
|
|
# * *Returns* :
|
|
|
|
|
# 200 - Updated
|
2015-10-12 17:21:16 +03:00
|
|
|
app.put_with_headers %r{\A/user/(#{DevopsConfig::OBJECT_NAME})/email\z}, :headers => [:accept, :content_type] do |user|
|
2015-07-30 15:37:43 +03:00
|
|
|
check_privileges("user", "w") unless request.env['REMOTE_USER'] == user
|
|
|
|
|
Devops::API2_0::Handler::User.new(request).change_email(user)
|
|
|
|
|
create_response("Updated")
|
|
|
|
|
end
|
2015-07-16 17:18:55 +03:00
|
|
|
|
2015-07-30 15:37:43 +03:00
|
|
|
# Change user password
|
|
|
|
|
#
|
|
|
|
|
# * *Request*
|
|
|
|
|
# - method : PUT
|
|
|
|
|
# - headers :
|
|
|
|
|
# - Accept: application/json
|
|
|
|
|
# - Content-Type: application/json
|
|
|
|
|
# - body :
|
|
|
|
|
# {
|
|
|
|
|
# "password": "new user password",
|
|
|
|
|
# }
|
|
|
|
|
#
|
|
|
|
|
# * *Returns* :
|
|
|
|
|
# 200 - Updated
|
2015-10-12 17:21:16 +03:00
|
|
|
app.put_with_headers %r{\A/user/(#{DevopsConfig::OBJECT_NAME})/password\z}, :headers => [:accept, :content_type] do |user|
|
2015-07-30 15:37:43 +03:00
|
|
|
check_privileges("user", "w") unless request.env['REMOTE_USER'] == user
|
|
|
|
|
Devops::API2_0::Handler::User.new(request).change_password(user)
|
2015-07-16 17:18:55 +03:00
|
|
|
create_response("Updated")
|
|
|
|
|
end
|
2014-12-22 14:22:04 +03:00
|
|
|
|
|
|
|
|
puts "User routes initialized"
|
2014-12-12 17:00:06 +03:00
|
|
|
end
|
2014-05-08 15:34:26 +04:00
|
|
|
|
2014-12-12 17:00:06 +03:00
|
|
|
end
|
2014-05-08 15:34:26 +04:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|