Skip to content

Commit

Permalink
Hook rule validation into engine so defaults are set.
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Antonio Osorio <[email protected]>
  • Loading branch information
JAORMX committed Nov 13, 2024
1 parent c3d0b0c commit a4c37a1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
16 changes: 16 additions & 0 deletions pkg/engine/v1/rtengine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,22 @@ func (r *RuleTypeEngine) Eval(
}
}()

// The rule type has already been validated at creation time. However,
// re-validating it here is a good idea to ensure that the rule type
// has not been tampered with. Also, this sets the defaults for the
// rule definition.
if ruleDef != nil {
if err := r.ruleValidator.ValidateRuleDefAgainstSchema(ruleDef); err != nil {
return fmt.Errorf("rule definition validation failed: %w", err)
}
}

if ruleParams != nil {
if err := r.ruleValidator.ValidateParamsAgainstSchema(ruleParams); err != nil {
return fmt.Errorf("rule parameters validation failed: %w", err)
}
}

logger.Info().Msg("entity evaluation - ingest started")
// Try looking at the ingesting cache first
result, ok := r.ingestCache.Get(r.ingester, entity, ruleParams)
Expand Down
1 change: 0 additions & 1 deletion pkg/profiles/rule_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ func TestSetDefaultValuesOnValidation(t *testing.T) {
t.Parallel()

rtstr := `
---
version: v1
release_phase: alpha
Expand Down

0 comments on commit a4c37a1

Please sign in to comment.