From e3c7aae453cfea30ce30fdc7293c2dc2c44ce9fc Mon Sep 17 00:00:00 2001 From: Piotr Kazmierczak <470696+pkazmierczak@users.noreply.github.com> Date: Mon, 15 May 2023 19:21:35 +0200 Subject: [PATCH] refactor acl.UpsertTokens to avoid unnecessary RPC calls. --- nomad/acl_endpoint.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/nomad/acl_endpoint.go b/nomad/acl_endpoint.go index fa124a9c217..882d805f2ba 100644 --- a/nomad/acl_endpoint.go +++ b/nomad/acl_endpoint.go @@ -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 { @@ -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 } @@ -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 }