@@ -892,6 +892,8 @@ def add_resource_policy(self, resource_policy, path, api_id, stage):
892
892
ip_range_blacklist = resource_policy .get ("IpRangeBlacklist" )
893
893
source_vpc_whitelist = resource_policy .get ("SourceVpcWhitelist" )
894
894
source_vpc_blacklist = resource_policy .get ("SourceVpcBlacklist" )
895
+
896
+ # Intrinsic's supported in these properties
895
897
source_vpc_intrinsic_whitelist = resource_policy .get ("IntrinsicVpcWhitelist" )
896
898
source_vpce_intrinsic_whitelist = resource_policy .get ("IntrinsicVpceWhitelist" )
897
899
source_vpc_intrinsic_blacklist = resource_policy .get ("IntrinsicVpcBlacklist" )
@@ -913,31 +915,38 @@ def add_resource_policy(self, resource_policy, path, api_id, stage):
913
915
resource_list = self ._get_method_path_uri_list (path , api_id , stage )
914
916
self ._add_ip_resource_policy_for_method (ip_range_blacklist , "IpAddress" , resource_list )
915
917
916
- if (
917
- (source_vpc_blacklist is not None )
918
- or (source_vpc_intrinsic_blacklist is not None )
919
- or (source_vpce_intrinsic_blacklist is not None )
920
- ):
921
- blacklist_dict = {
922
- "StringEndpointList" : source_vpc_blacklist ,
923
- "IntrinsicVpcList" : source_vpc_intrinsic_blacklist ,
924
- "IntrinsicVpceList" : source_vpce_intrinsic_blacklist ,
925
- }
926
- resource_list = self ._get_method_path_uri_list (path , api_id , stage )
927
- self ._add_vpc_resource_policy_for_method (blacklist_dict , "StringEquals" , resource_list )
918
+ if not SwaggerEditor ._validate_list_property_is_resolved (source_vpc_blacklist ):
919
+ raise InvalidDocumentException (
920
+ [
921
+ InvalidTemplateException (
922
+ "SourceVpcBlacklist must be a list of strings. Use IntrinsicVpcBlacklist instead for values that use Intrinsic Functions"
923
+ )
924
+ ]
925
+ )
928
926
929
- if (
930
- (source_vpc_whitelist is not None )
931
- or (source_vpc_intrinsic_whitelist is not None )
932
- or (source_vpce_intrinsic_whitelist is not None )
933
- ):
934
- whitelist_dict = {
935
- "StringEndpointList" : source_vpc_whitelist ,
936
- "IntrinsicVpcList" : source_vpc_intrinsic_whitelist ,
937
- "IntrinsicVpceList" : source_vpce_intrinsic_whitelist ,
938
- }
939
- resource_list = self ._get_method_path_uri_list (path , api_id , stage )
940
- self ._add_vpc_resource_policy_for_method (whitelist_dict , "StringNotEquals" , resource_list )
927
+ blacklist_dict = {
928
+ "StringEndpointList" : source_vpc_blacklist ,
929
+ "IntrinsicVpcList" : source_vpc_intrinsic_blacklist ,
930
+ "IntrinsicVpceList" : source_vpce_intrinsic_blacklist ,
931
+ }
932
+ resource_list = self ._get_method_path_uri_list (path , api_id , stage )
933
+ self ._add_vpc_resource_policy_for_method (blacklist_dict , "StringEquals" , resource_list )
934
+
935
+ if not SwaggerEditor ._validate_list_property_is_resolved (source_vpc_whitelist ):
936
+ raise InvalidDocumentException (
937
+ [
938
+ InvalidTemplateException (
939
+ "SourceVpcWhitelist must be a list of strings. Use IntrinsicVpcWhitelist instead for values that use Intrinsic Functions"
940
+ )
941
+ ]
942
+ )
943
+
944
+ whitelist_dict = {
945
+ "StringEndpointList" : source_vpc_whitelist ,
946
+ "IntrinsicVpcList" : source_vpc_intrinsic_whitelist ,
947
+ "IntrinsicVpceList" : source_vpce_intrinsic_whitelist ,
948
+ }
949
+ self ._add_vpc_resource_policy_for_method (whitelist_dict , "StringNotEquals" , resource_list )
941
950
942
951
self ._doc [self ._X_APIGW_POLICY ] = self .resource_policy
943
952
@@ -1268,3 +1277,17 @@ def safe_compare_regex_with_string(regex, data):
1268
1277
def get_path_without_trailing_slash (path ):
1269
1278
# convert greedy paths to such as {greedy+}, {proxy+} to "*"
1270
1279
return re .sub (r"{([a-zA-Z0-9._-]+|[a-zA-Z0-9._-]+\+|proxy\+)}" , "*" , path )
1280
+
1281
+ @staticmethod
1282
+ def _validate_list_property_is_resolved (property_list ):
1283
+ """
1284
+ Validate if the values of a Property List are all of type string
1285
+
1286
+ :param property_list: Value of a Property List
1287
+ :return bool: True if the property_list is all of type string otherwise False
1288
+ """
1289
+
1290
+ if property_list is not None and not all (isinstance (x , string_types ) for x in property_list ):
1291
+ return False
1292
+
1293
+ return True
0 commit comments