@@ -371,7 +371,7 @@ func (ct *CheckinT) ProcessRequest(zlog zerolog.Logger, w http.ResponseWriter, r
371371 actions = append (actions , acs ... )
372372 break LOOP
373373 case policy := <- sub .Output ():
374- actionResp , err := processPolicy (ctx , zlog , ct .bulker , agent . Id , policy )
374+ actionResp , err := processPolicy (ctx , zlog , ct .bulker , agent , policy )
375375 if err != nil {
376376 span .End ()
377377 return fmt .Errorf ("processPolicy: %w" , err )
@@ -841,7 +841,7 @@ func convertActions(zlog zerolog.Logger, agentID string, actions []model.Action)
841841// A new policy exists for this agent. Perform the following:
842842// - Generate and update default ApiKey if roles have changed.
843843// - Rewrite the policy for delivery to the agent injecting the key material.
844- func processPolicy (ctx context.Context , zlog zerolog.Logger , bulker bulk.Bulk , agentID string , pp * policy.ParsedPolicy ) (* Action , error ) {
844+ func processPolicy (ctx context.Context , zlog zerolog.Logger , bulker bulk.Bulk , agent * model. Agent , pp * policy.ParsedPolicy ) (* Action , error ) {
845845 var links []apm.SpanLink = nil // set to a nil array to preserve default behaviour if no policy links are found
846846 if err := pp .Links .Trace .Validate (); err == nil {
847847 links = []apm.SpanLink {pp .Links }
@@ -854,23 +854,14 @@ func processPolicy(ctx context.Context, zlog zerolog.Logger, bulker bulk.Bulk, a
854854 Str (LogPolicyID , pp .Policy .PolicyID ).
855855 Logger ()
856856
857- // Repull and decode the agent object. Do not trust the cache.
858- bSpan , bCtx := apm .StartSpan (ctx , "findAgent" , "search" )
859- agent , err := dl .FindAgent (bCtx , bulker , dl .QueryAgentByID , dl .FieldID , agentID )
860- bSpan .End ()
861- if err != nil {
862- zlog .Error ().Err (err ).Msg ("fail find agent record" )
863- return nil , err
864- }
865-
866857 if len (pp .Policy .Data .Outputs ) == 0 {
867858 return nil , ErrNoPolicyOutput
868859 }
869860
870861 data := model .ClonePolicyData (pp .Policy .Data )
871862 for policyName , policyOutput := range data .Outputs {
872863 // NOTE: Not sure if output secret keys collected here include new entries, but they are collected for completeness
873- ks , err := policy .ProcessOutputSecret (ctx , policyOutput , bulker )
864+ ks , err := policy .ProcessOutputSecret (ctx , policyOutput , bulker ) // makes a bulk request to get secret values
874865 if err != nil {
875866 return nil , fmt .Errorf ("failed to process output secrets %q: %w" ,
876867 policyName , err )
@@ -879,8 +870,7 @@ func processPolicy(ctx context.Context, zlog zerolog.Logger, bulker bulk.Bulk, a
879870 }
880871 // Iterate through the policy outputs and prepare them
881872 for _ , policyOutput := range pp .Outputs {
882- err = policyOutput .Prepare (ctx , zlog , bulker , & agent , data .Outputs )
883- if err != nil {
873+ if err := policyOutput .Prepare (ctx , zlog , bulker , agent , data .Outputs ); err != nil {
884874 return nil , fmt .Errorf ("failed to prepare output %q: %w" ,
885875 policyOutput .Name , err )
886876 }
0 commit comments