MatchesParameters evaluates the matches_parameters rule in a rego policy. The function creates an input object with policy parameters and expected parameters.
(ctx context.Context, policy *engine.Policy, evaluationParams, expectedParams map[string]string)
| 362 | // MatchesParameters evaluates the matches_parameters rule in a rego policy. |
| 363 | // The function creates an input object with policy parameters and expected parameters. |
| 364 | func (r *Engine) MatchesParameters(ctx context.Context, policy *engine.Policy, evaluationParams, expectedParams map[string]string) (bool, error) { |
| 365 | policyString := string(policy.Source) |
| 366 | parsedModule, err := ast.ParseModule(policy.Name, policyString) |
| 367 | if err != nil { |
| 368 | return false, fmt.Errorf("failed to parse rego policy: %w", err) |
| 369 | } |
| 370 | |
| 371 | // Create input with policy and expected parameters |
| 372 | inputMap := make(map[string]interface{}) |
| 373 | if evaluationParams == nil { |
| 374 | inputMap[inputArgs] = map[string]string{} |
| 375 | } else { |
| 376 | inputMap[inputArgs] = evaluationParams |
| 377 | } |
| 378 | if expectedParams == nil { |
| 379 | inputMap[expectedArgs] = map[string]string{} |
| 380 | } else { |
| 381 | inputMap[expectedArgs] = expectedParams |
| 382 | } |
| 383 | decodedInput := r.injectProjectMetadata(inputMap) |
| 384 | |
| 385 | // Evaluate matches_parameters rule |
| 386 | matchesParameters, found, err := r.evaluateMatchingRule(ctx, getRuleName(parsedModule.Package.Path, matchesParametersRule), parsedModule, decodedInput) |
| 387 | if err != nil { |
| 388 | return false, err |
| 389 | } |
| 390 | if !found { |
| 391 | // Rule not found, defaults to false |
| 392 | return false, nil |
| 393 | } |
| 394 | |
| 395 | return matchesParameters, nil |
| 396 | } |
| 397 | |
| 398 | // MatchesEvaluation evaluates the matches_evaluation rule in a rego policy. |
| 399 | // Creates an input object with expected parameters and policy violations. |