Skip to content

Commit 5878cbd

Browse files
PR IdentityPython#405: apply changes from review
Add base_path and endpoint_basepath to backend and micro_services Co-authored-by: Ivan Kanakarakis <ivan.kanak@gmail.com>
1 parent f558ead commit 5878cbd

File tree

7 files changed

+32
-20
lines changed

7 files changed

+32
-20
lines changed

src/satosa/backends/base.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
"""
44

55
from ..attribute_mapping import AttributeMapper
6+
from ..util import join_paths
7+
8+
from urllib.parse import urlparse
69

710

811
class BackendModule(object):
@@ -30,7 +33,10 @@ def __init__(self, auth_callback_func, internal_attributes, base_url, name):
3033
self.internal_attributes = internal_attributes
3134
self.converter = AttributeMapper(internal_attributes)
3235
self.base_url = base_url.rstrip("/") if base_url else ""
36+
self.base_path = urlparse(self.base_url).path.lstrip("/")
3337
self.name = name
38+
self.endpoint_baseurl = join_paths(self.base_url, self.name)
39+
self.endpoint_basepath = urlparse(self.endpoint_baseurl).path.lstrip("/")
3440

3541
def start_auth(self, context, internal_request):
3642
"""

src/satosa/frontends/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def __init__(self, auth_req_callback_func, internal_attributes, base_url, name):
3030
self.internal_attributes = internal_attributes
3131
self.converter = AttributeMapper(internal_attributes)
3232
self.base_url = base_url or ""
33+
self.base_path = urlparse(self.base_url).path.lstrip("/")
3334
self.name = name
3435
self.endpoint_baseurl = join_paths(self.base_url, self.name)
3536
self.endpoint_basepath = urlparse(self.endpoint_baseurl).path.lstrip("/")

src/satosa/frontends/saml2.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from ..response import Response
3434
from ..response import ServiceError
3535
from ..saml_util import make_saml_response
36+
from ..util import join_paths
3637
from satosa.exception import SATOSAError
3738
import satosa.util as util
3839

@@ -511,17 +512,18 @@ def _register_endpoints(self, providers):
511512
"""
512513
url_map = []
513514

514-
backend_providers = "|".join(providers)
515-
base_path = urlparse(self.base_url).path.lstrip("/")
516-
if base_path:
517-
base_path = base_path + "/"
515+
backend_providers = "(" + "|".join(providers) + ")"
518516
for endp_category in self.endpoints:
519517
for binding, endp in self.endpoints[endp_category].items():
520518
endp_path = urlparse(endp).path
521519
url_map.append(
522520
(
523-
"^{}({})/{}$".format(base_path, backend_providers, endp_path),
524-
functools.partial(self.handle_authn_request, binding_in=binding)
521+
"^{}$".format(
522+
join_paths(self.base_path, backend_providers, endp_path)
523+
),
524+
functools.partial(
525+
self.handle_authn_request, binding_in=binding
526+
),
525527
)
526528
)
527529

@@ -769,17 +771,20 @@ def _register_endpoints(self, providers):
769771
"""
770772
url_map = []
771773

772-
backend_providers = "|".join(providers)
773-
base_path = urlparse(self.base_url).path.lstrip("/")
774-
if base_path:
775-
base_path = base_path + "/"
774+
backend_providers = "(" + "|".join(providers) + ")"
776775
for endp_category in self.endpoints:
777776
for binding, endp in self.endpoints[endp_category].items():
778777
endp_path = urlparse(endp).path
779778
url_map.append(
780779
(
781-
"^{}({})/\S+/{}$".format(base_path, backend_providers, endp_path),
782-
functools.partial(self.handle_authn_request, binding_in=binding)
780+
"^{}$".format(
781+
join_paths(
782+
self.base_path, backend_providers, "\S+", endp_path
783+
)
784+
),
785+
functools.partial(
786+
self.handle_authn_request, binding_in=binding
787+
),
783788
)
784789
)
785790

src/satosa/micro_services/account_linking.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,7 @@ def register_endpoints(self):
165165
return [
166166
(
167167
"^{}$".format(
168-
join_paths(
169-
self.base_path, "account_linking", self.endpoint
170-
)
168+
join_paths(self.base_path, "account_linking", self.endpoint)
171169
),
172170
self._handle_al_response,
173171
)

src/satosa/micro_services/base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import logging
55
from urllib.parse import urlparse
66

7+
from ..util import join_paths
8+
79
logger = logging.getLogger(__name__)
810

911

@@ -16,6 +18,8 @@ def __init__(self, name, base_url, **kwargs):
1618
self.name = name
1719
self.base_url = base_url
1820
self.base_path = urlparse(base_url).path.lstrip("/")
21+
self.endpoint_baseurl = join_paths(self.base_url, self.name)
22+
self.endpoint_basepath = urlparse(self.endpoint_baseurl).path.lstrip("/")
1923
self.next = None
2024

2125
def process(self, context, data):

src/satosa/micro_services/consent.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,7 @@ def register_endpoints(self):
242242
return [
243243
(
244244
"^{}$".format(
245-
join_paths(
246-
self.base_path, "consent", self.endpoint
247-
)
245+
join_paths(self.base_path, "consent", self.endpoint)
248246
),
249247
self._handle_consent_response,
250248
)

src/satosa/routing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class UnknownEndpoint(ValueError):
3838
and handles the internal routing between frontends and backends.
3939
"""
4040

41-
def __init__(self, frontends, backends, micro_services, base_path=""):
41+
def __init__(self, frontends, backends, micro_services, base_path=None):
4242
"""
4343
:type frontends: dict[str, satosa.frontends.base.FrontendModule]
4444
:type backends: dict[str, satosa.backends.base.BackendModule]
@@ -70,7 +70,7 @@ def __init__(self, frontends, backends, micro_services, base_path=""):
7070
else:
7171
self.micro_services = {}
7272

73-
self.base_path = base_path
73+
self.base_path = base_path if base_path else ""
7474

7575
logger.debug("Loaded backends with endpoints: {}".format(backends))
7676
logger.debug("Loaded frontends with endpoints: {}".format(frontends))

0 commit comments

Comments
 (0)