Skip to content

Commit 3864536

Browse files
Merge remote-tracking branch 'origin/main' into feature/CCM-11228-db-schema
2 parents 49473c6 + fbf42cc commit 3864536

File tree

15 files changed

+469
-19
lines changed

15 files changed

+469
-19
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,16 @@ runs:
2525
run: |
2626
make publish-oas
2727
28-
- name: Setup Proxy Name
28+
- name: Setup Proxy Name and target
2929
shell: bash
3030
run: |
3131
3232
if [ -z $PR_NUMBER ]
3333
then
3434
echo "INSTANCE=$PROXYGEN_API_NAME" >> $GITHUB_ENV
35+
echo "TARGET=https://suppliers.dev.nhsnotify.national.nhs.uk" >> $GITHUB_ENV
3536
else
37+
echo "TARGET=https://pr$PR_NUMBER.suppliers.dev.nhsnotify.national.nhs.uk" >> $GITHUB_ENV
3638
echo "INSTANCE=$PROXYGEN_API_NAME-PR-$PR_NUMBER" >> $GITHUB_ENV
3739
fi
3840
@@ -52,6 +54,11 @@ runs:
5254
envsubst < ./.github/proxygen-settings.yaml > ${HOME}/.proxygen/settings.yaml
5355
envsubst < ./.github/proxygen-settings.yaml | cat
5456
57+
- name: Set target
58+
shell: bash
59+
run: |
60+
jq --arg newurl "$TARGET" '.["x-nhsd-apim"].target.url = $newurl' build/notify-supplier.json > build/notify-supplier_target.json && mv build/notify-supplier_target.json build/notify-supplier.json
61+
5562
5663
- name: Deploy to Internal Dev
5764
shell: bash

