Skip to content

Commit

Permalink
Merge pull request #576 from jsmolar/swot
Browse files Browse the repository at this point in the history
Update AuthPolicy to use filters instead of dynamicMetadata
  • Loading branch information
Jakub Smolar authored Nov 12, 2024
2 parents 08ff7b1 + 10400f3 commit 60d0982
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
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

0 comments on commit 60d0982

Please sign in to comment.