From 69b5c03c05c61cdc9de8e4d5f5467b183877649b Mon Sep 17 00:00:00 2001 From: Jakub Smolar Date: Mon, 11 Nov 2024 18:57:41 +0100 Subject: [PATCH] Update pattern-matching for AuthPolicy Signed-off-by: Jakub Smolar --- testsuite/kuadrant/policy/authorization/auth_policy.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/testsuite/kuadrant/policy/authorization/auth_policy.py b/testsuite/kuadrant/policy/authorization/auth_policy.py index 4e8444e5..2e9dfa5e 100644 --- a/testsuite/kuadrant/policy/authorization/auth_policy.py +++ b/testsuite/kuadrant/policy/authorization/auth_policy.py @@ -8,6 +8,7 @@ from testsuite.utils import asdict from .auth_config import AuthConfig from .. import Policy +from . import Pattern if TYPE_CHECKING: from . import Rule @@ -66,3 +67,10 @@ def overrides(self): """Add new rule into the `overrides` AuthPolicy section""" self.spec_section = self.model.spec.setdefault("overrides", {}) return self + + @modify + def add_patterns(self, patterns: dict[str, list[Pattern]]): + """Add named pattern-matching expressions to be referenced in other "when" rules.""" + self.model.spec.setdefault("patterns", {}) + for key, value in patterns.items(): + self.model.spec["patterns"].update({key: {"allOf": [asdict(x) for x in value]}})