From c7192912fa1dbfa9c95606c714901d69fc637ca9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charles-Edouard=20Br=C3=A9t=C3=A9ch=C3=A9?= Date: Wed, 29 Mar 2023 15:33:02 +0200 Subject: [PATCH] refactor: add preconditions check to engine invokeHandler (#6721) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Charles-Edouard Brétéché --- pkg/engine/engine.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pkg/engine/engine.go b/pkg/engine/engine.go index ddb98a3684..90932a92c4 100644 --- a/pkg/engine/engine.go +++ b/pkg/engine/engine.go @@ -205,6 +205,14 @@ func (e *engine) invokeRuleHandler( // TODO: return error ? return resource, nil } + // check preconditions + preconditionsPassed, err := internal.CheckPreconditions(logger, policyContext, rule.GetAnyAllConditions()) + if err != nil { + return resource, handlers.RuleResponses(internal.RuleError(&rule, ruleType, "failed to evaluate preconditions", err)) + } + if !preconditionsPassed { + return resource, handlers.RuleResponses(internal.RuleSkip(&rule, ruleType, "preconditions not met")) + } // process handler return handler.Process(ctx, logger, policyContext, resource, rule) },