@@ -52,24 +52,23 @@ def apigateway_models_resource_delete_integration(self, method_type):
52
52
53
53
return {}
54
54
55
- def apigateway_models_Integration_init (
56
- self , integration_type , uri , http_method ,
57
- request_templates = None , pass_through_behavior = 'WHEN_NO_MATCH' , cache_key_parameters = []
58
- ):
59
- super (apigateway_models .Integration , self ).__init__ ()
60
- self ['type' ] = integration_type
61
- self ['uri' ] = uri
62
- self ['httpMethod' ] = http_method
55
+ def apigateway_models_Integration_init (self , integration_type , uri , http_method ,
56
+ request_templates = None , pass_through_behavior = 'WHEN_NO_MATCH' , cache_key_parameters = [], * args , ** kwargs ):
57
+ apigateway_models_Integration_init_orig (
58
+ self , integration_type = integration_type , uri = uri , http_method = http_method ,
59
+ request_templates = request_templates , * args , ** kwargs
60
+ )
61
+
63
62
self ['passthroughBehavior' ] = pass_through_behavior
64
63
self ['cacheKeyParameters' ] = cache_key_parameters
65
64
self ['cacheNamespace' ] = short_uid ()
66
- self ['timeoutInMillis' ] = None
67
- self ['integrationResponses' ] = {'200' : apigateway_models .IntegrationResponse (200 )}
65
+
66
+ # httpMethod not present in response if integration_type is None, verified against AWS
67
+ if integration_type == 'MOCK' :
68
+ self ['httpMethod' ] = None
68
69
if request_templates :
69
70
self ['requestTemplates' ] = request_templates
70
71
71
- apigateway_models .Integration .__init__ = apigateway_models_Integration_init
72
-
73
72
def apigateway_models_backend_put_rest_api (self , function_id , body ):
74
73
rest_api = self .get_rest_api (function_id )
75
74
# Remove default root, then add paths from API spec
@@ -131,6 +130,7 @@ def apigateway_response_restapis_individual(self, request, full_url, headers):
131
130
132
131
def apigateway_response_resource_methods (self , request , * args , ** kwargs ):
133
132
result = apigateway_response_resource_methods_orig (self , request , * args , ** kwargs )
133
+
134
134
if len (result ) != 3 :
135
135
return result
136
136
authorization_type = self ._get_param ('authorizationType' )
@@ -143,24 +143,65 @@ def apigateway_response_resource_methods(self, request, *args, **kwargs):
143
143
result = result [0 ], result [1 ], json .dumps (data )
144
144
return result
145
145
146
- apigateway_response_integrations_orig = APIGatewayResponse .integrations
147
-
148
- def apigateway_response_integrations (self , request , full_url , headers ):
149
- result = apigateway_response_integrations_orig (self , request , full_url , headers )
146
+ def apigateway_response_integrations (self , request , * args , ** kwargs ):
147
+ result = apigateway_response_integrations_orig (self , request , * args , ** kwargs )
150
148
timeout_milliseconds = self ._get_param ('timeoutInMillis' )
149
+ request_parameters = self ._get_param ('requestParameters' ) or {}
150
+ cache_key_parameters = self ._get_param ('cacheKeyParameters' ) or []
151
+ content_handling = self ._get_param ('contentHandling' )
152
+
153
+ if self .method == 'PUT' :
154
+ url_path_parts = self .path .split ('/' )
155
+ function_id = url_path_parts [2 ]
156
+ resource_id = url_path_parts [4 ]
157
+ method_type = url_path_parts [6 ]
158
+
159
+ integration_response = self .backend .get_integration (function_id , resource_id , method_type )
160
+
161
+ integration_response ['timeoutInMillis' ] = timeout_milliseconds
162
+ integration_response ['requestParameters' ] = request_parameters
163
+ integration_response ['cacheKeyParameters' ] = cache_key_parameters
164
+ integration_response ['contentHandling' ] = content_handling
165
+ return 200 , {}, json .dumps (integration_response )
166
+
167
+ return result
168
+
169
+ def apigateway_response_integration_responses (self , request , * args , ** kwargs ):
170
+ result = apigateway_response_integration_responses_orig (self , request , * args , ** kwargs )
171
+ response_parameters = self ._get_param ('responseParameters' )
172
+
173
+ if self .method == 'PUT' and response_parameters :
174
+ url_path_parts = self .path .split ('/' )
175
+ function_id = url_path_parts [2 ]
176
+ resource_id = url_path_parts [4 ]
177
+ method_type = url_path_parts [6 ]
178
+ status_code = url_path_parts [9 ]
179
+
180
+ integration_response = self .backend .get_integration_response (
181
+ function_id , resource_id , method_type , status_code
182
+ )
183
+ integration_response ['responseParameters' ] = response_parameters
184
+
185
+ return 200 , {}, json .dumps (integration_response )
186
+
187
+ return result
151
188
152
- if self .method == 'PUT' and timeout_milliseconds :
189
+ def apigateway_response_resource_method_responses (self , request , * args , ** kwargs ):
190
+ result = apigateway_response_resource_method_responses_orig (self , request , * args , ** kwargs )
191
+ response_parameters = self ._get_param ('responseParameters' )
192
+
193
+ if self .method == 'PUT' and response_parameters :
153
194
url_path_parts = self .path .split ('/' )
154
195
function_id = url_path_parts [2 ]
155
196
resource_id = url_path_parts [4 ]
156
197
method_type = url_path_parts [6 ]
198
+ response_code = url_path_parts [8 ]
199
+
200
+ method_response = self .backend .get_method_response (function_id , resource_id , method_type , response_code )
157
201
158
- resource = self .backend .get_resource (function_id , resource_id )
159
- resource .resource_methods [method_type ]['methodIntegration' ] = (
160
- resource .resource_methods [method_type ].get ('methodIntegration' ) or {})
161
- resource .resource_methods [method_type ]['methodIntegration' ]['timeoutInMillis' ] = timeout_milliseconds
202
+ method_response ['responseParameters' ] = response_parameters
162
203
163
- return result [ 0 ], result [ 1 ] , json .dumps (resource . resource_methods [ method_type ][ 'methodIntegration' ] )
204
+ return 200 , {} , json .dumps (method_response )
164
205
165
206
return result
166
207
@@ -177,7 +218,14 @@ def apigateway_response_integrations(self, request, full_url, headers):
177
218
apigateway_models .Resource .delete_integration = apigateway_models_resource_delete_integration
178
219
apigateway_response_resource_methods_orig = APIGatewayResponse .resource_methods
179
220
APIGatewayResponse .resource_methods = apigateway_response_resource_methods
221
+ apigateway_response_integrations_orig = APIGatewayResponse .integrations
180
222
APIGatewayResponse .integrations = apigateway_response_integrations
223
+ apigateway_response_integration_responses_orig = APIGatewayResponse .integration_responses
224
+ APIGatewayResponse .integration_responses = apigateway_response_integration_responses
225
+ apigateway_response_resource_method_responses_orig = APIGatewayResponse .resource_method_responses
226
+ APIGatewayResponse .resource_method_responses = apigateway_response_resource_method_responses
227
+ apigateway_models_Integration_init_orig = apigateway_models .Integration .__init__
228
+ apigateway_models .Integration .__init__ = apigateway_models_Integration_init
181
229
182
230
183
231
def start_apigateway (port = None , backend_port = None , asynchronous = None , update_listener = None ):
0 commit comments