Skip to content

Commit

Permalink
PR IdentityPython#405: apply changes from review
Browse files Browse the repository at this point in the history
Add base_path and endpoint_basepath to backend and micro_services

Co-authored-by: Ivan Kanakarakis <[email protected]>
  • Loading branch information
bajnokk and c00kiemon5ter committed Nov 24, 2023
1 parent f558ead commit 5878cbd
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 20 deletions.
6 changes: 6 additions & 0 deletions src/satosa/backends/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"""

from ..attribute_mapping import AttributeMapper
from ..util import join_paths

from urllib.parse import urlparse


class BackendModule(object):
Expand Down Expand Up @@ -30,7 +33,10 @@ def __init__(self, auth_callback_func, internal_attributes, base_url, name):
self.internal_attributes = internal_attributes
self.converter = AttributeMapper(internal_attributes)
self.base_url = base_url.rstrip("/") if base_url else ""
self.base_path = urlparse(self.base_url).path.lstrip("/")
self.name = name
self.endpoint_baseurl = join_paths(self.base_url, self.name)
self.endpoint_basepath = urlparse(self.endpoint_baseurl).path.lstrip("/")

def start_auth(self, context, internal_request):
"""
Expand Down
1 change: 1 addition & 0 deletions src/satosa/frontends/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def __init__(self, auth_req_callback_func, internal_attributes, base_url, name):
self.internal_attributes = internal_attributes
self.converter = AttributeMapper(internal_attributes)
self.base_url = base_url or ""
self.base_path = urlparse(self.base_url).path.lstrip("/")
self.name = name
self.endpoint_baseurl = join_paths(self.base_url, self.name)
self.endpoint_basepath = urlparse(self.endpoint_baseurl).path.lstrip("/")
Expand Down
29 changes: 17 additions & 12 deletions src/satosa/frontends/saml2.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from ..response import Response
from ..response import ServiceError
from ..saml_util import make_saml_response
from ..util import join_paths
from satosa.exception import SATOSAError
import satosa.util as util

Expand Down Expand Up @@ -511,17 +512,18 @@ def _register_endpoints(self, providers):
"""
url_map = []

backend_providers = "|".join(providers)
base_path = urlparse(self.base_url).path.lstrip("/")
if base_path:
base_path = base_path + "/"
backend_providers = "(" + "|".join(providers) + ")"
for endp_category in self.endpoints:
for binding, endp in self.endpoints[endp_category].items():
endp_path = urlparse(endp).path
url_map.append(
(
"^{}({})/{}$".format(base_path, backend_providers, endp_path),
functools.partial(self.handle_authn_request, binding_in=binding)
"^{}$".format(
join_paths(self.base_path, backend_providers, endp_path)
),
functools.partial(
self.handle_authn_request, binding_in=binding
),
)
)

Expand Down Expand Up @@ -769,17 +771,20 @@ def _register_endpoints(self, providers):
"""
url_map = []

backend_providers = "|".join(providers)
base_path = urlparse(self.base_url).path.lstrip("/")
if base_path:
base_path = base_path + "/"
backend_providers = "(" + "|".join(providers) + ")"
for endp_category in self.endpoints:
for binding, endp in self.endpoints[endp_category].items():
endp_path = urlparse(endp).path
url_map.append(
(
"^{}({})/\S+/{}$".format(base_path, backend_providers, endp_path),
functools.partial(self.handle_authn_request, binding_in=binding)
"^{}$".format(
join_paths(
self.base_path, backend_providers, "\S+", endp_path
)
),
functools.partial(
self.handle_authn_request, binding_in=binding
),
)
)

Expand Down
4 changes: 1 addition & 3 deletions src/satosa/micro_services/account_linking.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,7 @@ def register_endpoints(self):
return [
(
"^{}$".format(
join_paths(
self.base_path, "account_linking", self.endpoint
)
join_paths(self.base_path, "account_linking", self.endpoint)
),
self._handle_al_response,
)
Expand Down
4 changes: 4 additions & 0 deletions src/satosa/micro_services/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import logging
from urllib.parse import urlparse

from ..util import join_paths

logger = logging.getLogger(__name__)


Expand All @@ -16,6 +18,8 @@ def __init__(self, name, base_url, **kwargs):
self.name = name
self.base_url = base_url
self.base_path = urlparse(base_url).path.lstrip("/")
self.endpoint_baseurl = join_paths(self.base_url, self.name)
self.endpoint_basepath = urlparse(self.endpoint_baseurl).path.lstrip("/")
self.next = None

def process(self, context, data):
Expand Down
4 changes: 1 addition & 3 deletions src/satosa/micro_services/consent.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,7 @@ def register_endpoints(self):
return [
(
"^{}$".format(
join_paths(
self.base_path, "consent", self.endpoint
)
join_paths(self.base_path, "consent", self.endpoint)
),
self._handle_consent_response,
)
Expand Down
4 changes: 2 additions & 2 deletions src/satosa/routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class UnknownEndpoint(ValueError):
and handles the internal routing between frontends and backends.
"""

def __init__(self, frontends, backends, micro_services, base_path=""):
def __init__(self, frontends, backends, micro_services, base_path=None):
"""
:type frontends: dict[str, satosa.frontends.base.FrontendModule]
:type backends: dict[str, satosa.backends.base.BackendModule]
Expand Down Expand Up @@ -70,7 +70,7 @@ def __init__(self, frontends, backends, micro_services, base_path=""):
else:
self.micro_services = {}

self.base_path = base_path
self.base_path = base_path if base_path else ""

logger.debug("Loaded backends with endpoints: {}".format(backends))
logger.debug("Loaded frontends with endpoints: {}".format(frontends))
Expand Down

0 comments on commit 5878cbd

Please sign in to comment.