From 5e954eca4e86d4b3a39adcc90935d79d5d246ce4 Mon Sep 17 00:00:00 2001 From: Michael Harrison Date: Mon, 18 May 2026 17:00:24 +0100 Subject: [PATCH] CCM-17784: seed demo clients --- .gitignore | 1 + scripts/seed/seed.sh | 48 +++++++++++++++++++++++++++++++++++++++++++ scripts/seed/utils.sh | 21 +++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100755 scripts/seed/seed.sh create mode 100644 scripts/seed/utils.sh diff --git a/.gitignore b/.gitignore index bda797693c..b73ee50324 100644 --- a/.gitignore +++ b/.gitignore @@ -97,3 +97,4 @@ lambdas/backend-api/src/email/email-template.json .github/copilot-instructions.md test-runs +seed-data.json diff --git a/scripts/seed/seed.sh b/scripts/seed/seed.sh new file mode 100755 index 0000000000..8a01629b96 --- /dev/null +++ b/scripts/seed/seed.sh @@ -0,0 +1,48 @@ +#!/bin/bash + +set -euo pipefail + +root_dir=$(git rev-parse --show-toplevel) + +source "$root_dir/scripts/seed/utils.sh" + +if [ $# -ne 1 ]; then + echo 1>&2 "$0: expected 1 arguments, received $#" + exit 2 +fi + +environment=$1 + +data_file="$root_dir/seed-data.json" + +if [ ! -f "${data_file}" ]; then + echo 1>&2 "Error: Seed data file not found at ${data_file}" + exit 2 +fi + +csi="nhs-notify-${environment}-app" + +client_parameter_namespace=${csi} + +clients=$(jq -c '.clients[]?' "${data_file}") + +while IFS= read -r client; do + if [[ -n "${client}" ]]; then + client_id=$(jq -r '.id' <<< "${client}") + client_name=$(jq -r '.name' <<< "${client}") + + echo + echo "---" + echo "Processing client (${client_name} - ${client_id})" + + echo "Creating client SSM parameter" + put_client_parameter "${client_parameter_namespace}" "${client}" + echo "Created client SSM parameter" + echo + echo "Processed client: (${client_name} - ${client_id})" + fi +done <<< "${clients}" + +echo +echo "---" +echo "Successfully seeded all demo clients" diff --git a/scripts/seed/utils.sh b/scripts/seed/utils.sh new file mode 100644 index 0000000000..613047542a --- /dev/null +++ b/scripts/seed/utils.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +function put_client_parameter() { + local namespace=$1 + local client=$2 + + local client_id=$(jq -r '.id' <<< "${client}") + local campaign_ids=$(jq '.campaignIds' <<< "${client}") + local features=$(jq '.features' <<< "${client}") + local parameter_name="/${namespace}/clients/${client_id}" + local parameter_value=$(jq <<< "{ + \"campaignIds\": ${campaign_ids}, + \"features\": ${features} + }") + + aws ssm put-parameter \ + --name "${parameter_name}" \ + --value "${parameter_value}" \ + --type SecureString \ + --overwrite > /dev/null +}