Skip to content

Commit

Permalink
initial addition of role acl
Browse files Browse the repository at this point in the history
  • Loading branch information
abaez committed Sep 14, 2019
1 parent 04222a5 commit 7911a54
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
19 changes: 18 additions & 1 deletion consulate/api/acl.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def read_self_token(self):
return self._get(["token", "self"])

def list_policies(self):
""" List all policies available in cluster
""" List all ACL policies available in cluster
"""
return self._get(["policies"])

Expand Down Expand Up @@ -66,6 +66,23 @@ def delete_policy(self, id):

return self._delete(["policy", id])

def list_roles(self):
""" List all ACL roles available in cluster
"""
return self._get(["roles"])

def create_role(self, name, description=None, policies=None, service_identities=None):
""" Create an ACL role from a list of policies and or service service_identities.
:param str name: The name of the ACL role. Must be unique alphanumeral and dashes and underscores.
:param str description: The description of the ACL role.
:param PolicyLinks policies: An array of PolicyLink.
:param ServiceIdentities service_identities: An array of ServiceIdentity.
"""
return self._put_response_body(["role"], {}, dict(
model.ACLPolicy(name=name, description=description,
policies=policies, service_identities=service_identities)
))

# NOTE: Everything below here is deprecated post consul-1.4.0.

def bootstrap(self):
Expand Down
28 changes: 26 additions & 2 deletions consulate/models/acl.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@


class ACLPolicy(base.Model):
"""Defins the model used fur an ACL policy.
"""
"""Defines the model used fur an ACL policy."""
__slots__ = ['datacenters', 'description', 'id', 'name', 'rules']

__attributes__ = {
Expand Down Expand Up @@ -36,6 +35,31 @@ class ACLPolicy(base.Model):
}


class ACLRole(base.Model):
"""Defines the model used fur an ACL role."""
__slots__ = ['description', 'name', 'policies', 'service_identities']

__attributes__ = {
'description': {
'key': 'Description',
'type': str,
},
'name': {
'key': 'Name',
'type': str,
'required': True,
},
'policies': {
'key': 'Policies',
'type': list,
},
"service_identities": {
'key': 'ServiceIdentities',
'type': list,
}
}


class ACL(base.Model):
"""Defines the model used for an individual ACL token."""
__slots__ = ['id', 'name', 'type', 'rules']
Expand Down

0 comments on commit 7911a54

Please sign in to comment.