-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce policy list/read capabilities (#70)
- ACL endpoint change, consul.acl is now consul.acl.token - add consul.acl.policy.list and acl.policy.read
- Loading branch information
Showing
4 changed files
with
119 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from consul.api.acl.policy import Policy | ||
from consul.api.acl.token import Token | ||
|
||
|
||
class ACL: | ||
def __init__(self, agent): | ||
self.agent = agent | ||
|
||
self.token = self.tokens = Token(agent) | ||
self.policy = self.policies = Policy(agent) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from consul.callback import CB | ||
|
||
|
||
class Policy: | ||
def __init__(self, agent): | ||
self.agent = agent | ||
|
||
def list(self, token=None): | ||
""" | ||
Lists all the active ACL policies. This is a privileged endpoint, and | ||
requires a management token. *token* will override this client's | ||
default token. | ||
Requires a token with acl:read capability. ACLPermissionDenied raised otherwise | ||
""" | ||
params = [] | ||
token = token or self.agent.token | ||
if token: | ||
params.append(("token", token)) | ||
return self.agent.http.get(CB.json(), "/v1/acl/policies", params=params) | ||
|
||
def read(self, uuid, token=None): | ||
""" | ||
Returns the policy information for *id*. Requires a token with acl:read capability. | ||
:param accessor_id: Specifies the UUID of the policy you lookup. | ||
:param token: token with acl:read capability | ||
:return: selected Polic information | ||
""" | ||
params = [] | ||
token = token or self.agent.token | ||
if token: | ||
params.append(("token", token)) | ||
return self.agent.http.get(CB.json(), f"/v1/acl/policy/{uuid}", params=params) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
from consul.callback import CB | ||
|
||
|
||
class ACL: | ||
class Token: | ||
def __init__(self, agent): | ||
self.agent = agent | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters