Skip to content

Commit

Permalink
fix errors on role and validate
Browse files Browse the repository at this point in the history
  • Loading branch information
abaez committed Sep 17, 2019
1 parent 2f6e3ff commit be4a07e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 24 deletions.
16 changes: 8 additions & 8 deletions consulate/api/acl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.
Expand Down
12 changes: 4 additions & 8 deletions consulate/models/acl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 4 additions & 4 deletions tests/acl_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 4 additions & 4 deletions tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit be4a07e

Please sign in to comment.