3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 from am_api_base import *
18 class RolesUsers(AMApiBase):
21 Role list users operations
23 .. :quickref: Roles users;Role list users operations
25 .. http:get:: /am/v1/roles/users
27 **Start Role list users**
33 GET am/v1/roles/permissions HTTP/1.1
34 Host: haproxyvip:61200
35 Accept: application/json
37 "role_name": "test_role"
40 :> json string role_name: The role name to be searched in users.
49 "description": "Resource added to role"
54 "role_name": "has_all",
55 "users": [user1, user2]
60 :> json int code: the status code
61 :> json string description: the error description, present if code is non zero
62 :> json object data: a dictionary with the role name and role owners
63 :> json string role_name: The role name.
64 :> json string users: The role owners.
67 endpoints = ['roles/users']
68 parser_arguments = ['role_name']
71 self.logger.info("Received a role users request!")
72 args = self.parse_args()
74 state, message = self._role_users(args)
77 result.update({"role_name": args["role_name"]})
78 result.update({"users": message})
79 self.logger.info("The role users response done!")
80 return AMApiBase.embed_data({args["role_name"]:result}, 0, "These users have this role")
82 self.logger.error("The {0} roles users list creation failed: {1}".format(args["role_name"], message))
83 return AMApiBase.embed_data({}, 1, message)
85 def _role_users(self, args):
86 state_open, message_open = self._open_db()
89 users=self.db.get_role_users(args["role_name"])
90 except Exception as ex:
91 self.logger.error("Internal error: {0}".format(ex))
92 return False, "Internal error: {0}".format(ex)
94 state_close, message_close = self._close_db()
99 return False, message_open