Skip to content

Commit

Permalink
add policy create
Browse files Browse the repository at this point in the history
  • Loading branch information
cpaillet committed May 23, 2024
1 parent 783a7be commit bf297a7
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions consul/api/acl/policy.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import json

from consul.callback import CB


Expand Down Expand Up @@ -30,3 +32,29 @@ def read(self, uuid, token=None):
if token:
params.append(("token", token))
return self.agent.http.get(CB.json(), f"/v1/acl/policy/{uuid}", params=params)

def create(self, name, token=None, description=None, rules=None):
"""
Create a policy
This is a privileged endpoint, and requires a token with acl:write.
:param name: Specifies a name for the ACL policy.
:param token: token with acl:read capability
:param description: Free form human readable description of the policy.
:param rules: Specifies rules for the ACL policy.
:return: The cloned token information
"""
params = []
token = token or self.agent.token
if token:
params.append(("token", token))
json_data = {"name": name}
if rules:
json_data["rules"] = json.dumps(rules)
if description:
json_data["Description"] = description
return self.agent.http.put(
CB.json(),
"/v1/acl/policy",
params=params,
data=json.dumps(json_data),
)

0 comments on commit bf297a7

Please sign in to comment.