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 RolesDetails(AMApiBase):
21 Role details operations
23 .. :quickref: Roles details;Role details operations
25 .. http:get:: /am/v1/roles/details
27 **Start Role details**
33 GET am/v1/roles/details HTTP/1.1
34 Host: haproxyvip:61200
35 Accept: application/json
37 "role_name": "test_role"
40 :> json string role_name: The showed role name.
49 "description": "Role details."
54 "permission_name": "has",
55 "resources": ["GET", "POST"]
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's details
63 :> json string permission_name: The permission's name.
64 :> json string resources: The permission resource's.
67 endpoints = ['roles/details']
68 parser_arguments = ['role_name']
71 self.logger.info("Received a role show request!")
73 args = self.parse_args()
75 state, details = self._role_show(args)
79 role_details.update({"None":{"permission_name": "No permissions","resources": "None"}})
82 role_details.update({perm: {"permission_name": perm,"resources": details[perm]}})
83 self.logger.info("The {0} role show response done!".format(args["role_name"]))
84 return AMApiBase.embed_data(role_details, 0)
86 self.logger.error("The {0} role show failed: {1}".format(args["role_name"], details))
87 return AMApiBase.construct_error_response(1, details)
89 def _role_show(self,args):
90 state_open, message_open = self._open_db()
93 details = self.db.get_role_resources(args["role_name"])
94 roles = self.db.get_role_table()
96 if role["name"] == args["role_name"]:
98 except Exception as ex:
99 self.logger.error("Internal error: {0}".format(ex))
100 return False, "Internal error: {0}".format(ex)
105 return False, message_open