Skip to content

Commit f0cc665

Browse files
CCM-12185: Add new endpoint to get mi information (#522)
1 parent 9e46494 commit f0cc665

47 files changed

Lines changed: 1215 additions & 34 deletions

Some content is hidden

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

.env.template

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ TARGET_ENVIRONMENT=prxx
3636
export NON_PROD_API_KEY=xxx
3737
export NON_PROD_SECONDARY_API_KEY=xxx
3838
export INTEGRATION_API_KEY=xxx
39+
export INTEGRATION_SECONDARY_API_KEY=xxx
3940
export PRODUCTION_API_KEY=xxx
41+
export PRODUCTION_SECONDARY_API_KEY=xxx
4042

4143
# Status Endpoint API Key
4244
# In order to find the value of the status endpoint API key, follow these steps:

.github/actions/acceptance-tests-e2e/action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,12 @@ runs:
7878
if [[ -z "$PR_NUMBER" ]]; then
7979
export PROXY_NAME="${BASE_PROXY_NAME}"
8080
export NON_PROD_API_KEY="${DEV_E2E_KEYS_APIM_MAIN}"
81+
export NON_PROD_SECONDARY_API_KEY="${DEV_E2E_KEYS_APIM_MAIN_SECONDARY}"
8182
else
8283
export PROXY_NAME="${BASE_PROXY_NAME}-PR-${PR_NUMBER}"
8384
export NON_PROD_API_KEY="${DEV_E2E_KEYS_APIM_PR}"
85+
export NON_PROD_SECONDARY_API_KEY="${DEV_E2E_KEYS_APIM_PR_SECONDARY}"
86+
8487
fi
8588
8689
export STATUS_ENDPOINT_API_KEY="${DEV_E2E_KEYS_APIM_STATUS}"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,4 @@ jobs:
8181
--targetEnvironment "$ENVIRONMENT" \
8282
--targetAccountGroup "nhs-notify-supplier-api-dev" \
8383
--targetComponent "api" \
84-
--extraSecretNames '["/dev/e2e/keys/apim/main","/dev/e2e/keys/apim/pr","/dev/e2e/keys/apim/status","/dev/e2e/keys/private"]'
84+
--extraSecretNames '["/dev/e2e/keys/apim/main","/dev/e2e/keys/apim/pr","/dev/e2e/keys/apim/pr/secondary","/dev/e2e/keys/apim/status","/dev/e2e/keys/private"]'

infrastructure/terraform/components/api/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ No requirements.
7272
| <a name="module_get_letter"></a> [get\_letter](#module\_get\_letter) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/4.0.2/terraform-lambda.zip | n/a |
7373
| <a name="module_get_letter_data"></a> [get\_letter\_data](#module\_get\_letter\_data) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/4.0.2/terraform-lambda.zip | n/a |
7474
| <a name="module_get_letters"></a> [get\_letters](#module\_get\_letters) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/4.0.2/terraform-lambda.zip | n/a |
75+
| <a name="module_get_mi"></a> [get\_mi](#module\_get\_mi) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.29/terraform-lambda.zip | n/a |
7576
| <a name="module_get_status"></a> [get\_status](#module\_get\_status) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/4.0.2/terraform-lambda.zip | n/a |
7677
| <a name="module_kms"></a> [kms](#module\_kms) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.26/terraform-kms.zip | n/a |
7778
| <a name="module_lambda_alarms"></a> [lambda\_alarms](#module\_lambda\_alarms) | ../../modules/alarms-lambda | n/a |

infrastructure/terraform/components/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.get_letter.function_arn,
5353
module.get_letter_data.function_arn,
5454
module.get_letters.function_arn,
55+
module.get_mi.function_arn,
5556
module.patch_letter.function_arn,
5657
module.post_letters.function_arn,
5758
module.get_status.function_arn,

infrastructure/terraform/components/api/locals.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ locals {
1717
PATCH_LETTER_LAMBDA_ARN = module.patch_letter.function_arn
1818
POST_LETTERS_LAMBDA_ARN = module.post_letters.function_arn
1919
POST_MI_LAMBDA_ARN = module.post_mi.function_arn
20+
GET_MI_LAMBDA_ARN = module.get_mi.function_arn
2021
})
2122

2223
destination_arn = "arn:aws:logs:${var.region}:${var.shared_infra_account_id}:destination:nhs-main-obs-firehose-logs"

infrastructure/terraform/components/api/locals_alarms.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ locals {
1111
get_letter = module.get_letter.function_name
1212
get_letters = module.get_letters.function_name
1313
get_letter_data = module.get_letter_data.function_name
14+
get_mi = module.get_mi.function_name
1415
get_status = module.get_status.function_name
1516
patch_letter = module.patch_letter.function_name
1617
post_letters = module.post_letters.function_name
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
module "get_mi" {
2+
source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.29/terraform-lambda.zip"
3+
4+
function_name = "get_mi"
5+
description = "Retrieve management information"
6+
7+
aws_account_id = var.aws_account_id
8+
component = var.component
9+
environment = var.environment
10+
project = var.project
11+
region = var.region
12+
group = var.group
13+
14+
log_retention_in_days = var.log_retention_in_days
15+
kms_key_arn = module.kms.key_arn
16+
17+
iam_policy_document = {
18+
body = data.aws_iam_policy_document.get_mi_lambda.json
19+
}
20+
21+
function_s3_bucket = local.acct.s3_buckets["lambda_function_artefacts"]["id"]
22+
function_code_base_path = local.aws_lambda_functions_dir_path
23+
function_code_dir = "api-handler/dist"
24+
function_include_common = true
25+
handler_function_name = "getMI"
26+
runtime = "nodejs22.x"
27+
memory = 512
28+
timeout = 29
29+
log_level = var.log_level
30+
31+
force_lambda_code_deploy = var.force_lambda_code_deploy
32+
enable_lambda_insights = false
33+
34+
log_destination_arn = local.destination_arn
35+
log_subscription_role_arn = local.acct.log_subscription_role_arn
36+
37+
lambda_env_vars = merge(local.common_lambda_env_vars, {})
38+
}
39+
40+
data "aws_iam_policy_document" "get_mi_lambda" {
41+
statement {
42+
sid = "KMSPermissions"
43+
effect = "Allow"
44+
45+
actions = [
46+
"kms:Decrypt",
47+
"kms:GenerateDataKey",
48+
]
49+
50+
resources = [
51+
module.kms.key_arn, ## Requires shared kms module
52+
]
53+
}
54+
55+
statement {
56+
sid = "AllowDynamoDBAccess"
57+
effect = "Allow"
58+
59+
actions = [
60+
"dynamodb:GetItem",
61+
"dynamodb:Query"
62+
]
63+
64+
resources = [
65+
aws_dynamodb_table.mi.arn,
66+
]
67+
}
68+
}

infrastructure/terraform/components/api/resources/spec.tmpl.json

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,56 @@
306306
"uri": "arn:aws:apigateway:${AWS_REGION}:lambda:path/2015-03-31/functions/${POST_MI_LAMBDA_ARN}/invocations"
307307
}
308308
}
309+
},
310+
"/mi/{id}": {
311+
"get": {
312+
"description": "Returns 200 OK with management information.",
313+
"responses": {
314+
"200": {
315+
"description": "OK"
316+
},
317+
"400": {
318+
"description": "Bad request, invalid input data"
319+
},
320+
"404": {
321+
"description": "Resource not found"
322+
},
323+
"500": {
324+
"description": "Server error"
325+
}
326+
},
327+
"security": [
328+
{
329+
"LambdaAuthorizer": []
330+
}
331+
],
332+
"summary": "Get MI",
333+
"x-amazon-apigateway-integration": {
334+
"contentHandling": "CONVERT_TO_TEXT",
335+
"credentials": "${APIG_EXECUTION_ROLE_ARN}",
336+
"httpMethod": "POST",
337+
"passthroughBehavior": "WHEN_NO_TEMPLATES",
338+
"responses": {
339+
".*": {
340+
"statusCode": "200"
341+
}
342+
},
343+
"timeoutInMillis": 29000,
344+
"type": "AWS_PROXY",
345+
"uri": "arn:aws:apigateway:${AWS_REGION}:lambda:path/2015-03-31/functions/${GET_MI_LAMBDA_ARN}/invocations"
346+
}
347+
},
348+
"parameters": [
349+
{
350+
"description": "Unique identifier of this resource",
351+
"in": "path",
352+
"name": "id",
353+
"required": true,
354+
"schema": {
355+
"type": "string"
356+
}
357+
}
358+
]
309359
}
310360
},
311361
"x-amazon-apigateway-endpoint-access-mode": "${ENDPOINT_ACCESS_MODE}",

internal/datastore/src/__test__/mi-repository.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,44 @@ describe("MiRepository", () => {
6464
);
6565
});
6666
});
67+
68+
describe("getMi", () => {
69+
it("throws an error when fetching MI information that does not exist", async () => {
70+
await expect(miRepository.getMI("XXX", "supplier1")).rejects.toThrow(
71+
"Management information not found: supplierId=supplier1, miId=XXX",
72+
);
73+
});
74+
75+
it("creates MI with id and timestamps", async () => {
76+
jest.useFakeTimers();
77+
// Month is zero-indexed in JS Date
78+
jest.setSystemTime(new Date(2020, 1, 1));
79+
const mi = {
80+
specificationId: "spec1",
81+
supplierId: "supplier1",
82+
groupId: "group1",
83+
lineItem: "item1",
84+
quantity: 12,
85+
timestamp: new Date().toISOString(),
86+
stockRemaining: 0,
87+
};
88+
89+
const persistedMi = await miRepository.putMI(mi);
90+
91+
const fetchedMi = await miRepository.getMI(
92+
persistedMi.id,
93+
persistedMi.supplierId,
94+
);
95+
96+
expect(fetchedMi).toEqual(
97+
expect.objectContaining({
98+
id: expect.any(String),
99+
createdAt: "2020-02-01T00:00:00.000Z",
100+
updatedAt: "2020-02-01T00:00:00.000Z",
101+
ttl: 1_580_518_800, // 2020-02-01T00:01:00.000Z, seconds since epoch
102+
...mi,
103+
}),
104+
);
105+
});
106+
});
67107
});

0 commit comments

Comments
 (0)