Skip to content

Commit

Permalink
refactor acl.UpsertTokens to avoid unnecessary RPC calls.
Browse files Browse the repository at this point in the history
  • Loading branch information
pkazmierczak committed May 15, 2023
1 parent e329a45 commit e3c7aae
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions nomad/acl_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,18 @@ func (a *ACL) UpsertTokens(args *structs.ACLTokenUpsertRequest, reply *structs.A
return err
}

return a.upsertTokens(args, reply, stateSnapshot)
}

// upsertTokens is a method that contains common token upsertion logic without
// the RPC authentication, metrics, etc. Used in other RPC calls that require to
// upsert tokens.
func (a *ACL) upsertTokens(
args *structs.ACLTokenUpsertRequest,
reply *structs.ACLTokenUpsertResponse,
stateSnapshot *state.StateSnapshot,
) error {

// Validate each token
for idx, token := range args.Tokens {

Expand Down Expand Up @@ -2776,7 +2788,7 @@ func (a *ACL) OIDCCompleteAuth(

var tokenUpsertReply structs.ACLTokenUpsertResponse

if err := a.srv.RPC(structs.ACLUpsertTokensRPCMethod, &tokenUpsertRequest, &tokenUpsertReply); err != nil {
if err := a.upsertTokens(&tokenUpsertRequest, &tokenUpsertReply, stateSnapshot); err != nil {
return err
}

Expand Down Expand Up @@ -2924,7 +2936,7 @@ func (a *ACL) Login(args *structs.ACLLoginRequest, reply *structs.ACLLoginRespon

var tokenUpsertReply structs.ACLTokenUpsertResponse

if err := a.srv.RPC(structs.ACLUpsertTokensRPCMethod, &tokenUpsertRequest, &tokenUpsertReply); err != nil {
if err := a.upsertTokens(&tokenUpsertRequest, &tokenUpsertReply, stateSnapshot); err != nil {
return err
}

Expand Down

0 comments on commit e3c7aae

Please sign in to comment.