Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update AuthPolicy to use filters instead of dynamicMetadata #576

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion testsuite/kuadrant/policy/authorization/auth_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 7 additions & 0 deletions testsuite/kuadrant/policy/authorization/auth_policy.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
"""Module containing classes related to AuthPolicy"""

from functools import cached_property
from typing import Dict, TYPE_CHECKING

from testsuite.gateway import Referencable
from testsuite.kubernetes import modify
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

Expand Down Expand Up @@ -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"""
Expand Down
6 changes: 5 additions & 1 deletion testsuite/kuadrant/policy/authorization/sections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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})
Expand Down
Loading