Skip to content

Commit ae97040

Browse files
author
Michael Brewer
committed
refactor: use a more explicit remove prefix
1 parent db1d9d1 commit ae97040

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

aws_lambda_powertools/utilities/data_classes/api_gateway_authorizer_event.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,8 +440,7 @@ def _add_route(self, effect: str, http_method: str, resource: str, conditions: O
440440
if not self._resource_pattern.match(resource):
441441
raise ValueError(f"Invalid resource path: {resource}. Path should match {self.path_regex}")
442442

443-
if resource.startswith("/"):
444-
resource = resource[1:]
443+
resource = self._removeprefix(resource, "/")
445444

446445
resource_arn = APIGatewayRouteArn(
447446
self.region, self.aws_account_id, self.api_id, self.stage, http_method, resource
@@ -454,6 +453,14 @@ def _add_route(self, effect: str, http_method: str, resource: str, conditions: O
454453
else: # deny
455454
self._deny_routes.append(route)
456455

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

logfile

Whitespace-only changes.

0 commit comments

Comments
 (0)