Skip to content

Commit 10a71b6

Browse files
CCM-11164: create RC (#709)
Co-authored-by: Michael Harrison <[email protected]>
1 parent b11469a commit 10a71b6

34 files changed

+1330
-308
lines changed

infrastructure/terraform/modules/backend-api/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ No requirements.
3939
|------|--------|---------|
4040
| <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 |
4141
| <a name="module_count_routing_configs_lambda"></a> [count\_routing\_configs\_lambda](#module\_count\_routing\_configs\_lambda) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.22/terraform-lambda.zip | n/a |
42+
| <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 |
4243
| <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 |
4344
| <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 |
4445
| <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 |

infrastructure/terraform/modules/backend-api/iam_role_api_gateway_execution_role.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ data "aws_iam_policy_document" "api_gateway_execution_policy" {
5252
module.upload_letter_template_lambda.function_arn,
5353
module.count_routing_configs_lambda.function_arn,
5454
module.create_template_lambda.function_arn,
55+
module.create_routing_config_lambda.function_arn,
5556
module.delete_template_lambda.function_arn,
5657
module.get_client_lambda.function_arn,
5758
module.get_routing_config_lambda.function_arn,

infrastructure/terraform/modules/backend-api/locals.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ locals {
1616
AWS_REGION = var.region
1717
COUNT_ROUTING_CONFIGS_LAMBDA_ARN = module.count_routing_configs_lambda.function_arn
1818
CREATE_LAMBDA_ARN = module.create_template_lambda.function_arn
19+
CREATE_ROUTING_CONFIG_LAMBDA_ARN = module.create_routing_config_lambda.function_arn
1920
DELETE_LAMBDA_ARN = module.delete_template_lambda.function_arn
2021
GET_CLIENT_LAMBDA_ARN = module.get_client_lambda.function_arn
2122
GET_LAMBDA_ARN = module.get_template_lambda.function_arn
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
module "create_routing_config_lambda" {
2+
source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.22/terraform-lambda.zip"
3+
4+
project = var.project
5+
environment = var.environment
6+
component = var.component
7+
aws_account_id = var.aws_account_id
8+
region = var.region
9+
10+
kms_key_arn = var.kms_key_arn
11+
12+
function_name = "create-routing-config"
13+
14+
function_module_name = "create-routing-config"
15+
handler_function_name = "handler"
16+
description = "Create Routing Config API endpoint"
17+
18+
memory = 512
19+
timeout = 3
20+
runtime = "nodejs20.x"
21+
22+
log_retention_in_days = var.log_retention_in_days
23+
24+
iam_policy_document = {
25+
body = data.aws_iam_policy_document.create_routing_config_lambda_policy.json
26+
}
27+
28+
lambda_env_vars = local.backend_lambda_environment_variables
29+
function_s3_bucket = var.function_s3_bucket
30+
function_code_base_path = local.lambdas_dir
31+
function_code_dir = "backend-api/dist/create-routing-config"
32+
33+
send_to_firehose = var.send_to_firehose
34+
log_destination_arn = var.log_destination_arn
35+
log_subscription_role_arn = var.log_subscription_role_arn
36+
}
37+
38+
data "aws_iam_policy_document" "create_routing_config_lambda_policy" {
39+
statement {
40+
sid = "AllowDynamoAccess"
41+
effect = "Allow"
42+
43+
actions = [
44+
"dynamodb:PutItem",
45+
]
46+
47+
resources = [
48+
aws_dynamodb_table.routing_configuration.arn,
49+
]
50+
}
51+
52+
statement {
53+
sid = "AllowKMSAccess"
54+
effect = "Allow"
55+
56+
actions = [
57+
"kms:Decrypt",
58+
"kms:DescribeKey",
59+
"kms:Encrypt",
60+
"kms:GenerateDataKey*",
61+
"kms:ReEncrypt*",
62+
]
63+
64+
resources = [
65+
var.kms_key_arn
66+
]
67+
}
68+
}

infrastructure/terraform/modules/backend-api/spec.tmpl.json

Lines changed: 96 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@
297297
"ClientConfiguration": {
298298
"properties": {
299299
"campaignId": {
300-
"deprecared": true,
300+
"deprecated": true,
301301
"type": "string"
302302
},
303303
"campaignIds": {
@@ -399,6 +399,35 @@
399399
],
400400
"type": "object"
401401
},
402+
"CreateUpdateRoutingConfig": {
403+
"properties": {
404+
"campaignId": {
405+
"type": "string"
406+
},
407+
"cascade": {
408+
"items": {
409+
"$ref": "#/components/schemas/CascadeItem"
410+
},
411+
"type": "array"
412+
},
413+
"cascadeGroupOverrides": {
414+
"items": {
415+
"$ref": "#/components/schemas/CascadeGroup"
416+
},
417+
"type": "array"
418+
},
419+
"name": {
420+
"type": "string"
421+
}
422+
},
423+
"required": [
424+
"campaignId",
425+
"cascadeGroupOverrides",
426+
"cascade",
427+
"name"
428+
],
429+
"type": "object"
430+
},
402431
"CreateUpdateTemplate": {
403432
"allOf": [
404433
{
@@ -617,28 +646,19 @@
617646
"format": "date-time",
618647
"type": "string"
619648
},
620-
"createdBy": {
621-
"type": "string"
622-
},
623649
"id": {
624650
"format": "uuid",
625651
"type": "string"
626652
},
627653
"name": {
628654
"type": "string"
629655
},
630-
"owner": {
631-
"type": "string"
632-
},
633656
"status": {
634657
"$ref": "#/components/schemas/RoutingConfigStatus"
635658
},
636659
"updatedAt": {
637660
"format": "date-time",
638661
"type": "string"
639-
},
640-
"updatedBy": {
641-
"type": "string"
642662
}
643663
},
644664
"required": [
@@ -647,14 +667,10 @@
647667
"cascade",
648668
"clientId",
649669
"createdAt",
650-
"createdBy",
651-
"displayCategory",
652670
"id",
653671
"name",
654-
"owner",
655672
"status",
656-
"updatedAt",
657-
"updatedBy"
673+
"updatedAt"
658674
],
659675
"type": "object"
660676
},
@@ -1011,6 +1027,71 @@
10111027
}
10121028
}
10131029
},
1030+
"/v1/routing-configuration": {
1031+
"post": {
1032+
"description": "Create a routing configuration",
1033+
"requestBody": {
1034+
"content": {
1035+
"application/json": {
1036+
"schema": {
1037+
"$ref": "#/components/schemas/CreateUpdateRoutingConfig"
1038+
}
1039+
}
1040+
},
1041+
"description": "Routing configuration to create",
1042+
"required": true
1043+
},
1044+
"responses": {
1045+
"201": {
1046+
"content": {
1047+
"application/json": {
1048+
"schema": {
1049+
"$ref": "#/components/schemas/RoutingConfigSuccess"
1050+
}
1051+
}
1052+
},
1053+
"description": "201 response",
1054+
"headers": {
1055+
"Content-Type": {
1056+
"schema": {
1057+
"type": "string"
1058+
}
1059+
}
1060+
}
1061+
},
1062+
"default": {
1063+
"content": {
1064+
"application/json": {
1065+
"schema": {
1066+
"$ref": "#/components/schemas/Failure"
1067+
}
1068+
}
1069+
},
1070+
"description": "Error"
1071+
}
1072+
},
1073+
"security": [
1074+
{
1075+
"authorizer": []
1076+
}
1077+
],
1078+
"summary": "Create a routing configuration by ID",
1079+
"x-amazon-apigateway-integration": {
1080+
"contentHandling": "CONVERT_TO_TEXT",
1081+
"credentials": "${APIG_EXECUTION_ROLE_ARN}",
1082+
"httpMethod": "POST",
1083+
"passthroughBehavior": "WHEN_NO_TEMPLATES",
1084+
"responses": {
1085+
".*": {
1086+
"statusCode": "200"
1087+
}
1088+
},
1089+
"timeoutInMillis": 29000,
1090+
"type": "AWS_PROXY",
1091+
"uri": "arn:aws:apigateway:${AWS_REGION}:lambda:path/2015-03-31/functions/${CREATE_ROUTING_CONFIG_LAMBDA_ARN}/invocations"
1092+
}
1093+
}
1094+
},
10141095
"/v1/routing-configuration/{routingConfigId}": {
10151096
"get": {
10161097
"description": "Get a routing configuration by ID",

lambdas/backend-api/README.md

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,10 @@ Setup an authenticated AWS terminal and run
1616
./scripts/sandbox_auth.sh <email> <password>
1717
```
1818

19-
Grab the `AccessToken` from `sandbox_cognito_auth_token.json`
19+
Grab the `AccessToken` and `api_base_url` from `sandbox_cognito_auth_token.json`
2020

2121
```bash
22-
SANDBOX_TOKEN=$(jq -r .AccessToken sandbox_cognito_auth_token.json)
23-
```
24-
25-
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`
26-
27-
```bash
28-
APIG_STAGE=$(jq -r .api_base_url.value ./sandbox_tf_outputs.json)
22+
SANDBOX_TOKEN=$(jq -r .AccessToken sandbox_cognito_auth_token.json) && APIG_STAGE=$(jq -r .api_base_url.value ./sandbox_tf_outputs.json)
2923
```
3024

3125
### GET - /v1/template/:templateId - Get a single template by id
@@ -153,7 +147,26 @@ curl --location "${APIG_STAGE}/v1/routing-configuration/${ROUTING_CONFIG_ID}" \
153147
### GET - /v1/routing-configurations - List routing configurations
154148
155149
```bash
156-
curl --location "${APIG_STAGE}/v1/routing-configurations \
150+
curl --location "${APIG_STAGE}/v1/routing-configurations" \
157151
--header 'Accept: application/json' \
158152
--header "Authorization: $SANDBOX_TOKEN"
159153
```
154+
155+
### POST - /v1/routing-configuration - Create a routing configuration
156+
157+
```bash
158+
curl -X POST --location "${APIG_STAGE}/v1/routing-configuration" \
159+
--header 'Content-Type: application/json' \
160+
--header 'Accept: application/json' \
161+
--header "Authorization: $SANDBOX_TOKEN" \
162+
--data '{
163+
"campaignId": "campaign",
164+
"cascade": [{
165+
"cascadeGroups": ["standard"],
166+
"channel": "EMAIL",
167+
"channelType": "primary",
168+
"defaultTemplateId": "email_id"
169+
}],
170+
"cascadeGroupOverrides": [{ "name": "standard" }],
171+
"name": "RC name"
172+
}'

lambdas/backend-api/build.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ npx esbuild \
1616
--external:pdfjs-dist \
1717
src/templates/copy-scanned-object-to-internal.ts \
1818
src/templates/count-routing-configs.ts \
19+
src/templates/create-routing-config.ts \
1920
src/templates/create.ts \
20-
src/templates/delete.ts \
2121
src/templates/delete-failed-scanned-object.ts \
22-
src/templates/get.ts \
22+
src/templates/delete.ts \
2323
src/templates/get-client.ts \
2424
src/templates/get-routing-config.ts \
25-
src/templates/list.ts \
25+
src/templates/get.ts \
2626
src/templates/list-routing-configs.ts \
27+
src/templates/list.ts \
2728
src/templates/process-proof.ts \
2829
src/templates/proof.ts \
2930
src/templates/set-letter-upload-virus-scan-status.ts \

lambdas/backend-api/src/__tests__/templates/api/count-routing-configs.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ describe('CountRoutingConfigs handler', () => {
8181
});
8282

8383
expect(mocks.routingConfigClient.countRoutingConfigs).toHaveBeenCalledWith(
84-
'nhs-notify-client-id',
84+
{ userId: 'sub', clientId: 'nhs-notify-client-id' },
8585
{ status: 'DRAFT' }
8686
);
8787
});
@@ -110,7 +110,7 @@ describe('CountRoutingConfigs handler', () => {
110110
});
111111

112112
expect(mocks.routingConfigClient.countRoutingConfigs).toHaveBeenCalledWith(
113-
'nhs-notify-client-id',
113+
{ userId: 'sub', clientId: 'nhs-notify-client-id' },
114114
{ status: 'COMPLETED' }
115115
);
116116
});

0 commit comments

Comments
 (0)