Skip to content

Commit

Permalink
support conditional python policy evaluation.
Browse files Browse the repository at this point in the history
Description: if a python policy implements should_evaluate_policy method, it can choose to have its evaluate a resource or ignore to be part of policy engine evaluation chain.
  • Loading branch information
neerajtickoo committed Aug 19, 2024
1 parent 74b33d5 commit 3e148ce
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions rpe/engines/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ def evaluate(self, resource):

for policy_name, policy_cls in matched_policies.items():
try:
if hasattr(policy_cls, "should_evaluate_policy"):
should_evaluate_policy_res = policy_cls.should_evaluate_policy(resource)
if not should_evaluate_policy_res:
print(f"Policy: {policy_name}, will not be evaluated for resource {resource} "
f"as should_evaluate_policy returned {should_evaluate_policy_res}")
continue

if hasattr(policy_cls, "evaluate"):
eval_result = policy_cls.evaluate(resource)
if not isinstance(eval_result, EvaluationResult):
Expand Down

0 comments on commit 3e148ce

Please sign in to comment.