Add ErrPermissionDenied, rename TokenNotFound

This commit is contained in:
Armon Dadgar
2017-08-20 20:18:18 -07:00
parent 79420d78cf
commit 0fcf618dfc
5 changed files with 8 additions and 9 deletions

View File

@@ -82,7 +82,7 @@ func (c *Client) ResolveToken(secretID string) (*acl.ACL, error) {
return nil, err
}
if token == nil {
return nil, structs.TokenNotFound
return nil, structs.ErrTokenNotFound
}
// Check if this is a management token

View File

@@ -159,6 +159,6 @@ func TestClient_ACL_ResolveToken(t *testing.T) {
// Test bad token
out4, err := c1.ResolveToken(structs.GenerateUUID())
assert.Equal(t, structs.TokenNotFound, err)
assert.Equal(t, structs.ErrTokenNotFound, err)
assert.Nil(t, out4)
}

View File

@@ -46,7 +46,7 @@ func resolveTokenFromSnapshotCache(snap *state.StateSnapshot, cache *lru.TwoQueu
return nil, err
}
if token == nil {
return nil, structs.TokenNotFound
return nil, structs.ErrTokenNotFound
}
}

View File

@@ -43,7 +43,7 @@ func TestResolveACLToken(t *testing.T) {
// Attempt resolution of unknown token. Should fail.
randID := structs.GenerateUUID()
aclObj, err = resolveTokenFromSnapshotCache(snap, cache, randID)
assert.Equal(t, structs.TokenNotFound, err)
assert.Equal(t, structs.ErrTokenNotFound, err)
assert.Nil(t, aclObj)
// Attempt resolution of management token. Should get singleton.

View File

@@ -34,8 +34,10 @@ import (
)
var (
ErrNoLeader = fmt.Errorf("No cluster leader")
ErrNoRegionPath = fmt.Errorf("No path to region")
ErrNoLeader = fmt.Errorf("No cluster leader")
ErrNoRegionPath = fmt.Errorf("No path to region")
ErrTokenNotFound = errors.New("ACL token not found")
ErrPermissionDenied = errors.New("Permission denied")
// validPolicyName is used to validate a policy name
validPolicyName = regexp.MustCompile("^[a-zA-Z0-9-]{1,128}$")
@@ -5440,9 +5442,6 @@ type ACLPolicyUpsertRequest struct {
WriteRequest
}
// TokenNotFound indicates the Token was not found
var TokenNotFound = errors.New("ACL token not found")
// ACLToken represents a client token which is used to Authenticate
type ACLToken struct {
AccessorID string // Public Accessor ID (UUID)