Skip to content

Commit 049b668

Browse files
authored
Merge pull request #197 from NHSDigital/feature/CCM-7525_template-api
CCM-7525: Add template API
2 parents f1abf95 + 249f007 commit 049b668

File tree

98 files changed

+8818
-878
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+8818
-878
lines changed

.eslintignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
public
22
jest.config.ts
33
jest.setup.ts
4+
lambdas/backend-client/src/types/generated
5+
**/*/coverage/*
6+
.build
7+
node_modules
48
dist

.eslintrc.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@
7373
"unicorn/no-null": "off",
7474
"prefer-regex-literals": "off",
7575
"class-methods-use-this": "off",
76-
"no-underscore-dangle": "off"
76+
"no-underscore-dangle": "off",
77+
"no-empty-constructor": "off",
78+
"no-empty-function": "off"
7779
},
7880
"overrides": [
7981
{

.github/workflows/stage-2-test.yaml

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,24 @@ permissions:
4141
contents: read # This is required for actions/checkout
4242

4343
jobs:
44+
check-generated-dependencies:
45+
name: "Check generated dependencies"
46+
runs-on: ubuntu-latest
47+
timeout-minutes: 5
48+
steps:
49+
- name: "Checkout code"
50+
uses: actions/checkout@v4
51+
- name: "Repo setup"
52+
run: |
53+
npm ci
54+
(cd amplify && npm ci)
55+
(cd lambdas/authorizer && npm ci)
56+
(cd lambdas/backend-client && npm ci)
57+
(cd lambdas/backend-api && npm ci)
58+
- name: "Generate dependencies"
59+
run: |
60+
npm run generate-dependencies
61+
git diff --exit-code
4462
test-unit:
4563
name: "Unit tests"
4664
runs-on: ubuntu-latest
@@ -51,8 +69,10 @@ jobs:
5169
- name: "Repo setup"
5270
run: |
5371
npm ci
72+
(cd amplify && npm ci)
5473
(cd lambdas/authorizer && npm ci)
55-
(cd lambdas/endpoint && npm ci)
74+
(cd lambdas/backend-client && npm ci)
75+
(cd lambdas/backend-api && npm ci)
5676
- name: "Generate dependencies"
5777
run: |
5878
npm run generate-dependencies
@@ -82,8 +102,10 @@ jobs:
82102
run: |
83103
npm ci
84104
npm ci tests/test-team
105+
(cd amplify && npm ci)
85106
(cd lambdas/authorizer && npm ci)
86-
(cd lambdas/endpoint && npm ci)
107+
(cd lambdas/backend-client && npm ci)
108+
(cd lambdas/backend-api && npm ci)
87109
- name: "Generate dependencies"
88110
run: |
89111
npm run generate-dependencies
@@ -101,8 +123,10 @@ jobs:
101123
run: |
102124
npm ci
103125
npm ci tests/test-team
126+
(cd amplify && npm ci)
104127
(cd lambdas/authorizer && npm ci)
105-
(cd lambdas/endpoint && npm ci)
128+
(cd lambdas/backend-client && npm ci)
129+
(cd lambdas/backend-api && npm ci)
106130
- name: "Generate dependencies"
107131
run: |
108132
npm run generate-dependencies

.github/workflows/stage-4-acceptance.yaml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ jobs:
5151
- name: "Repo setup"
5252
run: |
5353
npm ci
54+
npm ci tests/test-team
55+
(cd amplify && npm ci)
56+
(cd lambdas/authorizer && npm ci)
57+
(cd lambdas/backend-client && npm ci)
58+
(cd lambdas/backend-api && npm ci)
5459
- name: "Generate dependencies"
5560
run: |
5661
npm run generate-dependencies
@@ -122,8 +127,11 @@ jobs:
122127
- name: "Repo setup"
123128
run: |
124129
npm ci
130+
npm ci tests/test-team
131+
(cd amplify && npm ci)
125132
(cd lambdas/authorizer && npm ci)
126-
(cd lambdas/endpoint && npm ci)
133+
(cd lambdas/backend-client && npm ci)
134+
(cd lambdas/backend-api && npm ci)
127135
- name: "Generate dependencies"
128136
run: |
129137
npm run generate-dependencies
@@ -156,8 +164,10 @@ jobs:
156164
run: |
157165
npm ci
158166
npm ci tests/test-team
167+
(cd amplify && npm ci)
159168
(cd lambdas/authorizer && npm ci)
160-
(cd lambdas/endpoint && npm ci)
169+
(cd lambdas/backend-client && npm ci)
170+
(cd lambdas/backend-api && npm ci)
161171
- name: "Generate dependencies"
162172
run: |
163173
npm run generate-dependencies
@@ -193,6 +203,11 @@ jobs:
193203
- name: "Repo setup"
194204
run: |
195205
npm ci
206+
npm ci tests/test-team
207+
(cd amplify && npm ci)
208+
(cd lambdas/authorizer && npm ci)
209+
(cd lambdas/backend-client && npm ci)
210+
(cd lambdas/backend-api && npm ci)
196211
- name: "Generate dependencies"
197212
run: |
198213
npm run generate-dependencies

amplify.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ backend:
66
- nvm install 20.13.1
77
- nvm use 20.13.1
88
- npm ci --cache .npm --prefer-offline
9+
- (cd lambdas/authorizer && npm ci)
10+
- (cd lambdas/endpoint && npm ci)
911
- npm run generate-dependencies
1012
- npx ampx pipeline-deploy --branch $AWS_BRANCH --app-id $AWS_APP_ID
1113
frontend:

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,12 @@ data "aws_iam_policy_document" "api_gateway_execution_policy" {
4040
]
4141

4242
resources = [
43-
module.email_lambda.function_arn,
44-
module.authorizer_lambda.function_arn
43+
module.authorizer_lambda.function_arn,
44+
module.create_template_lambda.function_arn,
45+
module.update_template_lambda.function_arn,
46+
module.get_template_lambda.function_arn,
47+
module.list_template_lambda.function_arn,
48+
module.email_lambda.function_arn
4549
]
4650
}
4751
}

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@ locals {
77
AWS_REGION = var.region
88
APIG_EXECUTION_ROLE_ARN = aws_iam_role.api_gateway_execution_role.arn
99
AUTHORIZER_LAMBDA_ARN = module.authorizer_lambda.function_arn
10-
EMAIL_LAMBDA_ARN = module.email_lambda.function_arn
10+
CREATE_LAMBDA_ARN = module.create_template_lambda.function_arn
11+
UPDATE_LAMBDA_ARN = module.update_template_lambda.function_arn
12+
GET_LAMBDA_ARN = module.get_template_lambda.function_arn
13+
LIST_LAMBDA_ARN = module.list_template_lambda.function_arn
14+
EMAIL_LAMBDA_ARN = module.email_lambda.function_arn
1115
})
16+
17+
backend_lambda_entrypoints = {
18+
create_template = "src/templates/api/create.ts"
19+
get_template = "src/templates/api/get.ts"
20+
update_template = "src/templates/api/update.ts"
21+
list_template = "src/templates/api/list.ts"
22+
send_email = "src/email/handler.ts"
23+
template_client = "src/index.ts"
24+
}
1225
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module "build_template_lambda" {
2+
source = "../typescript-build-zip"
3+
4+
source_code_dir = "${local.lambdas_source_code_dir}/backend-api"
5+
entrypoints = [
6+
local.backend_lambda_entrypoints.create_template,
7+
local.backend_lambda_entrypoints.get_template,
8+
local.backend_lambda_entrypoints.update_template,
9+
local.backend_lambda_entrypoints.list_template,
10+
local.backend_lambda_entrypoints.send_email,
11+
]
12+
}
13+
14+
module "build_template_client" {
15+
source = "../typescript-build-zip"
16+
17+
source_code_dir = "${local.lambdas_source_code_dir}/backend-client"
18+
entrypoints = [local.backend_lambda_entrypoints.template_client]
19+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
module "create_template_lambda" {
2+
depends_on = [module.build_template_lambda, module.build_template_client]
3+
4+
source = "../lambda-function"
5+
description = "Create template API endpoint"
6+
7+
function_name = "${local.csi}-create-template"
8+
filename = module.build_template_lambda.zips[local.backend_lambda_entrypoints.create_template].path
9+
source_code_hash = module.build_template_lambda.zips[local.backend_lambda_entrypoints.create_template].base64sha256
10+
runtime = "nodejs20.x"
11+
handler = "create.handler"
12+
13+
log_retention_in_days = var.log_retention_in_days
14+
15+
environment_variables = {
16+
TEMPLATES_TABLE_NAME = aws_dynamodb_table.templates.name
17+
}
18+
19+
execution_role_policy_document = data.aws_iam_policy_document.create_template_lambda_policy.json
20+
}
21+
22+
data "aws_iam_policy_document" "create_template_lambda_policy" {
23+
statement {
24+
sid = "AllowDynamoAccess"
25+
effect = "Allow"
26+
27+
actions = [
28+
"dynamodb:PutItem",
29+
]
30+
31+
resources = [
32+
aws_dynamodb_table.templates.arn,
33+
]
34+
}
35+
36+
statement {
37+
sid = "AllowKMSAccess"
38+
effect = "Allow"
39+
40+
actions = [
41+
"kms:Decrypt",
42+
"kms:DescribeKey",
43+
"kms:Encrypt",
44+
"kms:GenerateDataKey*",
45+
"kms:ReEncrypt*",
46+
]
47+
48+
resources = [
49+
aws_kms_key.dynamo.arn
50+
]
51+
}
52+
}

infrastructure/terraform/modules/templates-api/module_email_lambda.tf

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
module "email_lambda" {
2+
depends_on = [module.build_template_lambda, module.build_template_client]
3+
24
source = "../lambda-function"
3-
description = "templates api endpoint"
5+
description = "Send an email to the recipient"
46

57
function_name = "${local.csi}-email"
6-
filename = module.endpoint_build.zips[local.endpoint_entrypoint].path
7-
source_code_hash = module.endpoint_build.zips[local.endpoint_entrypoint].base64sha256
8+
filename = module.build_template_lambda.zips[local.backend_lambda_entrypoints.send_email].path
9+
source_code_hash = module.build_template_lambda.zips[local.backend_lambda_entrypoints.send_email].base64sha256
810
runtime = "nodejs20.x"
9-
handler = "index.emailHandler"
11+
handler = "handler.emailHandler"
1012

1113
log_retention_in_days = var.log_retention_in_days
1214

0 commit comments

Comments
 (0)