3
3
4
4
"""
5
5
import logging
6
- import json
7
6
8
7
from consulate .models import acl as model
9
8
from consulate .api import base
20
19
# RoleLinks = List[RoleLink]
21
20
22
21
23
- def __check_policylinks (policies ):
24
- """ Checks if policies is formatted correctly.
25
- :param list policies: A list of PolicyLink.
26
- :param rtype: bool
27
- :raises: consulate.exceptions.ACLFormatError
28
-
29
- """
30
- for policy in policies :
31
- if not ('ID' in policy or 'Name' in policy ):
32
- raise exceptions .ACLPolicyFormatError (str (policy ))
33
-
34
- return True
35
-
36
-
37
- def __check_service_identities (service_identities ):
38
- """ Checks if service_identities is formatted correctly.
39
- :param list service_identities: A ServiceIdentity list
40
- :param rtype: bool
41
- :raises: consulate.exceptions.ACLFormatError
42
-
43
- """
44
- for service_identity in service_identities :
45
- if 'ServiceName' not in service_identity :
46
- raise exceptions .ACLPolicyFormatError (str (service_identity ))
47
-
48
- return True
49
-
50
-
51
- def __create_json_format (structures , check ):
52
- """Creates a json string from a structures provided check passes.
53
- :param list structure: a PolicyLinks or ServiceIdentities.
54
- :param function check: a function to check structure
55
- :param rtype: str
56
-
57
- """
58
- formatted = None
59
- if structures is not None and check (structures ):
60
- formatted = json .dumps (structures )
61
-
62
- return formatted
63
-
64
-
65
22
class ACL (base .Endpoint ):
66
23
"""The ACL endpoints are used to create, update, destroy, and query ACL
67
24
tokens.
@@ -176,10 +133,6 @@ def create_role(self,
176
133
:param rtype: dict
177
134
178
135
"""
179
- policies = __create_json_format (policies , __check_policylinks )
180
- service_identities = __create_json_format (service_identities ,
181
- __check_service_identities )
182
-
183
136
return self ._put_response_body (
184
137
["role" ], {},
185
138
dict (
@@ -203,9 +156,6 @@ def update_role(self,
203
156
:param rtype: dict
204
157
205
158
"""
206
- policies = __create_json_format (policies , __check_policylinks )
207
- service_identities = __create_json_format (service_identities ,
208
- __check_service_identities )
209
159
return self ._put_response_body (
210
160
["role" , id ], {},
211
161
dict (
0 commit comments