Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
2 changes: 1 addition & 1 deletion .github/scripts/dispatch_internal_repo_workflow.sh
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ if [[ -z "$extraSecretNames" ]]; then
extraSecretNames=""
fi

if [{ -z "$tableName" }]; then
if [[ -z "$tableName" ]]; then
tableName=""
fi

Expand Down
2 changes: 2 additions & 0 deletions infrastructure/terraform/components/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ No requirements.
| <a name="module_sqs_alarms"></a> [sqs\_alarms](#module\_sqs\_alarms) | ../../modules/alarms-sqs | n/a |
| <a name="module_sqs_letter_updates"></a> [sqs\_letter\_updates](#module\_sqs\_letter\_updates) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.1.5/terraform-sqs.zip | n/a |
| <a name="module_sqs_supplier_allocator"></a> [sqs\_supplier\_allocator](#module\_sqs\_supplier\_allocator) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.1.5/terraform-sqs.zip | n/a |
| <a name="module_sqs_supplier_config"></a> [sqs\_supplier\_config](#module\_sqs\_supplier\_config) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.6/terraform-sqs.zip | n/a |
| <a name="module_supplier_allocator"></a> [supplier\_allocator](#module\_supplier\_allocator) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.29/terraform-lambda.zip | n/a |
| <a name="module_supplier_config_ingress"></a> [supplier\_config\_ingress](#module\_supplier\_config\_ingress) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.29/terraform-lambda.zip | n/a |
| <a name="module_supplier_ssl"></a> [supplier\_ssl](#module\_supplier\_ssl) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.26/terraform-ssl.zip | n/a |
| <a name="module_update_letter_queue"></a> [update\_letter\_queue](#module\_update\_letter\_queue) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.29/terraform-lambda.zip | n/a |
| <a name="module_upsert_letter"></a> [upsert\_letter](#module\_upsert\_letter) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.29/terraform-lambda.zip | n/a |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
resource "aws_lambda_event_source_mapping" "supplier_config_ingress" {
event_source_arn = module.sqs_supplier_config.sqs_queue_arn
function_name = module.supplier_config_ingress.function_name
batch_size = 10
maximum_batching_window_in_seconds = 5
function_response_types = [
"ReportBatchItemFailures"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@

Comment thread
masl2 marked this conversation as resolved.
Outdated








Comment thread
stevebux marked this conversation as resolved.
Outdated
module "supplier_config_ingress" {
source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.29/terraform-lambda.zip"

function_name = "supplier-config-ingress"
description = "Persist supplier config changes"

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

log_retention_in_days = var.log_retention_in_days
kms_key_arn = module.kms.key_arn

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

function_s3_bucket = local.acct.s3_buckets["lambda_function_artefacts"]["id"]
function_code_base_path = local.aws_lambda_functions_dir_path
function_code_dir = "supplier-config-ingress/dist"
function_include_common = true
handler_function_name = "supplierConfigHandler"
runtime = "nodejs22.x"
memory = 512
timeout = 29
log_level = var.log_level

force_lambda_code_deploy = var.force_lambda_code_deploy
enable_lambda_insights = false

log_destination_arn = local.destination_arn
log_subscription_role_arn = local.acct.log_subscription_role_arn

lambda_env_vars = merge(local.common_lambda_env_vars, {})
}
Comment thread
stevebux marked this conversation as resolved.

data "aws_iam_policy_document" "supplier_config_ingress_lambda" {
statement {
sid = "KMSPermissions"
effect = "Allow"

actions = [
"kms:Decrypt",
"kms:GenerateDataKey",
]

resources = [
module.kms.key_arn,
]
}

statement {
sid = "AllowSQSRead"
effect = "Allow"

actions = [
"sqs:ReceiveMessage",
"sqs:DeleteMessage",
"sqs:GetQueueAttributes"
]

resources = [
module.sqs_supplier_config.sqs_queue_arn
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
module "sqs_supplier_config" {
source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/3.0.6/terraform-sqs.zip"
Comment thread
masl2 marked this conversation as resolved.
Outdated

aws_account_id = var.aws_account_id
component = var.component
environment = var.environment
project = var.project
region = var.region
name = "supplier-config"

sqs_kms_key_arn = module.kms.key_arn

visibility_timeout_seconds = 60

create_dlq = true
sqs_policy_overload = data.aws_iam_policy_document.supplier_config_queue_policy.json
}
Comment thread
masl2 marked this conversation as resolved.

data "aws_iam_policy_document" "supplier_config_queue_policy" {
version = "2012-10-17"

statement {
sid = "AllowSNSPermissions"
effect = "Allow"

principals {
type = "Service"
identifiers = ["sns.amazonaws.com"]
}

actions = [
"sqs:SendMessage",
"sqs:ListQueueTags",
"sqs:GetQueueUrl",
"sqs:GetQueueAttributes",
]

resources = [
"arn:aws:sqs:${var.region}:${var.aws_account_id}:${var.project}-${var.environment}-${var.component}-supplier-config-queue"
]

condition {
test = "ArnEquals"
variable = "aws:SourceArn"
values = [module.eventsub.sns_topic.arn]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
resource "aws_sns_topic_subscription" "eventsub_sqs_supplier_config" {
topic_arn = module.eventsub.sns_topic.arn
protocol = "sqs"
endpoint = module.sqs_supplier_config.sqs_queue_arn
raw_message_delivery = true

filter_policy_scope = "MessageBody"
filter_policy = jsonencode({
type = [{ prefix = "uk.nhs.notify.supplier-config" }]
})
}
4 changes: 4 additions & 0 deletions lambdas/supplier-config-ingress/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
coverage
node_modules
dist
.reports
55 changes: 55 additions & 0 deletions lambdas/supplier-config-ingress/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const baseJestConfig = {
preset: "ts-jest",
extensionsToTreatAsEsm: [".ts"],
transform: {
"^.+\\.ts$": [
"ts-jest",
{
useESM: true,
},
],
},

// Automatically clear mock calls, instances, contexts and results before every test
clearMocks: true,

// Indicates whether the coverage information should be collected while executing the test
collectCoverage: true,

// The directory where Jest should output its coverage files
coverageDirectory: "./.reports/unit/coverage",

// Indicates which provider should be used to instrument code for coverage
coverageProvider: "babel",

coverageThreshold: {
global: {
branches: 100,
functions: 100,
lines: 100,
statements: -10,
},
},

coveragePathIgnorePatterns: ["/__tests__/"],
testPathIgnorePatterns: [".build"],
testMatch: ["**/?(*.)+(spec|test).[jt]s?(x)"],

// Use this configuration option to add custom reporters to Jest
reporters: [
"default",
[
"jest-html-reporter",
{
pageTitle: "Test Report",
outputPath: "./.reports/unit/test-report.html",
includeFailureMsg: true,
},
],
],

// The test environment that will be used for testing
testEnvironment: "node",
};

export default baseJestConfig;
16 changes: 16 additions & 0 deletions lambdas/supplier-config-ingress/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"dependencies": {
"@types/aws-lambda": "^8.10.148",
"esbuild": "^0.27.2"
},
"name": "nhs-notify-supplier-api-supplier-config-ingress",
"private": true,
"scripts": {
"lambda-build": "rm -rf dist && npx esbuild --bundle --minify --sourcemap --target=es2020 --platform=node --loader:.node=file --entry-names=[name] --outdir=dist src/index.ts",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"test:unit": "jest",
"typecheck": "tsc --noEmit"
},
"version": "0.0.1"
}
12 changes: 12 additions & 0 deletions lambdas/supplier-config-ingress/src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { SQSEvent } from "aws-lambda";
import { supplierConfigHandler } from "..";

describe("supplierConfigHandler", () => {
it("returns an empty batchItemFailures list", async () => {
const event = { Records: [] } as unknown as SQSEvent;

const result = await supplierConfigHandler(event);

expect(result).toEqual({ batchItemFailures: [] });
});
});
9 changes: 9 additions & 0 deletions lambdas/supplier-config-ingress/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { SQSBatchResponse, SQSEvent } from "aws-lambda";

// eslint-disable-next-line import-x/prefer-default-export
export const supplierConfigHandler = async (
_event: SQSEvent,
): Promise<SQSBatchResponse> => {
// Implementation to be done under CCM-17379
return { batchItemFailures: [] };
};
13 changes: 13 additions & 0 deletions lambdas/supplier-config-ingress/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"types": [
"jest",
"node"
]
},
"extends": "../../tsconfig.base.json",
"include": [
"src/**/*",
"jest.config.ts"
]
}
12 changes: 12 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading