Skip to content
Merged
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
b201b05
CCM-11163: get routing config endpoint
harrim91 Sep 16, 2025
b5635cf
CCM-11163: regenerate types from autofixed api spec
harrim91 Sep 16, 2025
4c94c17
CCM-11163: fix tests
harrim91 Sep 17, 2025
d345def
Merge branch 'main' into feature/CCM-11163_routing-config-api-get-end…
harrim91 Sep 17, 2025
52f6eb6
CCM-11163: update lockfile
harrim91 Sep 17, 2025
66cd8b8
CCM-11163: fix ref in tests
harrim91 Sep 17, 2025
53c4781
CCM-11163: add full schema
harrim91 Sep 18, 2025
860038a
CCM-11163: simplify spec
harrim91 Sep 18, 2025
e9c9182
Merge branch 'main' into feature/CCM-11163_routing-config-api-get-end…
harrim91 Sep 19, 2025
15b61e2
CCM-11163: self review
harrim91 Sep 19, 2025
d3ef89c
CCM-11163: lock file
harrim91 Sep 19, 2025
000759b
CCM-11163: type fix
harrim91 Sep 19, 2025
1c645e5
Merge branch 'main' into feature/CCM-11163_routing-config-api-get-end…
harrim91 Sep 25, 2025
b39bd2a
CCM-11163: update readme
harrim91 Sep 25, 2025
2bce3ec
init
alexnuttall Sep 29, 2025
d9b5f8c
typechecks
alexnuttall Sep 30, 2025
6406441
curl cmd
alexnuttall Oct 1, 2025
1c1b87f
first unit tests
alexnuttall Oct 1, 2025
ef28478
Merge remote-tracking branch 'origin/main' into feature/CCM-11164-rc-…
alexnuttall Oct 1, 2025
e7117d9
fix tf lambda mod
alexnuttall Oct 1, 2025
4cfd90e
fix tf lambda modgss
alexnuttall Oct 1, 2025
df6915f
post merge fixes
alexnuttall Oct 1, 2025
b4323b8
tfdocs
alexnuttall Oct 1, 2025
0f6b861
adding repo tests
alexnuttall Oct 1, 2025
9947110
CCM-12222: list routing configs api endpoint
harrim91 Oct 1, 2025
51942d4
CCM-12222: self-review
harrim91 Oct 1, 2025
5ef2a02
CCM-12222: self-review
harrim91 Oct 1, 2025
3f603c0
CCM-12222: regenerate types
harrim91 Oct 1, 2025
040a681
CCM-12222: snapshot
harrim91 Oct 1, 2025
0cdb47d
client test
alexnuttall Oct 1, 2025
75bfbb9
CCM-12222: bump coverage
harrim91 Oct 1, 2025
69f78e9
unused import
alexnuttall Oct 1, 2025
0011c11
schema coverage
alexnuttall Oct 1, 2025
43bd731
pw
alexnuttall Oct 1, 2025
49545bd
merge list
alexnuttall Oct 1, 2025
367c0eb
tidy
alexnuttall Oct 1, 2025
a472e0e
fix some api tests (list)
alexnuttall Oct 2, 2025
730da2d
fix delete seeded rcs
alexnuttall Oct 2, 2025
5f7f425
rc factory tidy
alexnuttall Oct 2, 2025
fb74c39
fix post merge
alexnuttall Oct 2, 2025
9288f3a
package lock
alexnuttall Oct 2, 2025
ce04628
split createRc and rc types
alexnuttall Oct 2, 2025
d643f09
newline
alexnuttall Oct 2, 2025
dae5869
dedupe type
alexnuttall Oct 2, 2025
03b2520
remove 'client' logging
alexnuttall Oct 2, 2025
a9b0004
zod parse entire rc before creation
alexnuttall Oct 2, 2025
61996c9
split rc validator completely to match types
alexnuttall Oct 2, 2025
e99c25e
fix readme cmd
alexnuttall Oct 2, 2025
f77f9fd
rm unnecessary return
alexnuttall Oct 2, 2025
28cc522
merge count
alexnuttall Oct 3, 2025
f6bd62b
unit test fix
alexnuttall Oct 3, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions infrastructure/terraform/modules/backend-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ No requirements.
| Name | Source | Version |
|------|--------|---------|
| <a name="module_authorizer_lambda"></a> [authorizer\_lambda](#module\_authorizer\_lambda) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.22/terraform-lambda.zip | n/a |
| <a name="module_create_routing_config_lambda"></a> [create\_routing\_config\_lambda](#module\_create\_routing\_config\_lambda) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.22/terraform-lambda.zip | n/a |
| <a name="module_create_template_lambda"></a> [create\_template\_lambda](#module\_create\_template\_lambda) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.22/terraform-lambda.zip | n/a |
| <a name="module_delete_template_lambda"></a> [delete\_template\_lambda](#module\_delete\_template\_lambda) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.22/terraform-lambda.zip | n/a |
| <a name="module_get_client_lambda"></a> [get\_client\_lambda](#module\_get\_client\_lambda) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.22/terraform-lambda.zip | n/a |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ data "aws_iam_policy_document" "api_gateway_execution_policy" {
module.authorizer_lambda.function_arn,
module.upload_letter_template_lambda.function_arn,
module.create_template_lambda.function_arn,
module.create_routing_config_lambda.function_arn,
module.delete_template_lambda.function_arn,
module.get_client_lambda.function_arn,
module.get_routing_config_lambda.function_arn,
Expand Down
29 changes: 15 additions & 14 deletions infrastructure/terraform/modules/backend-api/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,21 @@ locals {
client_ssm_path_pattern = "arn:aws:ssm:${var.region}:${var.aws_account_id}:parameter${local.client_ssm_path_prefix}/*"

openapi_spec = templatefile("${path.module}/spec.tmpl.json", {
APIG_EXECUTION_ROLE_ARN = aws_iam_role.api_gateway_execution_role.arn
AUTHORIZER_LAMBDA_ARN = module.authorizer_lambda.function_arn
AWS_REGION = var.region
CREATE_LAMBDA_ARN = module.create_template_lambda.function_arn
DELETE_LAMBDA_ARN = module.delete_template_lambda.function_arn
GET_CLIENT_LAMBDA_ARN = module.get_client_lambda.function_arn
GET_LAMBDA_ARN = module.get_template_lambda.function_arn
GET_ROUTING_CONFIG_LAMBDA_ARN = module.get_routing_config_lambda.function_arn
LIST_LAMBDA_ARN = module.list_template_lambda.function_arn
LIST_ROUTING_CONFIGS_LAMBDA_ARN = module.list_routing_configs_lambda.function_arn
REQUEST_PROOF_LAMBDA_ARN = module.request_proof_lambda.function_arn
SUBMIT_LAMBDA_ARN = module.submit_template_lambda.function_arn
UPDATE_LAMBDA_ARN = module.update_template_lambda.function_arn
UPLOAD_LETTER_LAMBDA_ARN = module.upload_letter_template_lambda.function_arn
APIG_EXECUTION_ROLE_ARN = aws_iam_role.api_gateway_execution_role.arn
AUTHORIZER_LAMBDA_ARN = module.authorizer_lambda.function_arn
AWS_REGION = var.region
CREATE_LAMBDA_ARN = module.create_template_lambda.function_arn
CREATE_ROUTING_CONFIG_LAMBDA_ARN = module.create_routing_config_lambda.function_arn
DELETE_LAMBDA_ARN = module.delete_template_lambda.function_arn
GET_CLIENT_LAMBDA_ARN = module.get_client_lambda.function_arn
GET_LAMBDA_ARN = module.get_template_lambda.function_arn
GET_ROUTING_CONFIG_LAMBDA_ARN = module.get_routing_config_lambda.function_arn
LIST_LAMBDA_ARN = module.list_template_lambda.function_arn
LIST_ROUTING_CONFIGS_LAMBDA_ARN = module.list_routing_configs_lambda.function_arn
REQUEST_PROOF_LAMBDA_ARN = module.request_proof_lambda.function_arn
SUBMIT_LAMBDA_ARN = module.submit_template_lambda.function_arn
UPDATE_LAMBDA_ARN = module.update_template_lambda.function_arn
UPLOAD_LETTER_LAMBDA_ARN = module.upload_letter_template_lambda.function_arn
})

backend_lambda_environment_variables = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
module "create_routing_config_lambda" {
source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.22/terraform-lambda.zip"

project = var.project
environment = var.environment
component = var.component
aws_account_id = var.aws_account_id
region = var.region

kms_key_arn = var.kms_key_arn

function_name = "create-routing-config"

function_module_name = "create-routing-config"
handler_function_name = "handler"
description = "Create Routing Config API endpoint"

memory = 512
timeout = 3
runtime = "nodejs20.x"

log_retention_in_days = var.log_retention_in_days

iam_policy_document = {
body = data.aws_iam_policy_document.create_routing_config_lambda_policy.json
}

lambda_env_vars = local.backend_lambda_environment_variables
function_s3_bucket = var.function_s3_bucket
function_code_base_path = local.lambdas_dir
function_code_dir = "backend-api/dist/create-routing-config"

send_to_firehose = var.send_to_firehose
log_destination_arn = var.log_destination_arn
log_subscription_role_arn = var.log_subscription_role_arn
}

data "aws_iam_policy_document" "create_routing_config_lambda_policy" {
statement {
sid = "AllowDynamoAccess"
effect = "Allow"

actions = [
"dynamodb:PutItem",
]

resources = [
aws_dynamodb_table.routing_configuration.arn,
]
}

statement {
sid = "AllowKMSAccess"
effect = "Allow"

actions = [
"kms:Decrypt",
"kms:DescribeKey",
"kms:Encrypt",
"kms:GenerateDataKey*",
"kms:ReEncrypt*",
]

resources = [
var.kms_key_arn
]
}
}
111 changes: 96 additions & 15 deletions infrastructure/terraform/modules/backend-api/spec.tmpl.json
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@
"ClientConfiguration": {
"properties": {
"campaignId": {
"deprecared": true,
"deprecated": true,
"type": "string"
},
"campaignIds": {
Expand Down Expand Up @@ -376,6 +376,35 @@
],
"type": "object"
},
"CreateUpdateRoutingConfig": {
"properties": {
"campaignId": {
"type": "string"
},
"cascade": {
"items": {
"$ref": "#/components/schemas/CascadeItem"
},
"type": "array"
},
"cascadeGroupOverrides": {
"items": {
"$ref": "#/components/schemas/CascadeGroup"
},
"type": "array"
},
"name": {
"type": "string"
}
},
"required": [
"campaignId",
"cascadeGroupOverrides",
"cascade",
"name"
],
"type": "object"
},
"CreateUpdateTemplate": {
"allOf": [
{
Expand Down Expand Up @@ -594,28 +623,19 @@
"format": "date-time",
"type": "string"
},
"createdBy": {
"type": "string"
},
"id": {
"format": "uuid",
"type": "string"
},
"name": {
"type": "string"
},
"owner": {
"type": "string"
},
"status": {
"$ref": "#/components/schemas/RoutingConfigStatus"
},
"updatedAt": {
"format": "date-time",
"type": "string"
},
"updatedBy": {
"type": "string"
}
},
"required": [
Expand All @@ -624,14 +644,10 @@
"cascade",
"clientId",
"createdAt",
"createdBy",
"displayCategory",
"id",
"name",
"owner",
"status",
"updatedAt",
"updatedBy"
"updatedAt"
],
"type": "object"
},
Expand Down Expand Up @@ -988,6 +1004,71 @@
}
}
},
"/v1/routing-configuration": {
"post": {
"description": "Create a routing configuration",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/CreateUpdateRoutingConfig"
}
}
},
"description": "Routing configuration to create",
"required": true
},
"responses": {
"201": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/RoutingConfigSuccess"
}
}
},
"description": "201 response",
"headers": {
"Content-Type": {
"schema": {
"type": "string"
}
}
}
},
"default": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Failure"
}
}
},
"description": "Error"
}
},
"security": [
{
"authorizer": []
}
],
"summary": "Create a routing configuration by ID",
"x-amazon-apigateway-integration": {
"contentHandling": "CONVERT_TO_TEXT",
"credentials": "${APIG_EXECUTION_ROLE_ARN}",
"httpMethod": "POST",
"passthroughBehavior": "WHEN_NO_TEMPLATES",
"responses": {
".*": {
"statusCode": "200"
}
},
"timeoutInMillis": 29000,
"type": "AWS_PROXY",
"uri": "arn:aws:apigateway:${AWS_REGION}:lambda:path/2015-03-31/functions/${CREATE_ROUTING_CONFIG_LAMBDA_ARN}/invocations"
}
}
},
"/v1/routing-configuration/{routingConfigId}": {
"get": {
"description": "Get a routing configuration by ID",
Expand Down
29 changes: 21 additions & 8 deletions lambdas/backend-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,10 @@ Setup an authenticated AWS terminal and run
./scripts/sandbox_auth.sh <email> <password>
```

Grab the `AccessToken` from `sandbox_cognito_auth_token.json`
Grab the `AccessToken` and `api_base_url` from `sandbox_cognito_auth_token.json`

```bash
SANDBOX_TOKEN=$(jq -r .AccessToken sandbox_cognito_auth_token.json)
```

Set APIG stage. The following extracts the value from `sandbox_tf_outputs.tf`. Values resemble `https://cc5p8d4l3b.execute-api.eu-west-2.amazonaws.com/main`

```bash
APIG_STAGE=$(jq -r .api_base_url.value ./sandbox_tf_outputs.json)
SANDBOX_TOKEN=$(jq -r .AccessToken sandbox_cognito_auth_token.json) && APIG_STAGE=$(jq -r .api_base_url.value ./sandbox_tf_outputs.json)
```

### GET - /v1/template/:templateId - Get a single template by id
Expand Down Expand Up @@ -157,3 +151,22 @@ curl --location "${APIG_STAGE}/v1/routing-configurations \
--header 'Accept: application/json' \
--header "Authorization: $SANDBOX_TOKEN"
```

### POST - /v1/routing-configuration - Create a routing configuration

```bash
curl -X POST --location "${APIG_STAGE}/v1/routing-configuration" \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header "Authorization: $SANDBOX_TOKEN" \
--data '{
"campaignId": "campaign",
"cascade": [{
"cascadeGroups": ["standard"],
"channel": "EMAIL",
"channelType": "primary",
"defaultTemplateId": "email_id"
}],
"cascadeGroupOverrides": [{ "name": "standard" }],
"name": "RC name"
}'
1 change: 1 addition & 0 deletions lambdas/backend-api/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ npx esbuild \
src/templates/copy-scanned-object-to-internal.ts \
src/templates/upload-letter.ts \
src/templates/create.ts \
src/templates/create-routing-config.ts \
src/templates/delete-failed-scanned-object.ts \
src/templates/delete.ts \
src/templates/get-client.ts \
Expand Down
Loading