Skip to content

Commit

Permalink
Merge pull request #3623 from ministryofjustice/add-get-schema-endpoint
Browse files Browse the repository at this point in the history
Add get-schema endpoint
  • Loading branch information
tom-webber authored Oct 17, 2023
2 parents 2f338ab + 1b1b466 commit a8300d3
Show file tree
Hide file tree
Showing 6 changed files with 193 additions and 186 deletions.
57 changes: 47 additions & 10 deletions terraform/environments/data-platform/api.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,21 @@ resource "aws_api_gateway_deployment" "deployment" {
aws_api_gateway_resource.data_product_table,
aws_api_gateway_resource.data_product_table_name,
aws_api_gateway_resource.upload_data_for_data_product_table_name,
aws_api_gateway_resource.create_schema_for_data_product_table_name,
aws_api_gateway_resource.schema_for_data_product_table_name,
aws_api_gateway_method.docs,
aws_api_gateway_method.get_glue_metadata,
aws_api_gateway_method.register_data_product,
aws_api_gateway_method.upload_data_for_data_product_table_name,
aws_api_gateway_method.create_schema_for_data_product_table_name,
aws_api_gateway_method.get_schema_for_data_product_table_name,
aws_api_gateway_integration.docs_to_lambda,
aws_api_gateway_integration.upload_data_for_data_product_table_name_to_lambda,
aws_api_gateway_integration.proxy_to_lambda,
aws_api_gateway_integration.docs_lambda_root,
aws_api_gateway_integration.get_glue_metadata,
aws_api_gateway_integration.register_data_product_to_lambda,
aws_api_gateway_integration.create_schema_for_data_product_table_name_to_lambda,
aws_api_gateway_integration.get_schema_for_data_product_table_name_to_lambda,
]))
}

Expand Down Expand Up @@ -123,6 +125,18 @@ resource "aws_api_gateway_resource" "upload_data_for_data_product_table_name" {
rest_api_id = aws_api_gateway_rest_api.data_platform.id
}

# /data-product/{data-product-name}/table/{table-name}/schema resource
resource "aws_api_gateway_resource" "schema_for_data_product_table_name" {
parent_id = aws_api_gateway_resource.data_product_table_name.id
path_part = "schema"
rest_api_id = aws_api_gateway_rest_api.data_platform.id
}

moved {
from = aws_api_gateway_resource.create_schema_for_data_product_table_name
to = aws_api_gateway_resource.schema_for_data_product_table_name
}

# /data-product/{data-product-name}/table/{table-name}/upload POST method
resource "aws_api_gateway_method" "upload_data_for_data_product_table_name" {
authorization = "CUSTOM"
Expand Down Expand Up @@ -153,19 +167,12 @@ resource "aws_api_gateway_integration" "upload_data_for_data_product_table_name_
}
}

# /data-product/{data-product-name}/table/{table-name}/schema resource
resource "aws_api_gateway_resource" "create_schema_for_data_product_table_name" {
parent_id = aws_api_gateway_resource.data_product_table_name.id
path_part = "schema"
rest_api_id = aws_api_gateway_rest_api.data_platform.id
}

# /data-product/{data-product-name}/table/{table-name}/schema POST method
resource "aws_api_gateway_method" "create_schema_for_data_product_table_name" {
authorization = "CUSTOM"
authorizer_id = aws_api_gateway_authorizer.authorizer.id
http_method = "POST"
resource_id = aws_api_gateway_resource.create_schema_for_data_product_table_name.id
resource_id = aws_api_gateway_resource.schema_for_data_product_table_name.id
rest_api_id = aws_api_gateway_rest_api.data_platform.id

request_parameters = {
Expand All @@ -178,7 +185,7 @@ resource "aws_api_gateway_method" "create_schema_for_data_product_table_name" {
# /data-product/{data-product-name}/table/{table-name}/schema lambda integration
resource "aws_api_gateway_integration" "create_schema_for_data_product_table_name_to_lambda" {
http_method = aws_api_gateway_method.create_schema_for_data_product_table_name.http_method
resource_id = aws_api_gateway_resource.create_schema_for_data_product_table_name.id
resource_id = aws_api_gateway_resource.schema_for_data_product_table_name.id
rest_api_id = aws_api_gateway_rest_api.data_platform.id
integration_http_method = "POST"
type = "AWS_PROXY"
Expand All @@ -190,6 +197,36 @@ resource "aws_api_gateway_integration" "create_schema_for_data_product_table_nam
}
}

# /data-product/{data-product-name}/table/{table-name}/schema GET method
resource "aws_api_gateway_method" "get_schema_for_data_product_table_name" {
authorization = "CUSTOM"
authorizer_id = aws_api_gateway_authorizer.authorizer.id
http_method = "GET"
resource_id = aws_api_gateway_resource.schema_for_data_product_table_name.id
rest_api_id = aws_api_gateway_rest_api.data_platform.id

request_parameters = {
"method.request.header.Authorization" = true,
"method.request.path.data-product-name" = true,
"method.request.path.table-name" = true,
}
}

# /data-product/{data-product-name}/table/{table-name}/schema lambda integration
resource "aws_api_gateway_integration" "get_schema_for_data_product_table_name_to_lambda" {
http_method = aws_api_gateway_method.get_schema_for_data_product_table_name.http_method
resource_id = aws_api_gateway_resource.schema_for_data_product_table_name.id
rest_api_id = aws_api_gateway_rest_api.data_platform.id
integration_http_method = "POST"
type = "AWS_PROXY"
uri = module.get_schema_lambda.lambda_function_invoke_arn

request_parameters = {
"integration.request.path.data-product-name" = "method.request.path.data-product-name",
"integration.request.path.table-name" = "method.request.path.table-name",
}
}

# API docs endpoint

resource "aws_api_gateway_resource" "docs" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,11 @@
"test": "1.0.0",
"preproduction": "1.0.0",
"production": "1.0.0"
},
"get_schema_versions": {
"development": "1.0.0",
"test": "1.0.0",
"preproduction": "1.0.0",
"production": "1.0.0"
}
}
Loading

0 comments on commit a8300d3

Please sign in to comment.