in syndicate/core/transform/terraform/converter/tf_api_gateway_converter.py [0:0]
def convert(self, name, resource):
validate_params(name, resource, API_REQUIRED_PARAMS)
api_name = name
rest_api_template = generate_tf_template_for_api_gateway(
api_name=api_name)
self.template.add_aws_api_gateway_rest_api(meta=rest_api_template)
auth_mappings = self._transform_authorizers(resource=resource,
api_name=api_name)
method_names = []
integration_names = []
resources = resource.get('resources')
for res_name, res in resources.items():
api_gateway_resource, resource_name = self._create_api_gateway_resource(
path_part=res_name, api_name=api_name)
for http_method in API_GATEWAY_SUPPORTED_METHODS:
method_meta = res.get(http_method)
if method_meta:
tf_method_resource_name = build_terraform_resource_name(
resource_name, http_method)
method_names.append(tf_method_resource_name)
self.create_request_validator(method_meta=method_meta,
api_name=api_name,
resource_name=resource_name,
http_method=http_method)
authorizer_id = None
authorization_type = method_meta.get('authorization_type')
if authorization_type not in ['NONE', 'AWS_IAM']:
authorizer_id = auth_mappings.get(
authorization_type)
if not authorizer_id:
raise AssertionError(
'Authorizer {0} does not exist'.format(
authorization_type))
authorization_type = 'CUSTOM'
method_request_parameters = method_meta.get(
'method_request_parameters')
method_template = get_api_gateway_method(
http_method=http_method,
resource_name=resource_name,
rest_api=api_name,
authorization=authorization_type,
method_name=tf_method_resource_name,
request_parameters=method_request_parameters,
authorizer_id=authorizer_id)
self.template.add_aws_api_gateway_method(
meta=method_template)
integration_type = method_meta.get('integration_type')
integration_name = build_terraform_resource_name(
resource_name, http_method)
integration_names.append(integration_name)
if integration_type:
if integration_type == 'lambda':
self._create_lambda_integration(
method_meta=method_meta,
method_name=tf_method_resource_name,
api_name=api_name,
integration_name=integration_name,
resource_name=resource_name)
elif integration_type == 'service':
self._create_service_integration(
resource_name=resource_name,
method_meta=method_meta,
method_name=tf_method_resource_name,
api_name=api_name,
integration_name=integration_name)
elif integration_type == 'mock':
self._create_mock_integration(
method_meta=method_meta,
resource_name=resource_name, api_name=api_name,
integration_name=integration_name,
method_name=tf_method_resource_name)
elif integration_type == 'http':
self._create_http_integration(
method_meta=method_meta,
method_name=tf_method_resource_name,
integration_name=integration_name,
resource_name=resource_name,
api_name=api_name)
responses = method_meta.get('responses')
for response in responses:
status_code = response.get('status_code')
method_response = api_gateway_method_response(
resource_name=resource_name,
status_code=status_code,
api_name=api_name,
http_method=http_method,
method_name=tf_method_resource_name)
self.template.add_aws_api_gateway_method_response(
meta=method_response)
integration_responses = method_meta.get(
'integration_responses')
for int_response in integration_responses:
status_code = int_response.get('status_code')
response_templates = int_response.get(
'response_templates')
error_regex = int_response.get('error_regex')
integration_response = create_api_gateway_integration_response(
resource_name=resource_name,
api_name=api_name,
status_code=status_code,
response_template=response_templates,
http_method=http_method,
method_name=tf_method_resource_name,
integration=integration_name,
selection_pattern=error_regex)
self.template.add_aws_api_gateway_integration_response(
meta=integration_response)
self._create_api_gateway_deployment(resource=resource,
api_name=api_name,
method_names=method_names,
integration_names=integration_names)