MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / evaluateMatchingRule

Method evaluateMatchingRule

pkg/policies/engine/rego/rego.go:435–463  ·  view source on GitHub ↗

Evaluates a single rule and returns its boolean result

(ctx context.Context, ruleName string, parsedModule *ast.Module, decodedInput interface{})

Source from the content-addressed store, hash-verified

433
434// Evaluates a single rule and returns its boolean result
435func (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}

Callers 2

MatchesParametersMethod · 0.95
MatchesEvaluationMethod · 0.95

Calls 2

CapabilitiesMethod · 0.95
queryRegoFunction · 0.85

Tested by

no test coverage detected