Skip to content

Commit

Permalink
Merge pull request #211 from pehala/remove_authorization
Browse files Browse the repository at this point in the history
Remove Authorization interface
  • Loading branch information
pehala authored Aug 2, 2023
2 parents 849cdcd + cda46e6 commit cdf4ee4
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 162 deletions.
47 changes: 0 additions & 47 deletions testsuite/objects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
import abc
from dataclasses import dataclass, is_dataclass, fields
from copy import deepcopy
from functools import cached_property
from typing import Literal, Union

from testsuite.objects.sections import Metadata, Identities, Authorizations, Responses

JSONValues = Union[None, str, int, bool, list["JSONValues"], dict[str, "JSONValues"]]


Expand Down Expand Up @@ -147,50 +144,6 @@ def oidc_url(self):
"""Authorino oidc url"""


class Authorization(LifecycleObject):
"""Object containing Authorization rules and configuration for either Authorino or Kuadrant"""

@cached_property
@abc.abstractmethod
def authorization(self) -> Authorizations:
"""Gives access to authorization settings"""

@cached_property
@abc.abstractmethod
def identity(self) -> Identities:
"""Gives access to identity settings"""

@cached_property
@abc.abstractmethod
def metadata(self) -> Metadata:
"""Gives access to metadata settings"""

@cached_property
@abc.abstractmethod
def responses(self) -> Responses:
"""Gives access to response settings"""

@abc.abstractmethod
def add_host(self, hostname):
"""Adds host"""

@abc.abstractmethod
def remove_host(self, hostname):
"""Remove host"""

@abc.abstractmethod
def remove_all_hosts(self):
"""Remove all hosts"""

@abc.abstractmethod
def set_deny_with(self, code, value):
"""Set denyWith"""

@abc.abstractmethod
def add_rule(self, when: list[Rule]):
"""Add rule for the skip of entire AuthConfig"""


class PreexistingAuthorino(Authorino):
"""Authorino which is already deployed prior to the testrun"""

Expand Down
91 changes: 0 additions & 91 deletions testsuite/objects/sections.py

This file was deleted.

14 changes: 7 additions & 7 deletions testsuite/openshift/objects/auth_config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
from functools import cached_property
from typing import Dict, List

from testsuite.objects import Authorization, Responses, Metadata, Identities, Authorizations, Rule
from testsuite.objects import Rule
from testsuite.openshift.client import OpenShiftClient
from testsuite.openshift.objects import OpenShiftObject, modify
from .sections import AuthorizationsSection, IdentitySection, MetadataSection, ResponsesSection
from .sections import Identities, Metadata, Responses, Authorizations
from ..route import Route


class AuthConfig(OpenShiftObject, Authorization):
class AuthConfig(OpenShiftObject):
"""Represents AuthConfig CR from Authorino"""

@property
Expand All @@ -20,22 +20,22 @@ def auth_section(self):
@cached_property
def authorization(self) -> Authorizations:
"""Gives access to authorization settings"""
return AuthorizationsSection(self, "authorization")
return Authorizations(self, "authorization")

@cached_property
def identity(self) -> Identities:
"""Gives access to identity settings"""
return IdentitySection(self, "identity")
return Identities(self, "identity")

@cached_property
def metadata(self) -> Metadata:
"""Gives access to metadata settings"""
return MetadataSection(self, "metadata")
return Metadata(self, "metadata")

@cached_property
def responses(self) -> Responses:
"""Gives access to response settings"""
return ResponsesSection(self, "response")
return Responses(self, "response")

