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 authored Jun 12, 2023
1 parent 0c8ab4f commit 91c0ac2
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 16 deletions.
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
10 changes: 2 additions & 8 deletions src/satosa/frontends/saml2.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,15 +512,12 @@ 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 + "/"
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),
"^{}/({})/{}$".format(self.base_path, backend_providers, endp_path),
functools.partial(self.handle_authn_request, binding_in=binding)
)
)
Expand Down Expand Up @@ -770,15 +767,12 @@ 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 + "/"
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),
"^{}/({})/\S+/{}$".format(self.base_path, backend_providers, 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.endpoint_basepath, self.endpoint)
),
self._handle_al_response,
)
Expand Down
2 changes: 2 additions & 0 deletions src/satosa/micro_services/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,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.endpoint_basepath, 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 91c0ac2

Please sign in to comment.