@@ -36,9 +36,16 @@ def arn(self) -> str:
36
36
eg: arn:aws:execute-api:us-east-1:123456789012:abcdef123/test/GET/request"""
37
37
return (
38
38
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 } "
40
40
)
41
41
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
+
42
49
43
50
def parse_api_gateway_arn (arn : str ) -> APIGatewayRouteArn :
44
51
"""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
440
447
if not self ._resource_pattern .match (resource ):
441
448
raise ValueError (f"Invalid resource path: { resource } . Path should match { self .path_regex } " )
442
449
443
- resource = self ._removeprefix (resource , "/" )
444
-
445
450
resource_arn = APIGatewayRouteArn (
446
451
self .region , self .aws_account_id , self .api_id , self .stage , http_method , resource
447
452
).arn
@@ -453,14 +458,6 @@ def _add_route(self, effect: str, http_method: str, resource: str, conditions: O
453
458
else : # deny
454
459
self ._deny_routes .append (route )
455
460
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
-
464
461
@staticmethod
465
462
def _get_empty_statement (effect : str ) -> Dict [str , Any ]:
466
463
"""Returns an empty statement object prepopulated with the correct action and the desired effect."""
0 commit comments