8000 add update and read role · python-microservices/consulate@007c964 · GitHub
[go: up one dir, main page]

Skip to content
< 8000 /div>

Commit 007c964

Browse files
committed
add update and read role
1 parent 8132c23 commit 007c964

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

consulate/api/acl.py

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ def delete_policy(self, id):
138138
:param rtype: dict
139139
140140
"""
141-
142141
return self._delete(["policy", id])
143142

144143
def list_roles(self):
@@ -148,6 +147,20 @@ def list_roles(self):
148147
"""
149148
return self._get(["roles"])
150149

150+
def read_role(self, id=None, name=None):
151+
"""Read an existing role with the given ID or Name.
152+
:param str id: The ID of the role.
153+
:param str name: The name of the role.
154+
:param rtype: dict
155+
156+
"""
157+
if id is not None:
158+
return self._get(["role", id])
159+
elif name is not None:
160+
return self._get(["role", "name", name])
161+
else:
162+
raise exceptions.NotFound("Either id or name must be specified")
163+
151164
def create_role(self,
152165
name,
153166
description=None,
@@ -161,6 +174,10 @@ def create_role(self,
161174
:param rtype: dict
162175
163176
"""
177+
policies = __create_json_format(policies, __check_policylinks)
178+
service_identities = __create_json_format(service_identities,
179+
__check_service_identities)
180+
164181
return self._put_response_body(
165182
["role"], {},
166183
dict(
@@ -169,6 +186,32 @@ def create_role(self,
169186
policies=policies,
170187
service_identities=service_identities)))
171188

189+
def update_role(self,
190+
id,
191+
name,
192+
description=None,
193+
policies=None,
194+
service_identities=None):
195+
"""Update role with id given.
196+
:param str id: A UUID for the policy to update.
197+
:param str name: name of the policy
198+
:param list() datacenters: A list of datacenters to filter on policy.
199+
:param str description: Human readable description of the policy.
200+
:param str rules: A json serializable string for ACL rules.
201+
:param rtype: dict
202+
203+
"""
204+
policies = __create_json_format(policies, __check_policylinks)
205+
service_identities = __create_json_format(service_identities,
206+
__check_service_identities)
207+
return self._put_response_body(
208+
["role", id], {},
209+
dict(
210+
model.ACLPolicy(name=name,
211+
description=description,
212+
policies=policies,
213+
service_identities=service_identities)))
214+
172215
# NOTE: Everything below here is deprecated post consul-1.4.0.
173216

174217
def bootstrap(self):

0 commit comments

Comments
 (0)
0