Skip to content

Commit b882458

Browse files
committed
Replaced urllib.parse.urljoin() with a private _urljoin(). Addresses changes made in Python 3.11 urllib.parse.urlsplit() which is implicitly called by urllib.parse.urljoin(): python/cpython#103848
CDK guarantee's a static URL is returned from the default Api stage: https://github.com/aws/aws-cdk/blob/v2.103.1/packages/@aws-cdk/aws-apigatewayv2-alpha/lib/http/stage.ts#L188-L192 So, since we're only appending some desired path to the base of the HttpApi URL, we extrapolate and format the scheme + netloc, concatenate the path, then return the result.
1 parent 59c59ee commit b882458

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

components/control_broker_api.py

+15-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import json
22
from typing import Any
3-
from urllib.parse import urljoin
43

54
import aws_cdk
65
from aws_cdk import (
@@ -18,6 +17,7 @@
1817

1918

2019
class ControlBrokerApi(aws_apigatewayv2_alpha.HttpApi):
20+
2121
CONTROL_BROKER_EVAL_ENGINE_INVOCATION_PATH = "/EvalEngine"
2222

2323
def __init__(
@@ -68,8 +68,18 @@ def __init__(
6868
},
6969
)
7070
self.urls = []
71+
72+
self.parsed_url = self.url.split('/')
73+
self.scheme = self.parsed_url[0].rstrip(':')
74+
self.netloc = self.parsed_url[2].rstrip('/')
75+
7176
self._add_control_broker_eval_engine_invocation_route()
7277

78+
def _urljoin(self, path: str) -> str:
79+
"""Concatenate and return a URL using the base HttpApi's scheme + netloc with the desired path."""
80+
81+
return '{}://{}/{}'.format(self.scheme, self.netloc, path)
82+
7383
def _add_control_broker_eval_engine_invocation_route(self):
7484
"""Adds a route, which only handlers can call, that directly invokes the Control Broker Eval Engine."""
7585

@@ -84,10 +94,9 @@ def _add_control_broker_eval_engine_invocation_route(self):
8494
integration=self.handler_invocation_integration,
8595
authorizer=aws_apigatewayv2_authorizers_alpha.HttpIamAuthorizer(),
8696
)[0]
87-
eval_engine_url = urljoin(
88-
self.url.rstrip("/"),
89-
self.CONTROL_BROKER_EVAL_ENGINE_INVOCATION_PATH.strip("/"),
90-
)
97+
98+
eval_engine_url = self._urljoin(self.CONTROL_BROKER_EVAL_ENGINE_INVOCATION_PATH.strip('/'))
99+
91100
self.urls.append(eval_engine_url)
92101
self.handler_invocation_url_mapping = aws_apigatewayv2_alpha.ParameterMapping()
93102
self.handler_invocation_url_mapping.overwrite_header(
@@ -131,7 +140,7 @@ def add_api_handler(
131140
integration=integration,
132141
**kwargs,
133142
)[0]
134-
handler_url = urljoin(self.url.rstrip("/"), path.strip("/"))
143+
handler_url = self._urljoin(path.strip("/"))
135144
self.urls.append(handler_url)
136145
CfnOutput(self, f"{name}HandlerUrl", value=handler_url)
137146
# return route

0 commit comments

Comments
 (0)