|
3 | 3 |
|
4 | 4 | """
|
5 | 5 | import logging
|
| 6 | +import json |
6 | 7 |
|
7 | 8 | from consulate.models import acl as model
|
8 | 9 | from consulate.api import base
|
|
11 | 12 | LOGGER = logging.getLogger(__name__)
|
12 | 13 |
|
13 | 14 |
|
| 15 | +def __check_policylinks(policies): |
| 16 | + """ Checks if policies is formatted correctly. |
| 17 | + :param list policies: A list of PolicyLink. |
| 18 | + :param rtype: bool |
| 19 | + :raises: consulate.exceptions.ACLFormatError |
| 20 | +
|
| 21 | + """ |
| 22 | + for policy in policies: |
| 23 | + if not ('ID' in policy or 'Name' in policy): |
| 24 | + raise exceptions.ACLPolicyFormatError(str(policy)) |
| 25 | + |
| 26 | + return True |
| 27 | + |
| 28 | + |
| 29 | +def __check_service_identities(service_identities): |
| 30 | + """ Checks if service_identities is formatted correctly. |
| 31 | + :param list service_identities: A ServiceIdentity list |
| 32 | + :param rtype: bool |
| 33 | + :raises: consulate.exceptions.ACLFormatError |
| 34 | +
|
| 35 | + """ |
| 36 | + for service_identity in service_identities: |
| 37 | + if 'ServiceName' not in service_identity: |
| 38 | + raise exceptions.ACLPolicyFormatError(str(service_identity)) |
| 39 | + |
| 40 | + return True |
| 41 | + |
| 42 | + |
| 43 | +def __create_json_format(structures, check): |
| 44 | + """Creates a json string from a structures provided check passes. |
| 45 | + :param list structure: a PolicyLinks or ServiceIdentities. |
| 46 | + :param function check: a function to check structure |
| 47 | + :param rtype: str |
| 48 | +
|
| 49 | + """ |
| 50 | + formatted = None |
| 51 | + if structures is not None and check(structures): |
| 52 | + formatted = json.dumps(structures) |
| 53 | + |
| 54 | + return formatted |
| 55 | + |
| 56 | + |
14 | 57 | class ACL(base.Endpoint):
|
15 | 58 | """The ACL endpoints are used to create, update, destroy, and query ACL
|
16 | 59 | tokens.
|
|
0 commit comments