Skip to content

Commit 286b0de

Browse files
author
Michael Brewer
committed
chore: another option
1 parent 27ecea1 commit 286b0de

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

aws_lambda_powertools/utilities/data_classes/api_gateway_authorizer_event.py

+8-11
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,16 @@ def arn(self) -> str:
3636
eg: arn:aws:execute-api:us-east-1:123456789012:abcdef123/test/GET/request"""
3737
return (
3838
f"arn:{self.partition}:execute-api:{self.region}:{self.aws_account_id}:{self.api_id}/{self.stage}/"
39-
f"{self.http_method}/{self.resource}"
39+
f"{self.http_method}/{self._resource}"
4040
)
4141

42+
@property
43+
def _resource(self) -> str:
44+
"""Remove matching "/" from `resource`. To be replaced with built-in `removeprefix`"""
45+
if self.resource.startswith("/"):
46+
return self.resource[1:]
47+
return self.resource
48+
4249

4350
def parse_api_gateway_arn(arn: str) -> APIGatewayRouteArn:
4451
"""Parses a gateway route arn as a APIGatewayRouteArn class
@@ -440,8 +447,6 @@ def _add_route(self, effect: str, http_method: str, resource: str, conditions: O
440447
if not self._resource_pattern.match(resource):
441448
raise ValueError(f"Invalid resource path: {resource}. Path should match {self.path_regex}")
442449

443-
resource = self._removeprefix(resource, "/")
444-
445450
resource_arn = APIGatewayRouteArn(
446451
self.region, self.aws_account_id, self.api_id, self.stage, http_method, resource
447452
).arn
@@ -453,14 +458,6 @@ def _add_route(self, effect: str, http_method: str, resource: str, conditions: O
453458
else: # deny
454459
self._deny_routes.append(route)
455460

456-
@staticmethod
457-
def _removeprefix(value: str, prefix: str) -> str:
458-
"""Remove matching prefix from value. To be replaced with built-in `removeprefix`"""
459-
length = len(prefix)
460-
if value[:length] == prefix:
461-
return value[length:]
462-
return value
463-
464461
@staticmethod
465462
def _get_empty_statement(effect: str) -> Dict[str, Any]:
466463
"""Returns an empty statement object prepopulated with the correct action and the desired effect."""

0 commit comments

Comments
 (0)