@@ -393,11 +393,11 @@ def _add_method(self, effect: str, verb: str, resource: str, conditions: List[Di
393
393
the internal list contains a resource ARN and a condition statement. The condition
394
394
statement can be null."""
395
395
if verb != "*" and not hasattr (HttpVerb , verb ):
396
- raise NameError (f"Invalid HTTP verb { verb } . Allowed verbs in HttpVerb class" )
396
+ raise ValueError (f"Invalid HTTP verb { verb } . Allowed verbs in HttpVerb class" )
397
397
398
398
resource_pattern = re .compile (self .path_regex )
399
399
if not resource_pattern .match (resource ):
400
- raise NameError (f"Invalid resource path: { resource } . Path should match { self .path_regex } " )
400
+ raise ValueError (f"Invalid resource path: { resource } . Path should match { self .path_regex } " )
401
401
if resource [:1 ] == "/" :
402
402
resource = resource [1 :]
403
403
@@ -445,35 +445,29 @@ def deny_all_methods(self):
445
445
"""Adds a '*' allow to the policy to deny access to all methods of an API"""
446
446
self ._add_method ("Deny" , HttpVerb .ALL , "*" , [])
447
447
448
- def allow_method (self , verb , resource : str ):
448
+ def allow_method (self , http_method : str , resource : str , conditions : Optional [ List [ Dict ]] = None ):
449
449
"""Adds an API Gateway method (Http verb + Resource path) to the list of allowed
450
- methods for the policy"""
451
- self ._add_method ("Allow" , verb , resource , [])
450
+ methods for the policy.
452
451
453
- def deny_method (self , verb : str , resource : str ):
454
- """Adds an API Gateway method (Http verb + Resource path) to the list of denied
455
- methods for the policy"""
456
- self ._add_method ("Deny" , verb , resource , [])
457
-
458
- def allow_method_with_conditions (self , verb : str , resource : str , conditions : List [Dict ]):
459
- """Adds an API Gateway method (Http verb + Resource path) to the list of allowed
460
- methods and includes a condition for the policy statement. More on AWS policy
452
+ Optionally includes a condition for the policy statement. More on AWS policy
461
453
conditions here: https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements.html#Condition"""
462
- self ._add_method ("Allow" , verb , resource , conditions )
454
+ self ._add_method ("Allow" , http_method , resource , conditions or [] )
463
455
464
- def deny_method_with_conditions (self , verb : str , resource : str , conditions : List [Dict ]):
456
+ def deny_method (self , http_method : str , resource : str , conditions : Optional [ List [Dict ]] = None ):
465
457
"""Adds an API Gateway method (Http verb + Resource path) to the list of denied
466
- methods and includes a condition for the policy statement. More on AWS policy
458
+ methods for the policy.
459
+
460
+ Optionally includes a condition for the policy statement. More on AWS policy
467
461
conditions here: https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements.html#Condition"""
468
- self ._add_method ("Deny" , verb , resource , conditions )
462
+ self ._add_method ("Deny" , http_method , resource , conditions or [] )
469
463
470
464
def asdict (self ) -> Dict [str , Any ]:
471
465
"""Generates the policy document based on the internal lists of allowed and denied
472
466
conditions. This will generate a policy with two main statements for the effect:
473
467
one statement for Allow and one statement for Deny.
474
468
Methods that includes conditions will have their own statement in the policy."""
475
469
if len (self ._allow_methods ) == 0 and len (self ._deny_methods ) == 0 :
476
- raise NameError ("No statements defined for the policy" )
470
+ raise ValueError ("No statements defined for the policy" )
477
471
478
472
response : Dict [str , Any ] = {
479
473
"principalId" : self .principal_id ,
0 commit comments