Evaluates a single rule and returns its boolean result
(ctx context.Context, ruleName string, parsedModule *ast.Module, decodedInput interface{})
| 433 | |
| 434 | // Evaluates a single rule and returns its boolean result |
| 435 | func (r *Engine) evaluateMatchingRule(ctx context.Context, ruleName string, parsedModule *ast.Module, decodedInput interface{}) (result bool, found bool, err error) { |
| 436 | // Add input |
| 437 | regoInput := rego.Input(decodedInput) |
| 438 | |
| 439 | // Add module |
| 440 | regoFunc := rego.ParsedModule(parsedModule) |
| 441 | options := []func(r *rego.Rego){regoInput, regoFunc, rego.Capabilities(r.Capabilities())} |
| 442 | |
| 443 | if r.operatingMode == EnvironmentModeRestrictive { |
| 444 | options = append(options, rego.StrictBuiltinErrors(true)) |
| 445 | } |
| 446 | |
| 447 | res, err := queryRego(ctx, ruleName, options...) |
| 448 | if err != nil { |
| 449 | return false, false, err |
| 450 | } |
| 451 | |
| 452 | // Parse the boolean result |
| 453 | for _, exp := range res { |
| 454 | for _, val := range exp.Expressions { |
| 455 | if boolResult, ok := val.Value.(bool); ok { |
| 456 | return boolResult, true, nil |
| 457 | } |
| 458 | } |
| 459 | } |
| 460 | |
| 461 | // Rule not found or returns non bool value |
| 462 | return false, false, nil |
| 463 | } |
no test coverage detected