diff --git a/.gitignore b/.gitignore index fb9c5ab6a..d01b955bd 100644 --- a/.gitignore +++ b/.gitignore @@ -95,3 +95,4 @@ tests/test-team/playwright/.cache/ .github/copilot-instructions.md test-runs +seed-data.json diff --git a/scripts/sandbox_auth.sh b/scripts/sandbox_auth.sh index 14e0b301c..ccfaf8caa 100755 --- a/scripts/sandbox_auth.sh +++ b/scripts/sandbox_auth.sh @@ -4,6 +4,8 @@ set -euo pipefail root_dir=$(git rev-parse --show-toplevel) +source "$root_dir/scripts/seed/utils.sh" + # expect 3 argument to the script if [ $# -ne 2 ]; then echo 1>&2 "$0: expected 2 arguments, received $#" @@ -68,11 +70,7 @@ if [[ "$get_user_command_exit_code" -ne 0 ]]; then if aws ssm get-parameter --name "$client_config_param_name" --with-decryption >/dev/null 2>&1; then echo "Client config parameter already exists: $client_config_param_name" else - aws ssm put-parameter \ - --name "$client_config_param_name" \ - --value "$client_config_param_value" \ - --type String - + put_client_parameter "${client_config_param_name}" "${client_config_param_value}" echo "Created client config parameter: $client_config_param_name" fi diff --git a/scripts/seed/seed.sh b/scripts/seed/seed.sh new file mode 100755 index 000000000..7becda88c --- /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" + +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_id}" "${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 000000000..74ee24082 --- /dev/null +++ b/scripts/seed/utils.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +function put_client_parameter() { + local parameter_name=$1 + local client=$2 + + local campaign_ids=$(jq '.campaignIds' <<< "${client}") + local features=$(jq '.features' <<< "${client}") + local parameter_value=$(jq <<< "{ + \"campaignIds\": ${campaign_ids}, + \"features\": ${features} + }") + + aws ssm put-parameter \ + --name "${parameter_name}" \ + --value "${parameter_value}" \ + --type String \ + --overwrite > /dev/null +}