Skip to content

Commit

Permalink
Combine conditionals
Browse files Browse the repository at this point in the history
  • Loading branch information
backspace committed Jul 29, 2019
1 parent dd704e5 commit 8389af6
Showing 1 changed file with 22 additions and 24 deletions.
46 changes: 22 additions & 24 deletions nomad/acl_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,34 +220,32 @@ func (a *ACL) GetPolicy(args *structs.ACLPolicySpecificRequest, reply *structs.S
}

// If the policy is the anonymous one, anyone can get it
if args.Name != "anonymous" {
// If it is not a management token determine if it can get this policy
mgt := acl.IsManagement()
if !mgt {
snap, err := a.srv.fsm.State().Snapshot()
if err != nil {
return err
}
// If it is not a management token determine if it can get this policy
mgt := acl.IsManagement()
if !mgt && args.Name != "anonymous" {
snap, err := a.srv.fsm.State().Snapshot()
if err != nil {
return err
}

token, err := snap.ACLTokenBySecretID(nil, args.AuthToken)
if err != nil {
return err
}
if token == nil {
return structs.ErrTokenNotFound
}
token, err := snap.ACLTokenBySecretID(nil, args.AuthToken)
if err != nil {
return err
}
if token == nil {
return structs.ErrTokenNotFound
}

found := false
for _, p := range token.Policies {
if p == args.Name {
found = true
break
}
found := false
for _, p := range token.Policies {
if p == args.Name {
found = true
break
}
}

if !found {
return structs.ErrPermissionDenied
}
if !found {
return structs.ErrPermissionDenied
}
}

Expand Down

0 comments on commit 8389af6

Please sign in to comment.