@classmethod
def create_instance(
Expand Down
21 changes: 12 additions & 9 deletions testsuite/openshift/objects/auth_config/sections.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@

from testsuite.objects import (
asdict,
Identities,
Metadata,
Responses,
MatchExpression,
Authorizations,
Rule,
Cache,
ABCValue,
Expand Down Expand Up @@ -60,7 +56,7 @@ def add_item(
self.section.append(item)


class IdentitySection(Section, Identities):
class Identities(Section):
"""Section which contains identity configuration"""

@modify
Expand Down Expand Up @@ -147,7 +143,7 @@ def remove_all(self):
self.section.clear()


class MetadataSection(Section, Metadata):
class Metadata(Section):
"""Section which contains metadata configuration"""

@modify
Expand Down Expand Up @@ -176,19 +172,26 @@ def uma_metadata(self, name, endpoint, credentials, **common_features):
self.add_item(name, {"uma": {"endpoint": endpoint, "credentialsRef": {"name": credentials}}}, **common_features)


class ResponsesSection(Section, Responses):
class Responses(Section):
"""Section which contains response configuration"""

def add_simple(self, auth_json, name="simple", key="data", **common_features):
self.add({"name": name, "json": {"properties": [{"name": key, "valueFrom": {"authJSON": auth_json}}]}})
"""Adds simple response to AuthConfig"""
self.add(
{
"name": name,
"json": {"properties": [{"name": key, "valueFrom": {"authJSON": auth_json}}]},
**common_features,
}
)

@modify
def add(self, response, **common_features):
"""Adds response section to AuthConfig."""
self.add_item(response.pop("name"), response, **common_features)


class AuthorizationsSection(Section, Authorizations):
class Authorizations(Section):
"""Section which contains authorization configuration"""

@modify
Expand Down
4 changes: 2 additions & 2 deletions testsuite/tests/kuadrant/authorino/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from weakget import weakget

from testsuite.httpx.auth import HttpxOidcClientAuth
from testsuite.objects import Authorino, Authorization, PreexistingAuthorino
from testsuite.objects import Authorino, PreexistingAuthorino
from testsuite.openshift.client import OpenShiftClient
from testsuite.openshift.objects.api_key import APIKey
from testsuite.openshift.objects.auth_config import AuthConfig
Expand Down Expand Up @@ -48,7 +48,7 @@ def authorino(authorino, openshift, blame, request, testconfig, module_label, au
@pytest.fixture(scope="module")
def authorization(
authorization, oidc_provider, authorino, envoy, authorization_name, openshift, module_label
) -> Authorization:
) -> AuthConfig:
"""In case of Authorino, AuthConfig used for authorization"""
if authorization is None:
authorization = AuthConfig.create_instance(
Expand Down
4 changes: 2 additions & 2 deletions testsuite/tests/kuadrant/authorino/operator/http/conftest.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
"""Conftest for all tests requiring custom deployment of Authorino"""
import pytest

from testsuite.objects import Authorization
from testsuite.httpx import HttpxBackoffClient
from testsuite.openshift.objects.auth_config import AuthConfig


# pylint: disable=unused-argument
@pytest.fixture(scope="module")
def authorization(authorization, wildcard_domain, openshift, module_label) -> Authorization:
def authorization(authorization, wildcard_domain, openshift, module_label) -> AuthConfig:
"""In case of Authorino, AuthConfig used for authorization"""
authorization.remove_all_hosts()
authorization.add_host(wildcard_domain)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
import openshift as oc
from openshift import OpenShiftPythonException

from testsuite.objects import Authorization, Rule, ValueFrom
from testsuite.objects import Rule, ValueFrom
from testsuite.certificates import CertInfo
from testsuite.openshift.objects.auth_config import AuthConfig
from testsuite.utils import cert_builder
from testsuite.openshift.objects.ingress import Ingress

Expand Down Expand Up @@ -65,7 +66,7 @@ def authorino_parameters(authorino_parameters, specific_authorino_name):

# pylint: disable=unused-argument
@pytest.fixture(scope="module")
def authorization(authorization, openshift, module_label, authorino_domain) -> Authorization:
def authorization(authorization, openshift, module_label, authorino_domain) -> AuthConfig:
"""In case of Authorino, AuthConfig used for authorization"""

# Authorino should have specific url so it is accessible by k8s webhook
Expand Down
3 changes: 1 addition & 2 deletions testsuite/tests/kuadrant/authorino/wristband/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from testsuite.openshift.objects.auth_config import AuthConfig
from testsuite.openshift.envoy import Envoy
from testsuite.certificates import CertInfo
from testsuite.objects import Authorization
from testsuite.utils import cert_builder


Expand Down Expand Up @@ -61,7 +60,7 @@ def wristband_endpoint(openshift, authorino, authorization_name):


@pytest.fixture(scope="module")
def authorization(authorization, wristband_secret, wristband_endpoint) -> Authorization:
def authorization(authorization, wristband_secret, wristband_endpoint) -> AuthConfig:
"""Add wristband response with the signing key to the AuthConfig"""
authorization.responses.add(
{
Expand Down

0 comments on commit cdf4ee4

Please sign in to comment.