From 24a1d8603822f6ce3206dda4addb5b820cc6bbc9 Mon Sep 17 00:00:00 2001 From: Janardhan Sharma Date: Fri, 19 Jul 2024 16:30:42 +0200 Subject: [PATCH] rebase Signed-off-by: Janardhan Sharma --- filters/openpolicyagent/evaluation.go | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/filters/openpolicyagent/evaluation.go b/filters/openpolicyagent/evaluation.go index 2effefb122..7d3b5a578b 100644 --- a/filters/openpolicyagent/evaluation.go +++ b/filters/openpolicyagent/evaluation.go @@ -23,7 +23,11 @@ func (opa *OpenPolicyAgentInstance) Eval(ctx context.Context, req *ext_authz_v3. return nil, err } - setDecisionIdInRequest(req, decisionId) + err = setDecisionIdInRequest(req, decisionId) + if err != nil { + opa.Logger().WithFields(map[string]interface{}{"err": err}).Error("Unable to set decision ID in Request.") + return nil, err + } result, stopeval, err := envoyauth.NewEvalResult(withDecisionID(decisionId)) if err != nil { @@ -68,21 +72,27 @@ func (opa *OpenPolicyAgentInstance) Eval(ctx context.Context, req *ext_authz_v3. return result, nil } -func setDecisionIdInRequest(req *ext_authz_v3.CheckRequest, decisionId string) { +func setDecisionIdInRequest(req *ext_authz_v3.CheckRequest, decisionId string) error { if req.Attributes.MetadataContext == nil { req.Attributes.MetadataContext = &ext_authz_v3_core.Metadata{ FilterMetadata: map[string]*pbstruct.Struct{}, } } - req.Attributes.MetadataContext.FilterMetadata["open_policy_agent"] = FormOpenPolicyAgentMetaDataObject(decisionId) + + filterMeta, err := formOpenPolicyAgentMetaDataObject(decisionId) + if err != nil { + return err + } + req.Attributes.MetadataContext.FilterMetadata["open_policy_agent"] = filterMeta + return nil } -func FormOpenPolicyAgentMetaDataObject(decisionId string) *pbstruct.Struct { +func formOpenPolicyAgentMetaDataObject(decisionId string) (*pbstruct.Struct, error) { + innerFields := make(map[string]interface{}) innerFields["decision_id"] = decisionId - openPolicyAgentMetaDataObject, _ := pbstruct.NewStruct(innerFields) - return openPolicyAgentMetaDataObject + return pbstruct.NewStruct(innerFields) } func (opa *OpenPolicyAgentInstance) logDecision(ctx context.Context, input interface{}, result *envoyauth.EvalResult, err error) error {