Skip to content

Commit

Permalink
AuthPolicy upgrade to v2
Browse files Browse the repository at this point in the history
  • Loading branch information
azgabur committed Oct 25, 2023
1 parent dbff688 commit 88fed67
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 105 deletions.
42 changes: 6 additions & 36 deletions testsuite/objects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,14 @@ def __post_init__(self):
class Credentials:
"""Dataclass for Credentials structure"""

in_location: str
in_location: Literal["authorizationHeader", "customHeader", "queryString", "cookie"]
keySelector: str

def asdict(self):
"""Custom asdict, because I cannot use 'in' as a name"""
return {"in": self.in_location, "keySelector": self.keySelector}
"""Custom asdict because of needing to put location as parent dict key for inner dict"""
if self.in_location == "authorizationHeader":
return {self.in_location: {"prefix": self.keySelector}}
return {self.in_location: {"name": self.keySelector}}


@dataclass
Expand Down Expand Up @@ -116,39 +118,7 @@ class Value(ABCValue):
class ValueFrom(ABCValue):
"""Dataclass for dynamic Value. It contains reference path to existing value in AuthJson."""

authJSON: str

def asdict(self):
"""Override `asdict` function"""
return {"valueFrom": {"authJSON": self.authJSON}}


@dataclass
class Property:
"""Dataclass for static and dynamic values. Property is a Value with name."""

name: str
value: ABCValue

def asdict(self):
"""Override `asdict` function"""
return {"name": self.name, **asdict(self.value)}


@dataclass
class ExtendedProperty(Property):
"""
Dataclass extending Property class adding optional `overwrite` feature
used in extended_properties functionality in Identity section.
"""

overwrite: Optional[bool] = None

def asdict(self):
"""Extend inherited `asdict` function to include new attributes."""
if self.overwrite is not None:
return {**super().asdict(), "overwrite": self.overwrite}
return super().asdict()
selector: str


@dataclass
Expand Down
11 changes: 2 additions & 9 deletions testsuite/openshift/objects/auth_config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def authorization(self) -> AuthorizationSection:
@cached_property
def identity(self) -> IdentitySection:
"""Gives access to identity settings"""
return IdentitySection(self, "identity")
return IdentitySection(self, "authentication")

@cached_property
def metadata(self) -> MetadataSection:
Expand All @@ -48,7 +48,7 @@ def create_instance(
):
"""Creates base instance"""
model: Dict = {
"apiVersion": "authorino.kuadrant.io/v1beta1",
"apiVersion": "authorino.kuadrant.io/v1beta2",
"kind": "AuthConfig",
"metadata": {"name": name, "namespace": openshift.project, "labels": labels},
"spec": {"hosts": hostnames or [route.hostname]}, # type: ignore
Expand All @@ -71,13 +71,6 @@ def remove_all_hosts(self):
"""Remove all hosts"""
self.model.spec.hosts = []

@modify
def set_deny_with(self, code, value):
"""Set denyWith"""
self.auth_section["denyWith"] = {
"unauthenticated": {"code": code, "headers": [{"name": "Location", "valueFrom": {"authJSON": value}}]}
}

@modify
def add_rule(self, when: list[Rule]):
"""Add rule for the skip of entire AuthConfig"""
Expand Down
4 changes: 2 additions & 2 deletions testsuite/openshift/objects/auth_config/auth_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def route(self) -> HTTPRoute:

@property
def auth_section(self):
return self.model.spec.setdefault("authScheme", {})
return self.model.spec.setdefault("rules", {})

# pylint: disable=unused-argument
@classmethod
Expand All @@ -37,7 +37,7 @@ def create_instance( # type: ignore
):
"""Creates base instance"""
model: Dict = {
"apiVersion": "kuadrant.io/v1beta1",
"apiVersion": "kuadrant.io/v1beta2",
"kind": "AuthPolicy",
"metadata": {"name": name, "namespace": openshift.project, "labels": labels},
"spec": {
Expand Down
Loading

0 comments on commit 88fed67

Please sign in to comment.