Skip to content

Commit

Permalink
rebase
Browse files Browse the repository at this point in the history
Signed-off-by: Janardhan Sharma <janardhan.sharma@zalando.de>
  • Loading branch information
Janardhan Sharma committed Jul 19, 2024
1 parent e9b9671 commit 24a1d86
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions filters/openpolicyagent/evaluation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 24a1d86

Please sign in to comment.