Skip to content

Commit 2ebd6ce

Browse files
committed
add read and list token
1 parent a85c8cc commit 2ebd6ce

2 files changed

Lines changed: 58 additions & 9 deletions

File tree

consulate/api/acl.py

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,6 @@ class ACL(base.Endpoint):
2424
tokens.
2525
2626
"""
27-
def read_self_token(self):
28-
"""Retrieve the currently used token.
29-
:param rtype: dict
30-
31-
"""
32-
return self._get(["token", "self"])
33-
3427
def list_policies(self):
3528
"""List all ACL policies available in cluster.
3629
:param rtype: list
@@ -172,6 +165,28 @@ def delete_role(self, id):
172165
"""
173166
return self._delete(["policy", id])
174167

168+
def list_tokens(self):
169+
"""List all ACL tokens available in cluster.
170+
:param rtype: list
171+
172+
"""
173+
return self._get(["tokens"])
174+
175+
def read_token(self, accessor_id):
176+
"""Read an existing token with the given ID.
177+
:param str id: The ID of the role.
178+
:param rtype: dict
179+
180+
"""
181+
return self._get(["token", accessor_id])
182+
183+
def read_self_token(self):
184+
"""Retrieve the currently used token.
185+
:param rtype: dict
186+
187+
"""
188+
return self._get(["token", "self"])
189+
175190
def create_token(self,
176191
accessor_id=None,
177192
description=None,
@@ -198,7 +213,17 @@ def create_token(self,
198213
:param rtype: dict
199214
200215
"""
201-
pass
216+
return self._put_response_body(
217+
["token"], {},
218+
dict(
219+
model.ACLToken(accessor_id=accessor_id,
220+
description=description,
221+
expiration_time=expiration_time,
222+
expiration_ttl=expiration_ttl,
223+
local=local,
224+
policies=policies,
225+
roles=roles,
226+
service_identities=service_identities)))
202227

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

tests/acl_tests.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,35 @@ def test_list_roles_exception(self):
206206
def test_create_token(self):
207207
secret_id = self.uuidv4()
208208
accessor_id = self.uuidv4()
209-
result = self.consul.acl.create_create_token(
209+
result = self.consul.acl.create_token(
210210
accessor_id=accessor_id,
211211
secret_id=secret_id,
212212
roles=ROLELINKS_SAMPLE,
213213
policies=POLICYLINKS_SAMPLE,
214214
service_identities=SERVICE_IDENTITIES_SAMPLE)
215215
self.assertEqual(result['AccessorID'], accessor_id)
216216
self.assertEqual(result['SecretID'], secret_id)
217+
218+
def test_create_and_read_token(self):
219+
secret_id = self.uuidv4()
220+
accessor_id = self.uuidv4()
221+
value = self.consul.acl.create_token(
222+
accessor_id=accessor_id,
223+
secret_id=secret_id,
224+
roles=ROLELINKS_SAMPLE,
225+
policies=POLICYLINKS_SAMPLE,
226+
service_identities=SERVICE_IDENTITIES_SAMPLE)
227+
result = self.consul.acl.read_token(value["AccessorID"])
228+
self.assertEqual(result['AccessorID'], accessor_id)
229+
230+
def test_create_and_delete_token(self):
231+
secret_id = self.uuidv4()
232+
accessor_id = self.uuidv4()
233+
value = self.consul.acl.create_token(
234+
accessor_id=accessor_id,
235+
secret_id=secret_id,
236+
roles=ROLELINKS_SAMPLE,
237+
policies=POLICYLINKS_SAMPLE,
238+
service_identities=SERVICE_IDENTITIES_SAMPLE)
239+
result = self.consul.acl.delete_token(value["AccessorID"])
240+
self.assertTrue(result)

0 commit comments

Comments
 (0)