generated from NHSDigital/nhs-notify-repository-template
-
Notifications
You must be signed in to change notification settings - Fork 0
CCM-14199 - Foundational: Infrastructure as Code and Core Types #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mjewildnhs
wants to merge
25
commits into
main
Choose a base branch
from
feature/CCM-14199-foundation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
fd5a645
First pass implementation
mjewildnhs 84ae5d5
Update lambda placeholder IAM policy name
mjewildnhs 8f8f6af
Use shared module for s3 config
mjewildnhs 924357d
Fix sonar scanner props
mjewildnhs 11c6c81
Placeholder tests to test coverage
mjewildnhs 4e27d7a
Fix lambda jest config
mjewildnhs a1fa079
Better name for config bucket
mjewildnhs ff16952
Update with data-model changes
mjewildnhs ded5a05
Update event names/terminology and remove nhsnumber, routingplan fiel…
mjewildnhs 7f340cc
Refactor model type structure
mjewildnhs 152ef89
Remove unncessary sonar exclusions
mjewildnhs 7ca4971
update teamResponsible enum
mjewildnhs 40f54e9
Update event schema based on guidance from meeting
mjewildnhs ac0273c
fixup! Update event schema based on guidance from meeting
mjewildnhs 71ee52f
fixup! Update event schema based on guidance from meeting
mjewildnhs 05f25eb
Apply suggestion from @mjewildnhs - model import consistency
mjewildnhs d37a8a2
added explicit pull-requeest read permission for pipeline
cgitim 505aa40
CCM-14203 - Fix for transitive dependency CVE
rhyscoxnhs 63925b5
Update supplier status enum values to match core rather than Open API…
mjewildnhs c551b6d
Update message status enum values to match core rather than Open API …
mjewildnhs 2f8761b
Update channel status enum values to match core rather than Open API …
mjewildnhs a683053
Revert "added explicit pull-requeest read permission for pipeline"
mjewildnhs e3df8d4
Force minimatch to patched versions - remove react lint
mjewildnhs 1f6e4f3
Revert "CCM-14203 - Fix for transitive dependency CVE"
mjewildnhs b6e377d
Update trivyignore to indicate minimatch CVE now false positive for 3…
mjewildnhs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # Add CVE IDs to ignore specific vulnerabilities. | ||
| # Keep justification inline after the CVE for auditability. | ||
| # Syntax: one entry per line, comments allowed. | ||
|
|
||
| # Examples: | ||
| # CVE-2025-0001 # Unexploitable in AWS Lambda base per vendor advisory | ||
| # CVE-2024-12345 # False positive: not present in runtime layer | ||
| # CVE-2024-12345 # https://avd.aquasec.com/nvd/cve-2024-12345 - package-name - < 2.0.1 - justification | ||
|
|
||
| ########################### | ||
| # Package Vulnerabilities # | ||
| ########################### | ||
|
|
||
| # All CVEs below are tracked for remediation under the following Jira ticket: | ||
| # https://nhsd-jira.digital.nhs.uk/browse/CCM-14687 | ||
| # EXAMPLE: | ||
| # CVE-2024-12345 # https://avd.aquasec.com/nvd/cve-2024-12345 - package-name - < 2.0.1 - justification | ||
| CVE-2026-26996 # https://avd.aquasec.com/nvd/cve-2026-26996 - minimatch - <10.2.1 - False positive as the fix has been backported to 3.1.3 (see https://github.com/isaacs/minimatch/security/advisories/GHSA-3ppc-4f35-3m26). This is a dev dependency used in the build process, not present in the runtime layer, and therefore not exploitable in production. We will update to a non-vulnerable versions for our transitive dependencies when available. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
infrastructure/terraform/components/callbacks/s3_bucket_client_config.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| ## | ||
| # S3 Bucket for Client Subscription Configuration | ||
| # | ||
| # Storage location for client subscription configurations loaded by Transform & Filter Lambda. | ||
| # Files are named {clientId}.json and contain ClientSubscriptionConfiguration arrays. | ||
| ## | ||
|
|
||
| module "client_config_bucket" { | ||
| source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.28/terraform-s3bucket.zip" | ||
|
|
||
| name = "subscription-config" | ||
|
|
||
| aws_account_id = var.aws_account_id | ||
| component = var.component | ||
| environment = var.environment | ||
| project = var.project | ||
| region = var.region | ||
|
|
||
| default_tags = merge( | ||
| local.default_tags, | ||
| { | ||
| Description = "Client subscription configuration storage" | ||
| } | ||
| ) | ||
|
|
||
| kms_key_arn = module.kms.key_arn | ||
| force_destroy = false | ||
| versioning = true | ||
| object_ownership = "BucketOwnerPreferred" | ||
| bucket_key_enabled = true | ||
|
|
||
| policy_documents = [ | ||
| data.aws_iam_policy_document.client_config_bucket.json | ||
| ] | ||
| } | ||
|
|
||
| ## | ||
| # S3 Bucket Policy | ||
| # | ||
| # Allows Transform & Filter Lambda to read configuration files | ||
| ## | ||
|
|
||
| data "aws_iam_policy_document" "client_config_bucket" { | ||
| statement { | ||
| sid = "AllowLambdaReadAccess" | ||
| effect = "Allow" | ||
|
|
||
| principals { | ||
| type = "AWS" | ||
| identifiers = [module.client_transform_filter_lambda.iam_role_arn] | ||
| } | ||
|
|
||
| actions = [ | ||
| "s3:GetObject", | ||
| ] | ||
|
|
||
| resources = [ | ||
| "${module.client_config_bucket.arn}/*", | ||
| ] | ||
| } | ||
|
|
||
| statement { | ||
| sid = "DenyInsecureTransport" | ||
| effect = "Deny" | ||
|
|
||
| principals { | ||
| type = "*" | ||
| identifiers = ["*"] | ||
| } | ||
|
|
||
| actions = [ | ||
| "s3:*", | ||
| ] | ||
|
|
||
| resources = [ | ||
| module.client_config_bucket.arn, | ||
| "${module.client_config_bucket.arn}/*" | ||
| ] | ||
|
|
||
| condition { | ||
| test = "Bool" | ||
| variable = "aws:SecureTransport" | ||
| values = ["false"] | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
lambdas/client-transform-filter-lambda/src/__tests__/models/status-transition-event.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import { EventTypes } from "models/status-transition-event"; | ||
|
|
||
| // coverage purposes | ||
| describe("EventTypes", () => { | ||
| it("should match the expected event type values", () => { | ||
| expect(EventTypes).toEqual({ | ||
| MESSAGE_STATUS_TRANSITIONED: | ||
| "uk.nhs.notify.client-callbacks.message.status.transitioned.v1", | ||
| CHANNEL_STATUS_TRANSITIONED: | ||
| "uk.nhs.notify.client-callbacks.channel.status.transitioned.v1", | ||
| }); | ||
| }); | ||
| }); | ||
23 changes: 23 additions & 0 deletions
23
lambdas/client-transform-filter-lambda/src/models/channel-status-data.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| /** | ||
| * Channel-level status transition event data. | ||
| */ | ||
| import type { Channel } from "models/channel-types"; | ||
| import type { ChannelStatus, SupplierStatus } from "models/status-types"; | ||
|
|
||
| export interface ChannelStatusData { | ||
| messageId: string; | ||
| messageReference: string; | ||
| channel: Channel; | ||
| channelStatus: ChannelStatus; | ||
| channelStatusDescription?: string; | ||
| channelFailureReasonCode?: string; | ||
| supplierStatus: SupplierStatus; | ||
| cascadeType: "primary" | "secondary"; | ||
| cascadeOrder: number; | ||
| timestamp: string; | ||
| retryCount: number; | ||
|
|
||
| clientId: string; | ||
| previousChannelStatus?: ChannelStatus; | ||
| previousSupplierStatus?: SupplierStatus; | ||
| } |
4 changes: 4 additions & 0 deletions
4
lambdas/client-transform-filter-lambda/src/models/channel-types.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| /** | ||
| * Communication channel types | ||
| */ | ||
| export type Channel = "NHSAPP" | "EMAIL" | "SMS" | "LETTER"; |
59 changes: 59 additions & 0 deletions
59
lambdas/client-transform-filter-lambda/src/models/client-callback-payload.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /** | ||
| * Message/Channel Status Callback payload delivered to client webhooks. | ||
| */ | ||
|
|
||
| import type { RoutingPlan } from "models/routing-plan"; | ||
| import type { Channel } from "models/channel-types"; | ||
| import type { | ||
| ChannelStatus, | ||
| MessageStatus, | ||
| SupplierStatus, | ||
| } from "models/status-types"; | ||
|
|
||
| export type ClientChannel = Lowercase<Channel>; | ||
| export type ClientMessageStatus = Lowercase<MessageStatus>; | ||
| export type ClientChannelStatus = Lowercase<ChannelStatus>; | ||
| export type ClientSupplierStatus = SupplierStatus; // SupplierStatus values are already lowercase | ||
|
|
||
| export interface ClientCallbackPayload { | ||
| data: CallbackItem[]; | ||
| } | ||
|
|
||
| export interface CallbackItem { | ||
| type: "MessageStatus" | "ChannelStatus"; | ||
| attributes: MessageStatusAttributes | ChannelStatusAttributes; | ||
| links: { | ||
| message: string; | ||
| }; | ||
| meta: { | ||
| idempotencyKey: string; | ||
| }; | ||
| } | ||
|
|
||
| export interface MessageStatusAttributes { | ||
| messageId: string; | ||
| messageReference: string; | ||
| messageStatus: ClientMessageStatus; | ||
| messageStatusDescription?: string; | ||
| messageFailureReasonCode?: string; | ||
| channels: { | ||
| type: ClientChannel; | ||
| channelStatus: ClientChannelStatus; | ||
| }[]; | ||
| timestamp: string; | ||
| routingPlan: RoutingPlan; | ||
| } | ||
|
|
||
| export interface ChannelStatusAttributes { | ||
| messageId: string; | ||
| messageReference: string; | ||
| cascadeType: "primary" | "secondary"; | ||
| cascadeOrder: number; | ||
| channel: ClientChannel; | ||
| channelStatus: ClientChannelStatus; | ||
| channelStatusDescription?: string; | ||
| channelFailureReasonCode?: string; | ||
| supplierStatus: ClientSupplierStatus; | ||
| timestamp: string; | ||
| retryCount: number; | ||
| } |
49 changes: 49 additions & 0 deletions
49
lambdas/client-transform-filter-lambda/src/models/client-config.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /** | ||
| * Client callback subscription configuration. | ||
| * Array of subscription rules (one per event type/channel combination). | ||
| */ | ||
|
|
||
| export type ClientSubscriptionConfiguration = ( | ||
| | MessageStatusSubscriptionConfiguration | ||
| | ChannelStatusSubscriptionConfiguration | ||
| )[]; | ||
|
|
||
| interface SubscriptionConfigurationBase { | ||
| Name: string; | ||
| ClientId: string; | ||
| Description: string; | ||
| EventSource: string; | ||
| EventDetail: string; | ||
| Targets: { | ||
| Type: "API"; | ||
| TargetId: string; | ||
| Name: string; | ||
| InputTransformer: { | ||
| InputPaths: string; | ||
| InputHeaders: { | ||
| "x-hmac-sha256-signature": string; | ||
| }; | ||
| }; | ||
| InvocationEndpoint: string; | ||
| InvocationMethod: "POST"; | ||
| InvocationRateLimit: number; | ||
| APIKey: { | ||
| HeaderName: string; | ||
| HeaderValue: string; | ||
| }; | ||
| }[]; | ||
| } | ||
|
|
||
| export interface MessageStatusSubscriptionConfiguration | ||
| extends SubscriptionConfigurationBase { | ||
| SubscriptionType: "MessageStatus"; | ||
| Statuses: string[]; | ||
| } | ||
|
|
||
| export interface ChannelStatusSubscriptionConfiguration | ||
| extends SubscriptionConfigurationBase { | ||
| SubscriptionType: "ChannelStatus"; | ||
| ChannelType: string; | ||
| ChannelStatuses: string[]; | ||
| SupplierStatuses: string[]; | ||
| } |
23 changes: 23 additions & 0 deletions
23
lambdas/client-transform-filter-lambda/src/models/message-status-data.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| /** | ||
| * Message-level status transition event data. | ||
| */ | ||
| import type { RoutingPlan } from "models/routing-plan"; | ||
| import type { Channel } from "models/channel-types"; | ||
| import type { MessageStatus } from "models/status-types"; | ||
|
|
||
| export interface MessageStatusData { | ||
| messageId: string; | ||
| messageReference: string; | ||
| messageStatus: MessageStatus; | ||
| messageStatusDescription?: string; | ||
| messageFailureReasonCode?: string; | ||
| channels: { | ||
| type: Channel; | ||
| channelStatus: string; | ||
| }[]; | ||
| timestamp: string; | ||
| routingPlan: RoutingPlan; | ||
|
|
||
| clientId: string; | ||
| previousMessageStatus?: MessageStatus; | ||
| } |
6 changes: 6 additions & 0 deletions
6
lambdas/client-transform-filter-lambda/src/models/routing-plan.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| export interface RoutingPlan { | ||
| id: string; | ||
| name: string; | ||
| version: string; | ||
| createdDate: string; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a useful test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No hence the "// coverage purposes" but sonar will fail coverage otherwise and i don't want to start adding exclusions