From be4a07e8b92f339941966afaf1ecfe086b350324 Mon Sep 17 00:00:00 2001 From: Alejandro Baez Date: Tue, 17 Sep 2019 13:45:13 -0400 Subject: [PATCH] fix errors on role and validate --- consulate/api/acl.py | 16 ++++++++-------- consulate/models/acl.py | 12 ++++-------- tests/acl_tests.py | 8 ++++---- tests/base.py | 8 ++++---- 4 files changed, 20 insertions(+), 24 deletions(-) diff --git a/consulate/api/acl.py b/consulate/api/acl.py index 8d6c3df..c10317c 100644 --- a/consulate/api/acl.py +++ b/consulate/api/acl.py @@ -135,10 +135,10 @@ def create_role(self, return self._put_response_body( ["role"], {}, dict( - model.ACLPolicy(name=name, - description=description, - policies=policies, - service_identities=service_identities))) + model.ACLRole(name=name, + description=description, + policies=policies, + service_identities=service_identities))) def update_role(self, id, @@ -159,10 +159,10 @@ def update_role(self, return self._put_response_body( ["role", id], {}, dict( - model.ACLPolicy(name=name, - description=description, - policies=policies, - service_identities=service_identities))) + model.ACLRole(name=name, + description=description, + policies=policies, + service_identities=service_identities))) def delete_role(self, id): """Delete an existing role with the given ID. diff --git a/consulate/models/acl.py b/consulate/models/acl.py index 9b19b5e..3c334fe 100644 --- a/consulate/models/acl.py +++ b/consulate/models/acl.py @@ -8,26 +8,22 @@ def _validate_link_array(value, model): """ Validate the policies or roles links are formatted correctly. - :param list(dict()) value: An array of PolicyLink or RoleLink. - :param rtype: bool - :param consulate.models.agent.Check model: The model instance. + :param list value: An array of PolicyLink or RoleLink. :param rtype: bool """ - return all(['ID' in link or 'Name' in link - for link in value]) and not model.args + return all(['ID' in link or 'Name' in link for link in value]) def _validate_service_identities(value, model): """ Validate service_identities is formatted correctly. - :param list(dict()) value: A ServiceIdentity list + :param ServiceIdentities value: A ServiceIdentity list :param rtype: bool """ return all( - ['ServiceName' in service_identity - for service_identity in value]) and not model.args + ['ServiceName' in service_identity for service_identity in value]) class ACLPolicy(base.Model): diff --git a/tests/acl_tests.py b/tests/acl_tests.py index e61abc4..d3de5a8 100644 --- a/tests/acl_tests.py +++ b/tests/acl_tests.py @@ -37,17 +37,17 @@ """ POLICYLINKS_SAMPLE = [ - dict(ID="783beef3-783f-f41f-7422-7087dc272765"), + dict(Name="policylink_sample"), ] POLICYLINKS_UPDATE_SAMPLE = [ - dict(ID="783beef3-783f-f41f-7422-7087dc272765"), - dict(Name="some_policy_name") + dict(Name="policylink_sample"), + dict(Name="policylink_update_sample") ] SERVICE_IDENTITIES_SAMPLE = [dict(ServiceName="db", Datacenters=["dc1"])] -ROLELINKS_SAMPLE = [dict(Name="some_role_name")] +ROLELINKS_SAMPLE = [dict(Name="role_sample")] class TestCase(base.TestCase): diff --git a/tests/base.py b/tests/base.py index 0685d65..80f6075 100644 --- a/tests/base.py +++ b/tests/base.py @@ -52,11 +52,11 @@ def tearDown(self): for name in services: self.consul.agent.service.deregister(services[name]['ID']) - for acl in self.consul.acl.list(): - if acl['ID'] == CONSUL_CONFIG['acl']['tokens']['master']: + for acl in self.consul.acl.list_tokens(): + if acl['AccessorID'] == CONSUL_CONFIG['acl']['tokens']['master']: continue try: - uuid.UUID(acl['ID']) - self.consul.acl.destroy(acl['ID']) + uuid.UUID(acl['AccessorID']) + self.consul.acl.delete_token(acl['AccessorID']) except (ValueError, exceptions.ConsulateException): pass