@@ -112,7 +112,7 @@ const (
112112 EnvironmentModePermissive EnvironmentMode = 1
113113 inputArgs = "args"
114114 expectedArgs = "expected_args"
115- evalResult = "evaluation_result "
115+ violationsResult = "violations "
116116 inputElements = "elements"
117117 deprecatedRule = "violations"
118118 mainRule = "result"
@@ -400,8 +400,16 @@ func (r *Engine) MatchesParameters(ctx context.Context, policy *engine.Policy, e
400400
401401 // Create input with policy and expected parameters
402402 inputMap := make (map [string ]interface {})
403- inputMap [inputArgs ] = evaluationParams
404- inputMap [expectedArgs ] = expectedParams
403+ if evaluationParams == nil {
404+ inputMap [inputArgs ] = map [string ]string {}
405+ } else {
406+ inputMap [inputArgs ] = evaluationParams
407+ }
408+ if expectedParams == nil {
409+ inputMap [expectedArgs ] = map [string ]string {}
410+ } else {
411+ inputMap [expectedArgs ] = expectedParams
412+ }
405413
406414 // Evaluate matches_parameters rule
407415 matchesParameters , err := r .evaluateMatchingRule (ctx , getRuleName (parsedModule .Package .Path , matchesParametersRule ), parsedModule , inputMap )
@@ -414,20 +422,27 @@ func (r *Engine) MatchesParameters(ctx context.Context, policy *engine.Policy, e
414422}
415423
416424// MatchesEvaluation evaluates the matches_evaluation rule in a rego policy.
417- // The function creates an input object with policy parameters and evaluation result .
425+ // The function creates an input object with expected parameters and policy violations .
418426// Returns true if the policy's matches_evaluation rule evaluates to true, false otherwise.
419- // If the rule is not found or evaluation fails, it defaults to false.
420- func (r * Engine ) MatchesEvaluation (ctx context.Context , policy * engine.Policy , ev * engine.EvaluationResult , evaluationParams map [string ]string ) (bool , error ) {
427+ func (r * Engine ) MatchesEvaluation (ctx context.Context , policy * engine.Policy , violations []string , expectedParams map [string ]string ) (bool , error ) {
421428 policyString := string (policy .Source )
422429 parsedModule , err := ast .ParseModule (policy .Name , policyString )
423430 if err != nil {
424431 return false , fmt .Errorf ("failed to parse rego policy: %w" , err )
425432 }
426433
427- // Create input with the policy evaluation data
434+ // Create input expected parameters and policy violations
428435 inputMap := make (map [string ]interface {})
429- inputMap [inputArgs ] = evaluationParams
430- inputMap [evalResult ] = ev
436+ if expectedParams == nil {
437+ inputMap [expectedArgs ] = map [string ]string {}
438+ } else {
439+ inputMap [expectedArgs ] = expectedParams
440+ }
441+ if violations == nil {
442+ inputMap [violationsResult ] = []string {}
443+ } else {
444+ inputMap [violationsResult ] = violations
445+ }
431446
432447 // Evaluate matches_parameters rule
433448 matchesEvaluation , err := r .evaluateMatchingRule (ctx , getRuleName (parsedModule .Package .Path , matchesEvaluationRule ), parsedModule , inputMap )
0 commit comments