.github/workflows/pr_create_dynamic_env.yaml

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ jobs:
1717
- name: Trigger nhs-notify-internal dynamic environment workflow
1818
shell: bash
1919
run: |
20-
set -x
2120
this_repo_name=$(echo ${{ github.repository }} | cut -d'/' -f2)
2221
2322
DISPATCH_EVENT=$(jq -ncM \
@@ -46,10 +45,70 @@ jobs:
4645
}
4746
}')
4847
49-
curl --fail -L \
48+
curl --fail -L -s \
5049
-X POST \
5150
-H "Accept: application/vnd.github+json" \
5251
-H "Authorization: Bearer ${{ secrets.PR_TRIGGER_PAT }}" \
5352
-H "X-GitHub-Api-Version: 2022-11-28" \
5453
https://api.github.com/repos/NHSDigital/nhs-notify-internal/actions/workflows/dispatch-deploy-dynamic-env.yaml/dispatches \
5554
-d "${DISPATCH_EVENT}"
55+
56+
echo "Workflow triggered. Waiting for the workflow to complete.."
57+
58+
# Poll GitHub API to check the workflow status
59+
workflow_run_url=""
60+
for i in {1..12}; do
61+
workflow_run_url=$(curl -s \
62+
-H "Accept: application/vnd.github+json" \
63+
-H "Authorization: Bearer ${{ secrets.PR_TRIGGER_PAT }}" \
64+
-H "X-GitHub-Api-Version: 2022-11-28" \
65+
"https://api.github.com/repos/NHSDigital/nhs-notify-internal/actions/runs?event=workflow_dispatch&status=in_progress" \
66+
| jq -r '.workflow_runs[]
67+
| select(.name
68+
| contains("'pr${{ github.event.number }}'") and
69+
contains("'nhs-notify-supplier-api-dev'") and
70+
contains("'api'") and
71+
contains("'apply'"))
72+
| .url')
73+
74+
if [[ -n "$workflow_run_url" && "$workflow_run_url" != null ]]; then
75+
ui_url=${workflow_run_url/api./}
76+
ui_url=${ui_url/\/repos/}
77+
echo "Found workflow run url: $ui_url"
78+
echo "workflow_run_url=$workflow_run_url" >> $GITHUB_ENV
79+
break
80+
fi
81+
82+
echo "Waiting for workflow to start..."
83+
sleep 10
84+
done
85+
86+
if [[ -z "$workflow_run_url" || "$workflow_run_url" == null ]]; then
87+
echo "Failed to get the workflow run url. Exiting."
88+
exit 1
89+
fi
90+
91+
# Wait for workflow completion
92+
while true; do
93+
sleep 10
94+
response=$(curl -s -L \
95+
-H "Authorization: Bearer ${{ secrets.PR_TRIGGER_PAT }}" \
96+
-H "Accept: application/vnd.github+json" \
97+
$workflow_run_url)
98+
99+
status=$(echo "$response" | jq -r '.status')
100+
conclusion=$(echo "$response" | jq -r '.conclusion')
101+
102+
if [ "$status" == "completed" ]; then
103+
if [ "$conclusion" == "success" ]; then
104+
echo "Workflow completed successfully."
105+
exit 0
106+
else
107+
echo "Workflow failed with conclusion: $conclusion"
108+
exit 1
109+
fi
110+
fi
111+
112+
echo "Workflow still running..."
113+
sleep 20
114+
done

docs/Gemfile.lock

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,14 @@ GEM
2727
erb (4.0.4)
2828
cgi (>= 0.3.3)
2929
eventmachine (1.2.7)
30+
ffi (1.17.2-aarch64-linux-gnu)
3031
ffi (1.17.2-arm64-darwin)
3132
ffi (1.17.2-x86_64-linux-gnu)
3233
forwardable-extended (2.6.0)
3334
gemoji (4.1.0)
35+
google-protobuf (4.31.1-aarch64-linux-gnu)
36+
bigdecimal
37+
rake (>= 13)
3438
google-protobuf (4.31.1-arm64-darwin)
3539
bigdecimal
3640
rake (>= 13)
@@ -101,8 +105,9 @@ GEM
101105
jekyll-seo-tag (~> 2.1)
102106
minitest (5.24.1)
103107
mutex_m (0.2.0)
104-
nokogiri (1.18.9-arm64-darwin)
108+
nokogiri (1.18.4-aarch64-linux-gnu)
105109
racc (~> 1.4)
110+
nokogiri (1.18.9-arm64-darwin)
106111
nokogiri (1.18.9-x86_64-linux-gnu)
107112
racc (~> 1.4)
108113
pathutil (0.16.2)
@@ -116,6 +121,8 @@ GEM
116121
rexml (3.4.1)
117122
rouge (4.5.2)
118123
safe_yaml (1.0.5)
124+
sass-embedded (1.83.0-aarch64-linux-gnu)
125+
google-protobuf (~> 4.28)
119126
sass-embedded (1.83.0-arm64-darwin)
120127
google-protobuf (~> 4.28)
121128
sass-embedded (1.83.0-x86_64-linux-gnu)
@@ -128,6 +135,7 @@ GEM
128135
webrick (1.8.2)
129136

130137
PLATFORMS
138+
aarch64-linux
131139
arm64-darwin-23
132140
x86_64-linux
133141

infrastructure/terraform/components/api/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ No requirements.
3030
| <a name="module_get_letters"></a> [get\_letters](#module\_get\_letters) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/lambda | v2.0.10 |
3131
| <a name="module_hello_world"></a> [hello\_world](#module\_hello\_world) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/lambda | v2.0.10 |
3232
| <a name="module_kms"></a> [kms](#module\_kms) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/kms | v2.0.10 |
33+
| <a name="module_patch_letters"></a> [patch\_letters](#module\_patch\_letters) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/lambda | v2.0.10 |
3334
## Outputs
3435

3536
| Name | Description |

infrastructure/terraform/components/api/ddb_table_letters.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ resource "aws_dynamodb_table" "letters" {
1919

2020
attribute {
2121
name = "id"
22-
type = "string"
22+
type = "S"
2323
}
2424

2525
attribute {
2626
name = "supplierId"
27-
type = "string"
27+
type = "S"
2828
}
2929

3030
attribute {
3131
name = "supplierStatus"
32-
type = "string"
32+
type = "S"
3333
}
3434

3535
point_in_time_recovery {

infrastructure/terraform/components/api/ddb_table_mi.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ resource "aws_dynamodb_table" "mi" {
1212

1313
attribute {
1414
name = "id"
15-
type = "string"
15+
type = "S"
1616
}
1717

1818
attribute {
1919
name = "supplierId"
20-
type = "string"
20+
type = "S"
2121
}
2222

2323
point_in_time_recovery {

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
@@ -51,6 +51,7 @@ data "aws_iam_policy_document" "api_gateway_execution_policy" {
5151
module.authorizer_lambda.function_arn,
5252
module.hello_world.function_arn,
5353
module.get_letters.function_arn,
54+
module.patch_letters.function_arn
5455
]
5556
}
5657
}

infrastructure/terraform/components/api/locals.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ locals {
1010
AUTHORIZER_LAMBDA_ARN = module.authorizer_lambda.function_arn
1111
HELLO_WORLD_LAMBDA_ARN = module.hello_world.function_arn
1212
GET_LETTERS_LAMBDA_ARN = module.get_letters.function_arn
13+
PATCH_LETTERS_LAMBDA_ARN = module.patch_letters.function_arn
1314
})
1415

1516
destination_arn = "arn:aws:logs:${var.region}:${var.shared_infra_account_id}:destination:nhs-main-obs-firehose-logs"
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
module "patch_letters" {
2+
source = "git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/lambda?ref=v2.0.10"
3+
4+
function_name = "patch_letters"
5+
description = "Update the status of a letter"
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+
13+
group = var.group
14+
15+
log_retention_in_days = var.log_retention_in_days
16+
kms_key_arn = module.kms.key_arn
17+
18+
iam_policy_document = {
19+
body = data.aws_iam_policy_document.patch_letters_lambda.json
20+
}
21+
22+
function_s3_bucket = local.acct.s3_buckets["lambda_function_artefacts"]["id"]
23+
function_code_base_path = local.aws_lambda_functions_dir_path
24+
function_code_dir = "api-handler/dist"
25+
function_include_common = true
26+
handler_function_name = "patchLetters"
27+
runtime = "nodejs22.x"
28+
memory = 128
29+
timeout = 5
30+
log_level = var.log_level
31+
32+
force_lambda_code_deploy = var.force_lambda_code_deploy
33+
enable_lambda_insights = false
34+
35+
send_to_firehose = true
36+
log_destination_arn = local.destination_arn
37+
log_subscription_role_arn = local.acct.log_subscription_role_arn
38+
39+
lambda_env_vars = {
40+
}
41+
}
42+
43+
data "aws_iam_policy_document" "patch_letters_lambda" {
44+
statement {
45+
sid = "KMSPermissions"
46+
effect = "Allow"
47+
48+
actions = [
49+
"kms:Decrypt",
50+
"kms:GenerateDataKey",
51+
]
52+
53+
resources = [
54+
module.kms.key_arn, ## Requires shared kms module
55+
]
56+
}
57+
}

0 commit comments

Comments
 (0)