mirror of
https://github.com/kemko/nomad.git
synced 2026-01-04 09:25:46 +03:00
api: support token listing
This commit is contained in:
21
api/acl.go
21
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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user