From 10400f32011dddaa2e4c89dd4d2ccb93ae675a4f Mon Sep 17 00:00:00 2001 From: Jakub Smolar Date: Mon, 11 Nov 2024 13:30:13 +0100 Subject: [PATCH] Update AuthPolicy to use filters instead of dynamicMetadata Signed-off-by: Jakub Smolar --- testsuite/kuadrant/policy/authorization/auth_config.py | 2 +- testsuite/kuadrant/policy/authorization/auth_policy.py | 7 +++++++ testsuite/kuadrant/policy/authorization/sections.py | 6 +++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/testsuite/kuadrant/policy/authorization/auth_config.py b/testsuite/kuadrant/policy/authorization/auth_config.py index 528fe1f0..28ed20ae 100644 --- a/testsuite/kuadrant/policy/authorization/auth_config.py +++ b/testsuite/kuadrant/policy/authorization/auth_config.py @@ -36,7 +36,7 @@ def metadata(self) -> MetadataSection: @cached_property def responses(self) -> ResponseSection: """Gives access to response settings""" - return ResponseSection(self, "response") + return ResponseSection(self, "response", "dynamicMetadata") @classmethod def create_instance( diff --git a/testsuite/kuadrant/policy/authorization/auth_policy.py b/testsuite/kuadrant/policy/authorization/auth_policy.py index 2e9dfa5e..40b34ce2 100644 --- a/testsuite/kuadrant/policy/authorization/auth_policy.py +++ b/testsuite/kuadrant/policy/authorization/auth_policy.py @@ -1,5 +1,6 @@ """Module containing classes related to AuthPolicy""" +from functools import cached_property from typing import Dict, TYPE_CHECKING from testsuite.gateway import Referencable @@ -7,6 +8,7 @@ from testsuite.kubernetes.client import KubernetesClient from testsuite.utils import asdict from .auth_config import AuthConfig +from .sections import ResponseSection from .. import Policy from . import Pattern @@ -56,6 +58,11 @@ def auth_section(self): self.spec_section = None return spec_section.setdefault("rules", {}) + @cached_property + def responses(self) -> ResponseSection: + """Gives access to response settings""" + return ResponseSection(self, "response", "filters") + @property def defaults(self): """Add new rule into the `defaults` AuthPolicy section""" diff --git a/testsuite/kuadrant/policy/authorization/sections.py b/testsuite/kuadrant/policy/authorization/sections.py index b35cb145..57d9b577 100644 --- a/testsuite/kuadrant/policy/authorization/sections.py +++ b/testsuite/kuadrant/policy/authorization/sections.py @@ -208,6 +208,10 @@ class ResponseSection(Section): SUCCESS_RESPONSE = Union[JsonResponse, PlainResponse, WristbandResponse] + def __init__(self, obj: "AuthConfig", section_name, data_key: Literal["filters", "dynamicMetadata"]): + super().__init__(obj, section_name) + self.data_key = data_key + def add_simple(self, auth_json: str, name="simple", key="data", **common_features): """ Add simple response to AuthConfig, used for configuring response for debugging purposes, @@ -232,7 +236,7 @@ def add_success_dynamic(self, name: str, value: SUCCESS_RESPONSE, **common_featu This section is for items wrapped as Envoy Dynamic Metadata. """ - success_dynamic_metadata = self.section.setdefault("success", {}).setdefault("filters", {}) + success_dynamic_metadata = self.section.setdefault("success", {}).setdefault(self.data_key, {}) asdict_value = asdict(value) add_common_features(asdict_value, **common_features) success_dynamic_metadata.update({name: asdict_value})