@@ -351,9 +351,6 @@ class APIGatewayAuthorizerResponse:
351
351
- https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-lambda-authorizer-output.html
352
352
"""
353
353
354
- version = "2012-10-17"
355
- """The policy version used for the evaluation. This should always be '2012-10-17'"""
356
-
357
354
path_regex = r"^[/.a-zA-Z0-9-\*]+$"
358
355
"""The regular expression used to validate resource paths for the policy"""
359
356
@@ -408,6 +405,7 @@ def __init__(
408
405
self .usage_identifier_key = usage_identifier_key
409
406
self ._allow_routes : List [Dict ] = []
410
407
self ._deny_routes : List [Dict ] = []
408
+ self .resource_pattern = re .compile (self .path_regex )
411
409
412
410
def _add_route (self , effect : str , http_method : str , resource : str , conditions : Optional [List [Dict ]] = None ):
413
411
"""Adds a route to the internal lists of allowed or denied routes. Each object in
@@ -417,8 +415,7 @@ def _add_route(self, effect: str, http_method: str, resource: str, conditions: O
417
415
allowed_values = [verb .value for verb in HttpVerb ]
418
416
raise ValueError (f"Invalid HTTP verb: '{ http_method } '. Use either '{ allowed_values } '" )
419
417
420
- resource_pattern = re .compile (self .path_regex )
421
- if not resource_pattern .match (resource ):
418
+ if not self .resource_pattern .match (resource ):
422
419
raise ValueError (f"Invalid resource path: { resource } . Path should match { self .path_regex } " )
423
420
424
421
if resource [:1 ] == "/" :
@@ -443,7 +440,7 @@ def _get_empty_statement(effect: str) -> Dict[str, Any]:
443
440
def _get_statement_for_effect (self , effect : str , routes : List [Dict ]) -> List [Dict ]:
444
441
"""This function loops over an array of objects containing a `resourceArn` and
445
442
`conditions` statement and generates the array of statements for the policy."""
446
- if len ( routes ) == 0 :
443
+ if not routes :
447
444
return []
448
445
449
446
statements : List [Dict ] = []
@@ -511,7 +508,7 @@ def asdict(self) -> Dict[str, Any]:
511
508
512
509
response : Dict [str , Any ] = {
513
510
"principalId" : self .principal_id ,
514
- "policyDocument" : {"Version" : self . version , "Statement" : []},
511
+ "policyDocument" : {"Version" : "2012-10-17" , "Statement" : []},
515
512
}
516
513
517
514
response ["policyDocument" ]["Statement" ].extend (self ._get_statement_for_effect ("Allow" , self ._allow_routes ))
0 commit comments