Skip to content

Commit cd7f36b

Browse files
stevebuxnhsd-david-wassmasl2timireland
authored
Authoriser lambda (#230)
* add product id header * CCM-11600: supplier repository and table * CCM-11600: cli interface for supplier repo * CCM-11600: lock for new packages * Update .gitleaksignore added gitleaks ignore * CCM-11600: fix some imports * Add certificate expiry check * Added supplier ID lookup * Test fix * Further development * Fix dependencies * Temp commit to force cloudwatch logging * Removed Cloudwatch client * Tidy up packages * CCM-11600: correct target attr * CCM-11600: header name, targets, add alarm * CCM-11600: correct env ref * CCM-11600: fix header lookup * lockfile * remove placeholder blurb * fix copy pasta * workspace refs * lock * CCM-11600: header references, format, name consistency --------- Co-authored-by: David Wass <[email protected]> Co-authored-by: Mark Slowey <[email protected]> Co-authored-by: Mark Slowey <[email protected]> Co-authored-by: Tim Ireland <[email protected]>
1 parent cd57610 commit cd7f36b

Some content is hidden

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

55 files changed

+17300
-18013
lines changed

.github/actions/build-docs/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ runs:
1111
uses: actions/checkout@v4
1212
- uses: actions/setup-node@v4
1313
with:
14-
node-version: 18
14+
node-version: 22
1515
- name: Npm cli install
1616
working-directory: .
1717
run: npm ci

.github/actions/build-libraries/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ runs:
1111
uses: actions/checkout@v4
1212
- uses: actions/setup-node@v4
1313
with:
14-
node-version: 24
14+
node-version: 22
1515

1616
- name: Npm install
1717
working-directory: .

.github/actions/build-sandbox/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ runs:
1212
uses: actions/checkout@v4
1313
- uses: actions/setup-node@v4
1414
with:
15-
node-version: 24
15+
node-version: 22
1616

1717
- name: Npm install
1818
working-directory: .

.github/actions/build-sdk/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ runs:
1111
uses: actions/checkout@v4
1212
- uses: actions/setup-node@v4
1313
with:
14-
node-version: 18
14+
node-version: 22
1515

1616
- name: Npm install
1717
working-directory: .

.github/actions/build-server/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ runs:
1111
uses: actions/checkout@v4
1212
- uses: actions/setup-node@v4
1313
with:
14-
node-version: 24
14+
node-version: 22
1515

1616
- name: Npm install
1717
working-directory: .

.github/workflows/manual-proxy-environment-deploy.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232

3333
- uses: actions/setup-node@v6
3434
with:
35-
node-version: 24
35+
node-version: 22
3636

3737
- name: Npm install
3838
working-directory: .
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
resource "aws_cloudwatch_metric_alarm" "alm-apim-client-certificate-near-expiry" {
2+
alarm_name = "${local.csi}-alm-apim-client-certificate-near-expiry"
3+
alarm_description = "RELIABILITY: An APIM client certificate is due to expire soon"
4+
5+
metric_name = "apim-client-certificate-near-expiry"
6+
namespace = "comms-apim-authorizer"
7+
8+
dimensions = {
9+
Environment = var.environment
10+
}
11+
12+
period = 60 * 60 * 4 //4 hours
13+
comparison_operator = "GreaterThanThreshold"
14+
threshold = "0"
15+
evaluation_periods = "1"
16+
statistic = "Sum"
17+
treat_missing_data = "notBreaching"
18+
19+
actions_enabled = "false"
20+
alarm_actions = []
21+
ok_actions = []
22+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
resource "aws_dynamodb_table" "suppliers" {
2+
name = "${local.csi}-suppliers"
3+
billing_mode = "PAY_PER_REQUEST"
4+
5+
hash_key = "id"
6+
range_key = "apimId"
7+
8+
ttl {
9+
attribute_name = "ttl"
10+
enabled = false
11+
}
12+
13+
global_secondary_index {
14+
name = "supplier-apim-index"
15+
hash_key = "apimId"
16+
projection_type = "ALL"
17+
}
18+
19+
attribute {
20+
name = "id"
21+
type = "S"
22+
}
23+
24+
attribute {
25+
name = "apimId"
26+
type = "S"
27+
}
28+
29+
point_in_time_recovery {
30+
enabled = true
31+
}
32+
33+
tags = var.default_tags
34+
}

infrastructure/terraform/components/api/module_authorizer_lambda.tf

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ module "authorizer_lambda" {
1111
log_retention_in_days = var.log_retention_in_days
1212
kms_key_arn = module.kms.key_arn
1313

14+
iam_policy_document = {
15+
body = data.aws_iam_policy_document.authorizer_lambda.json
16+
}
17+
1418
function_name = "authorizer"
1519
description = "Authorizer for Suppliers API"
1620

@@ -30,4 +34,40 @@ module "authorizer_lambda" {
3034
send_to_firehose = true
3135
log_destination_arn = local.destination_arn
3236
log_subscription_role_arn = local.acct.log_subscription_role_arn
37+
38+
lambda_env_vars = {
39+
CLOUDWATCH_NAMESPACE = "/aws/api-gateway/supplier/alarms",
40+
CLIENT_CERTIFICATE_EXPIRATION_ALERT_DAYS = 14,
41+
APIM_SUPPLIER_ID_HEADER = "NHSD-Supplier-ID",
42+
SUPPLIERS_TABLE_NAME = aws_dynamodb_table.suppliers.name
43+
}
44+
}
45+
46+
data "aws_iam_policy_document" "authorizer_lambda" {
47+
statement {
48+
sid = "AllowPutMetricData"
49+
effect = "Allow"
50+
51+
actions = [
52+
"cloudwatch:PutMetricData"
53+
]
54+
55+
resources = [
56+
"*"
57+
]
58+
}
59+
60+
statement {
61+
sid = "AllowDynamoDBAccess"
62+
effect = "Allow"
63+
64+
actions = [
65+
"dynamodb:Query"
66+
]
67+
68+
resources = [
69+
aws_dynamodb_table.suppliers.arn,
70+
"${aws_dynamodb_table.suppliers.arn}/index/supplier-apim-index"
71+
]
72+
}
3373
}

internal/datastore/src/__test__/db.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export async function setupDynamoDBContainer() {
3131
endpoint,
3232
lettersTableName: 'letters',
3333
miTableName: 'management-info',
34+
suppliersTableName: 'suppliers',
3435
lettersTtlHours: 1,
3536
miTtlHours: 1
3637
};
@@ -94,6 +95,29 @@ const createMITableCommand = new CreateTableCommand({
9495
]
9596
});
9697

98+
const createSupplierTableCommand = new CreateTableCommand({
99+
TableName: 'suppliers',
100+
BillingMode: 'PAY_PER_REQUEST',
101+
KeySchema: [
102+
{ AttributeName: 'id', KeyType: 'HASH' } // Partition key
103+
],
104+
GlobalSecondaryIndexes: [
105+
{
106+
IndexName: 'supplier-apim-index',
107+
KeySchema: [
108+
{ AttributeName: 'apimId', KeyType: 'HASH' } // Partition key for GSI
109+
],
110+
Projection: {
111+
ProjectionType: 'ALL'
112+
}
113+
}
114+
],
115+
AttributeDefinitions: [
116+
{ AttributeName: 'id', AttributeType: 'S' },
117+
{ AttributeName: 'apimId', AttributeType: 'S' }
118+
]
119+
});
120+
97121

98122
export async function createTables(context: DBContext) {
99123
const { ddbClient } = context;
@@ -102,6 +126,7 @@ export async function createTables(context: DBContext) {
102126
await ddbClient.send(updateTimeToLiveCommand);
103127

104128
await ddbClient.send(createMITableCommand);
129+
await ddbClient.send(createSupplierTableCommand);
105130
}
106131

107132

@@ -115,4 +140,8 @@ export async function deleteTables(context: DBContext) {
115140
await ddbClient.send(new DeleteTableCommand({
116141
TableName: 'management-info'
117142
}));
143+
144+
await ddbClient.send(new DeleteTableCommand({
145+
TableName: 'suppliers'
146+
}));
118147
}

0 commit comments

Comments
 (0)