From 02e97de7abfab8b2d515c50278ea8369f389fdfa Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Thu, 24 Aug 2017 17:15:47 -0700 Subject: [PATCH] api: support token listing --- api/acl.go | 21 +++++++++++++++++++++ api/acl_test.go | 19 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/api/acl.go b/api/acl.go index c28a12b10..9090ff941 100644 --- a/api/acl.go +++ b/api/acl.go @@ -82,6 +82,16 @@ func (a *ACLTokens) Bootstrap(q *WriteOptions) (*ACLToken, *WriteMeta, error) { return &resp, wm, nil } +// List is used to dump all of the tokens. +func (a *ACLTokens) List(q *QueryOptions) ([]*ACLTokenListStub, *QueryMeta, error) { + var resp []*ACLTokenListStub + qm, err := a.client.query("/v1/acl/tokens", &resp, q) + if err != nil { + return nil, nil, err + } + return resp, qm, nil +} + // ACLPolicyListStub is used to for listing ACL policies type ACLPolicyListStub struct { Name string @@ -111,3 +121,14 @@ type ACLToken struct { CreateIndex uint64 ModifyIndex uint64 } + +type ACLTokenListStub struct { + AccessorID string + Name string + Type string + Policies []string + Global bool + CreateTime time.Time + CreateIndex uint64 + ModifyIndex uint64 +} diff --git a/api/acl_test.go b/api/acl_test.go index 70748c938..ba4b72be1 100644 --- a/api/acl_test.go +++ b/api/acl_test.go @@ -108,3 +108,22 @@ func TestACLPolicies_Info(t *testing.T) { assertQueryMeta(t, qm) assert.Equal(t, policy.Name, out.Name) } + +func TestACLTokens_List(t *testing.T) { + t.Parallel() + c, s, _ := makeACLClient(t, nil, nil) + defer s.Stop() + at := c.ACLTokens() + + // Expect out bootstrap token + result, qm, err := at.List(nil) + if err != nil { + t.Fatalf("err: %s", err) + } + if qm.LastIndex == 0 { + t.Fatalf("bad index: %d", qm.LastIndex) + } + if n := len(result); n != 1 { + t.Fatalf("expected 1 token, got: %d", n) + } +}