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 Permissions(AMApiBase):
21 Permission list operations
23 .. :quickref: Permissions;Permission list operations
25 .. http:get:: /am/v1/permissions
27 **Start Permission list**
33 GET am/v1/permissions HTTP/1.1
34 Host: haproxyvip:61200
35 Accept: application/json
49 "permission_name": "am/permissions",
52 "am/permissions/details":
54 "permission_name": "am/permissions/details",
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 permissions elements
63 :> json string permission_name: Permission name
64 :> json string resources: permissions resources
67 endpoints = ['permissions']
70 self.logger.info("Received a permission list request!")
71 permissions_lis=dict({})
72 state, permissions = self._permission_list()
75 for element in permissions:
77 value.update({"permission_name": element, "resources": permissions[element]})
78 permissions_lis.update({element: value})
79 self.logger.info("The permission list response done!")
80 return AMApiBase.embed_data(permissions_lis, 0, "")
82 return AMApiBase.construct_error_response(1, permissions)
84 def _permission_list(self):
85 state_open, message_open = self._open_db()
88 permissions = self.db.get_resources()
89 except Exception as ex:
90 self.logger.error("Internal error: {0}".format(ex))
91 return False, "{0}".format(ex)
93 state_close, message_close = self._close_db()
96 return True, permissions
98 return False, message_open