1
1
import copy
2
- import json
3
2
import re
4
3
5
4
from samtranslator .model .intrinsics import ref , make_conditional , fnSub , is_intrinsic_no_value
@@ -45,11 +44,11 @@ def __init__(self, doc):
45
44
modifications on this copy.
46
45
47
46
:param dict doc: Swagger document as a dictionary
48
- :raises ValueError : If the input Swagger document does not meet the basic Swagger requirements.
47
+ :raises InvalidDocumentException : If the input Swagger document does not meet the basic Swagger requirements.
49
48
"""
50
49
51
50
if not SwaggerEditor .is_valid (doc ):
52
- raise ValueError ("Invalid Swagger document" )
51
+ raise InvalidDocumentException ("Invalid Swagger document" )
53
52
54
53
self ._doc = copy .deepcopy (doc )
55
54
self .paths = self ._doc ["paths" ]
@@ -187,7 +186,9 @@ def add_lambda_integration(
187
186
188
187
method = self ._normalize_method_name (method )
189
188
if self .has_integration (path , method ):
190
- raise ValueError ("Lambda integration already exists on Path={}, Method={}" .format (path , method ))
189
+ raise InvalidDocumentException (
190
+ "Lambda integration already exists on Path={}, Method={}" .format (path , method )
191
+ )
191
192
192
193
self .add_path (path , method )
193
194
@@ -251,7 +252,7 @@ def add_state_machine_integration(
251
252
252
253
method = self ._normalize_method_name (method )
253
254
if self .has_integration (path , method ):
254
- raise ValueError ("Integration already exists on Path={}, Method={}" .format (path , method ))
255
+ raise InvalidDocumentException ("Integration already exists on Path={}, Method={}" .format (path , method ))
255
256
256
257
self .add_path (path , method )
257
258
@@ -388,7 +389,7 @@ def add_cors(
388
389
:param integer/dict max_age: Maximum duration to cache the CORS Preflight request. Value is set on
389
390
Access-Control-Max-Age header. Value can also be an intrinsic function dict.
390
391
:param bool/None allow_credentials: Flags whether request is allowed to contain credentials.
391
- :raises ValueError : When values for one of the allowed_* variables is empty
392
+ :raises InvalidTemplateException : When values for one of the allowed_* variables is empty
392
393
"""
393
394
394
395
for path_item in self .get_conditional_contents (self .paths .get (path )):
@@ -1022,13 +1023,13 @@ def _add_iam_resource_policy_for_method(self, policy_list, effect, resource_list
1022
1023
"""
1023
1024
This method generates a policy statement to grant/deny specific IAM users access to the API method and
1024
1025
appends it to the swagger under `x-amazon-apigateway-policy`
1025
- :raises ValueError : If the effect passed in does not match the allowed values.
1026
+ :raises InvalidDocumentException : If the effect passed in does not match the allowed values.
1026
1027
"""
1027
1028
if not policy_list :
1028
1029
return
1029
1030
1030
1031
if effect not in ["Allow" , "Deny" ]:
1031
- raise ValueError ("Effect must be one of {}" .format (["Allow" , "Deny" ]))
1032
+ raise InvalidDocumentException ("Effect must be one of {}" .format (["Allow" , "Deny" ]))
1032
1033
1033
1034
if not isinstance (policy_list , (dict , list )):
1034
1035
raise InvalidDocumentException (
@@ -1081,7 +1082,7 @@ def _add_ip_resource_policy_for_method(self, ip_list, conditional, resource_list
1081
1082
"""
1082
1083
This method generates a policy statement to grant/deny specific IP address ranges access to the API method and
1083
1084
appends it to the swagger under `x-amazon-apigateway-policy`
1084
- :raises ValueError : If the conditional passed in does not match the allowed values.
1085
+ :raises InvalidDocumentException : If the conditional passed in does not match the allowed values.
1085
1086
"""
1086
1087
if not ip_list :
1087
1088
return
@@ -1090,7 +1091,7 @@ def _add_ip_resource_policy_for_method(self, ip_list, conditional, resource_list
1090
1091
ip_list = [ip_list ]
1091
1092
1092
1093
if conditional not in ["IpAddress" , "NotIpAddress" ]:
1093
- raise ValueError ("Conditional must be one of {}" .format (["IpAddress" , "NotIpAddress" ]))
1094
+ raise InvalidDocumentException ("Conditional must be one of {}" .format (["IpAddress" , "NotIpAddress" ]))
1094
1095
1095
1096
self .resource_policy ["Version" ] = "2012-10-17"
1096
1097
allow_statement = Py27Dict ()
@@ -1122,11 +1123,11 @@ def _add_vpc_resource_policy_for_method(self, endpoint_dict, conditional, resour
1122
1123
"""
1123
1124
This method generates a policy statement to grant/deny specific VPC/VPCE access to the API method and
1124
1125
appends it to the swagger under `x-amazon-apigateway-policy`
1125
- :raises ValueError : If the conditional passed in does not match the allowed values.
1126
+ :raises InvalidDocumentException : If the conditional passed in does not match the allowed values.
1126
1127
"""
1127
1128
1128
1129
if conditional not in ["StringNotEquals" , "StringEquals" ]:
1129
- raise ValueError ("Conditional must be one of {}" .format (["StringNotEquals" , "StringEquals" ]))
1130
+ raise InvalidDocumentException ("Conditional must be one of {}" .format (["StringNotEquals" , "StringEquals" ]))
1130
1131
1131
1132
condition = Py27Dict ()
1132
1133
string_endpoint_list = endpoint_dict .get ("StringEndpointList" )
0 commit comments