APIGateway: Add response parameters to integration response (#5675)
This commit is contained in:
parent
fa77d22d72
commit
db47aeeb02
@ -114,6 +114,7 @@ class IntegrationResponse(BaseModel):
|
|||||||
status_code: Union[str, int],
|
status_code: Union[str, int],
|
||||||
selection_pattern: Optional[str] = None,
|
selection_pattern: Optional[str] = None,
|
||||||
response_templates: Optional[Dict[str, Any]] = None,
|
response_templates: Optional[Dict[str, Any]] = None,
|
||||||
|
response_parameters: Optional[Dict[str, str]] = None,
|
||||||
content_handling: Optional[Any] = None,
|
content_handling: Optional[Any] = None,
|
||||||
):
|
):
|
||||||
if response_templates is None:
|
if response_templates is None:
|
||||||
@ -126,6 +127,7 @@ class IntegrationResponse(BaseModel):
|
|||||||
self.response_templates = response_templates
|
self.response_templates = response_templates
|
||||||
self.status_code = status_code
|
self.status_code = status_code
|
||||||
self.selection_pattern = selection_pattern
|
self.selection_pattern = selection_pattern
|
||||||
|
self.response_parameters = response_parameters
|
||||||
self.content_handling = content_handling
|
self.content_handling = content_handling
|
||||||
|
|
||||||
def to_json(self) -> Dict[str, Any]:
|
def to_json(self) -> Dict[str, Any]:
|
||||||
@ -137,6 +139,8 @@ class IntegrationResponse(BaseModel):
|
|||||||
resp["selectionPattern"] = self.selection_pattern
|
resp["selectionPattern"] = self.selection_pattern
|
||||||
if self.content_handling:
|
if self.content_handling:
|
||||||
resp["contentHandling"] = self.content_handling
|
resp["contentHandling"] = self.content_handling
|
||||||
|
if self.response_parameters:
|
||||||
|
resp["responseParameters"] = self.response_parameters
|
||||||
return resp
|
return resp
|
||||||
|
|
||||||
|
|
||||||
@ -191,10 +195,15 @@ class Integration(BaseModel):
|
|||||||
status_code: str,
|
status_code: str,
|
||||||
selection_pattern: str,
|
selection_pattern: str,
|
||||||
response_templates: Dict[str, str],
|
response_templates: Dict[str, str],
|
||||||
|
response_parameters: Dict[str, str],
|
||||||
content_handling: str,
|
content_handling: str,
|
||||||
) -> IntegrationResponse:
|
) -> IntegrationResponse:
|
||||||
integration_response = IntegrationResponse(
|
integration_response = IntegrationResponse(
|
||||||
status_code, selection_pattern, response_templates or None, content_handling
|
status_code,
|
||||||
|
selection_pattern,
|
||||||
|
response_templates or None,
|
||||||
|
response_parameters,
|
||||||
|
content_handling,
|
||||||
)
|
)
|
||||||
if self.integration_responses is None:
|
if self.integration_responses is None:
|
||||||
self.integration_responses = {}
|
self.integration_responses = {}
|
||||||
@ -1895,12 +1904,17 @@ class APIGatewayBackend(BaseBackend):
|
|||||||
status_code: str,
|
status_code: str,
|
||||||
selection_pattern: str,
|
selection_pattern: str,
|
||||||
response_templates: Dict[str, str],
|
response_templates: Dict[str, str],
|
||||||
|
response_parameters: Dict[str, str],
|
||||||
content_handling: str,
|
content_handling: str,
|
||||||
) -> IntegrationResponse:
|
) -> IntegrationResponse:
|
||||||
integration = self.get_integration(function_id, resource_id, method_type)
|
integration = self.get_integration(function_id, resource_id, method_type)
|
||||||
if integration:
|
if integration:
|
||||||
return integration.create_integration_response(
|
return integration.create_integration_response(
|
||||||
status_code, selection_pattern, response_templates, content_handling
|
status_code,
|
||||||
|
selection_pattern,
|
||||||
|
response_templates,
|
||||||
|
response_parameters,
|
||||||
|
content_handling,
|
||||||
)
|
)
|
||||||
raise NoIntegrationResponseDefined()
|
raise NoIntegrationResponseDefined()
|
||||||
|
|
||||||
|
@ -498,6 +498,7 @@ class APIGatewayResponse(BaseResponse):
|
|||||||
|
|
||||||
selection_pattern = self._get_param("selectionPattern")
|
selection_pattern = self._get_param("selectionPattern")
|
||||||
response_templates = self._get_param("responseTemplates")
|
response_templates = self._get_param("responseTemplates")
|
||||||
|
response_parameters = self._get_param("responseParameters")
|
||||||
content_handling = self._get_param("contentHandling")
|
content_handling = self._get_param("contentHandling")
|
||||||
integration_response = self.backend.put_integration_response(
|
integration_response = self.backend.put_integration_response(
|
||||||
function_id,
|
function_id,
|
||||||
@ -506,6 +507,7 @@ class APIGatewayResponse(BaseResponse):
|
|||||||
status_code,
|
status_code,
|
||||||
selection_pattern,
|
selection_pattern,
|
||||||
response_templates,
|
response_templates,
|
||||||
|
response_parameters,
|
||||||
content_handling,
|
content_handling,
|
||||||
)
|
)
|
||||||
return 201, {}, json.dumps(integration_response.to_json())
|
return 201, {}, json.dumps(integration_response.to_json())
|
||||||
|
@ -652,6 +652,10 @@ def test_integration_response():
|
|||||||
httpMethod="GET",
|
httpMethod="GET",
|
||||||
statusCode="200",
|
statusCode="200",
|
||||||
selectionPattern="foobar",
|
selectionPattern="foobar",
|
||||||
|
responseParameters={
|
||||||
|
"method.response.header.Location": "integration.response.body.redirect.url",
|
||||||
|
"method.response.header.x-user-id": "integration.response.header.x-userid",
|
||||||
|
},
|
||||||
responseTemplates={},
|
responseTemplates={},
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -664,6 +668,10 @@ def test_integration_response():
|
|||||||
"selectionPattern": "foobar",
|
"selectionPattern": "foobar",
|
||||||
"ResponseMetadata": {"HTTPStatusCode": 201},
|
"ResponseMetadata": {"HTTPStatusCode": 201},
|
||||||
"responseTemplates": {}, # Note: TF compatibility
|
"responseTemplates": {}, # Note: TF compatibility
|
||||||
|
"responseParameters": {
|
||||||
|
"method.response.header.Location": "integration.response.body.redirect.url",
|
||||||
|
"method.response.header.x-user-id": "integration.response.header.x-userid",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -679,6 +687,10 @@ def test_integration_response():
|
|||||||
"selectionPattern": "foobar",
|
"selectionPattern": "foobar",
|
||||||
"ResponseMetadata": {"HTTPStatusCode": 200},
|
"ResponseMetadata": {"HTTPStatusCode": 200},
|
||||||
"responseTemplates": {}, # Note: TF compatibility
|
"responseTemplates": {}, # Note: TF compatibility
|
||||||
|
"responseParameters": {
|
||||||
|
"method.response.header.Location": "integration.response.body.redirect.url",
|
||||||
|
"method.response.header.x-user-id": "integration.response.header.x-userid",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -692,6 +704,10 @@ def test_integration_response():
|
|||||||
"responseTemplates": {}, # Note: TF compatibility
|
"responseTemplates": {}, # Note: TF compatibility
|
||||||
"selectionPattern": "foobar",
|
"selectionPattern": "foobar",
|
||||||
"statusCode": "200",
|
"statusCode": "200",
|
||||||
|
"responseParameters": {
|
||||||
|
"method.response.header.Location": "integration.response.body.redirect.url",
|
||||||
|
"method.response.header.x-user-id": "integration.response.header.x-userid",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -1052,6 +1068,10 @@ def test_put_integration_response_with_response_template():
|
|||||||
httpMethod="GET",
|
httpMethod="GET",
|
||||||
statusCode="200",
|
statusCode="200",
|
||||||
selectionPattern="foobar",
|
selectionPattern="foobar",
|
||||||
|
responseParameters={
|
||||||
|
"method.response.header.Location": "integration.response.body.redirect.url",
|
||||||
|
"method.response.header.x-user-id": "integration.response.header.x-userid",
|
||||||
|
},
|
||||||
responseTemplates={"application/json": json.dumps({"data": "test"})},
|
responseTemplates={"application/json": json.dumps({"data": "test"})},
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -1068,6 +1088,10 @@ def test_put_integration_response_with_response_template():
|
|||||||
"selectionPattern": "foobar",
|
"selectionPattern": "foobar",
|
||||||
"ResponseMetadata": {"HTTPStatusCode": 200},
|
"ResponseMetadata": {"HTTPStatusCode": 200},
|
||||||
"responseTemplates": {"application/json": json.dumps({"data": "test"})},
|
"responseTemplates": {"application/json": json.dumps({"data": "test"})},
|
||||||
|
"responseParameters": {
|
||||||
|
"method.response.header.Location": "integration.response.body.redirect.url",
|
||||||
|
"method.response.header.x-user-id": "integration.response.header.x-userid",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user