From 75d12526ae1ddb2359ae6abc06c478748cca6324 Mon Sep 17 00:00:00 2001 From: Basilio Bogado <541149+basiliskus@users.noreply.github.com> Date: Fri, 25 Oct 2024 15:22:08 -0700 Subject: [PATCH 01/29] Simplified load-etor-org-settings script to only run in local env --- scripts/rs/load-etor-org-settings.sh | 55 ++++++---------------------- 1 file changed, 12 insertions(+), 43 deletions(-) diff --git a/scripts/rs/load-etor-org-settings.sh b/scripts/rs/load-etor-org-settings.sh index 9eae5d39e..c37b72ea4 100755 --- a/scripts/rs/load-etor-org-settings.sh +++ b/scripts/rs/load-etor-org-settings.sh @@ -1,51 +1,20 @@ #!/usr/bin/env bash -# This script loads the ETOR organization settings and adds the public keys for the senders. +# This script loads the ETOR organization settings locally and adds the public keys for the senders. # NOTE: Remember to run this script inside the prime-router directory of the prime-reportstream codebase # Make sure to add a CDCTI_HOME environment variable pointing to the trusted-intermediary directory # export CDCTI_HOME="/path/to/trusted-intermediary" # You'll also need to set the path to the keys if running in a non-local environment -env=${1:-"local"} +# Load organization settings +./prime multiple-settings set -s -i ./settings/STLTs/Flexion/flexion.yml +./prime multiple-settings set -s -i ./settings/STLTs/CA/ucsd.yml +./prime multiple-settings set -s -i ./settings/STLTs/LA/la-phl.yml +./prime multiple-settings set -s -i ./settings/STLTs/LA/la-ochsner.yml -if [ "$env" = "local" ]; then - echo "Using local public keys" - flexion_key="$CDCTI_HOME/mock_credentials/organization-trusted-intermediary-public-key-local.pem" - # al_phl_key="/path/to/organization-al-phl-public-key-local.pem" - # oracle_rln_key="/path/to/organization-oracle-rln-public-key-local.pem" - # la_phl_key="/path/to/organization-la-phl-public-key-local.pem" - # la_ochsner_key="/path/to/organization-la-ochsner-public-key-local.pem" -elif [ "$env" = "staging" ]; then - echo "Using staging public keys" - # flexion_key="/path/to/organization-trusted-intermediary-public-key-staging.pem" - # al_phl_key="/path/to/organization-al-phl-public-key-staging.pem" - # oracle_rln_key="/path/to/organization-oracle-rln-public-key-staging.pem" - # la_phl_key="/path/to/organization-la-phl-public-key-staging.pem" - # la_ochsner_key="/path/to/organization-la-ochsner-public-key-staging.pem" -elif [ "$env" = "prod" ]; then - echo "Using prod public keys" - # flexion_key="/path/to/organization-trusted-intermediary-public-key-prod.pem" - # al_phl_key="/path/to/organization-al-phl-public-key-prod.pem" - # oracle_rln_key="/path/to/organization-oracle-rln-public-key-prod.pem" - # la_phl_key="/path/to/organization-la-phl-public-key-prod.pem" - # la_ochsner_key="/path/to/organization-la-ochsner-public-key-prod.pem" -else - echo "Unknown environment: $env" - exit 1 -fi - -## Flexion -./prime multiple-settings set -s -e $env -i ./settings/STLTs/Flexion/flexion.yml -./prime organization addkey -e $env --public-key $flexion_key --scope "flexion.*.report" --orgName flexion --kid flexion.etor-service-sender --doit -./prime organization addkey -e $env --public-key $flexion_key --scope "flexion.*.report" --orgName flexion --kid flexion.simulated-hospital --doit -./prime organization addkey -e $env --public-key $flexion_key --scope "flexion.*.report" --orgName flexion --kid flexion.simulated-lab --doit -./prime organization addkey -e $env --public-key $flexion_key --scope "flexion.*.report" --orgName flexion --kid flexion.simulated-sender --doit - -## CA -./prime multiple-settings set -s -e $env -i ./settings/STLTs/CA/ucsd.yml - -## LA -./prime multiple-settings set -s -e $env -i ./settings/STLTs/LA/la-phl.yml -# ./prime organization addkey -e $env --public-key $la_phl_key --scope "la-phl.*.report" --orgName la-phl --kid la-phl.etor-nbs-results --doit -./prime multiple-settings set -s -e $env -i ./settings/STLTs/LA/la-ochsner.yml -# ./prime organization addkey -e $env --public-key $la_ochsner_key --scope "la-ochsner.*.report" --orgName la-ochsner --kid la-ochsner.etor-nbs-orders --doit +# Add public keys for senders +flexion_key="$CDCTI_HOME/mock_credentials/organization-trusted-intermediary-public-key-local.pem" +./prime organization addkey --public-key $flexion_key --scope "flexion.*.report" --orgName flexion --kid flexion.etor-service-sender --doit +./prime organization addkey --public-key $flexion_key --scope "flexion.*.report" --orgName flexion --kid flexion.simulated-hospital --doit +./prime organization addkey --public-key $flexion_key --scope "flexion.*.report" --orgName flexion --kid flexion.simulated-lab --doit +./prime organization addkey --public-key $flexion_key --scope "flexion.*.report" --orgName flexion --kid flexion.simulated-sender --doit From 917ba5481e22055d992c167d355e8367af070a47 Mon Sep 17 00:00:00 2001 From: Basilio Bogado <541149+basiliskus@users.noreply.github.com> Date: Fri, 25 Oct 2024 15:23:11 -0700 Subject: [PATCH 02/29] Using preferred gradlew commands instead of prime ones. Also added env variable for RS_HOME --- scripts/rs/reset.sh | 14 ++++++++------ scripts/start-here.sh | 3 +++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/scripts/rs/reset.sh b/scripts/rs/reset.sh index 558b7a799..0153b64eb 100755 --- a/scripts/rs/reset.sh +++ b/scripts/rs/reset.sh @@ -1,13 +1,15 @@ #!/usr/bin/env bash +CURRENT_DIR=$(pwd) + # This script resets the database and loads the baseline settings. # NOTE: Remember to run this script inside the prime-router directory of the prime-reportstream codebase -# Reset database -../gradlew resetDB +# Need to CD to the RS codebase local working copy to run the gradlew commands +cd "$RS_HOME" -# Reload tables -./prime lookuptables loadall +./gradlew resetDB +./gradlew reloadTable +./gradlew reloadSettings -# Load baseline organization settings -./prime multiple-settings set -s -i ./settings/organizations.yml +cd "$CURRENT_DIR" diff --git a/scripts/start-here.sh b/scripts/start-here.sh index 3392408f8..e1d5a6c81 100755 --- a/scripts/start-here.sh +++ b/scripts/start-here.sh @@ -1 +1,4 @@ +#!/usr/bin/env bash + export CDCTI_HOME="/path/to/trusted-intermediary" +export RS_HOME="/path/to/prime-reportstream" From 12609d132ac3de5fda45fb9e302e89a63e457577 Mon Sep 17 00:00:00 2001 From: Basilio Bogado <541149+basiliskus@users.noreply.github.com> Date: Mon, 28 Oct 2024 14:55:12 -0700 Subject: [PATCH 03/29] Moved common functions to /scripts/utils.sh and importing scripts using absolute path --- scripts/hurl/epic.sh | 4 +++- scripts/hurl/rs.sh | 5 +++-- scripts/hurl/submit_message.sh | 4 +++- scripts/hurl/ti.sh | 5 +++-- scripts/hurl/update_examples.sh | 4 +++- scripts/hurl/utils.sh | 33 -------------------------------- scripts/rs/update_org_yaml.sh | 3 ++- scripts/utils.sh | 34 +++++++++++++++++++++++++++++++++ 8 files changed, 51 insertions(+), 41 deletions(-) create mode 100755 scripts/utils.sh diff --git a/scripts/hurl/epic.sh b/scripts/hurl/epic.sh index 57835798d..e041bbcd4 100755 --- a/scripts/hurl/epic.sh +++ b/scripts/hurl/epic.sh @@ -1,6 +1,8 @@ #!/bin/bash -source ./utils.sh +[ -z "${CDCTI_HOME}" ] && echo "Error: Environment variable CDCTI_HOME is not set" && exit 1 +source "$CDCTI_HOME/scripts/utils.sh" +source "$CDCTI_HOME/scripts/hurl/utils.sh" client= audience=https://epicproxy-np.et0502.epichosted.com/FhirProxy/oauth2/token diff --git a/scripts/hurl/rs.sh b/scripts/hurl/rs.sh index 39a65d669..ff23f8081 100755 --- a/scripts/hurl/rs.sh +++ b/scripts/hurl/rs.sh @@ -1,6 +1,8 @@ #!/bin/bash -source ./utils.sh +[ -z "${CDCTI_HOME}" ] && echo "Error: Environment variable CDCTI_HOME is not set" && exit 1 +source "$CDCTI_HOME/scripts/utils.sh" +source "$CDCTI_HOME/scripts/hurl/utils.sh" # default values env=local @@ -97,7 +99,6 @@ run_hurl_command() { ${remaining_args:+$remaining_args} } -check_env_vars CDCTI_HOME parse_arguments "$@" setup_credentials run_hurl_command diff --git a/scripts/hurl/submit_message.sh b/scripts/hurl/submit_message.sh index 35c7ccfdb..09f7d1a0b 100755 --- a/scripts/hurl/submit_message.sh +++ b/scripts/hurl/submit_message.sh @@ -1,6 +1,8 @@ #!/bin/bash -source ./utils.sh +[ -z "${CDCTI_HOME}" ] && echo "Error: Environment variable CDCTI_HOME is not set" && exit 1 +source "$CDCTI_HOME/scripts/utils.sh" +source "$CDCTI_HOME/scripts/hurl/utils.sh" env="local" diff --git a/scripts/hurl/ti.sh b/scripts/hurl/ti.sh index 9278dc147..ad4ba73b8 100755 --- a/scripts/hurl/ti.sh +++ b/scripts/hurl/ti.sh @@ -1,6 +1,8 @@ #!/bin/bash -source ./utils.sh +[ -z "${CDCTI_HOME}" ] && echo "Error: Environment variable CDCTI_HOME is not set" && exit 1 +source "$CDCTI_HOME/scripts/utils.sh" +source "$CDCTI_HOME/scripts/hurl/utils.sh" # default values env=local @@ -89,7 +91,6 @@ run_hurl_command() { ${remaining_args:+$remaining_args} } -check_env_vars CDCTI_HOME parse_arguments "$@" setup_credentials run_hurl_command diff --git a/scripts/hurl/update_examples.sh b/scripts/hurl/update_examples.sh index d140ebfab..aef8a1318 100755 --- a/scripts/hurl/update_examples.sh +++ b/scripts/hurl/update_examples.sh @@ -1,6 +1,8 @@ #!/bin/bash -source ./utils.sh +[ -z "${CDCTI_HOME}" ] && echo "Error: Environment variable CDCTI_HOME is not set" && exit 1 +source "$CDCTI_HOME/scripts/utils.sh" +source "$CDCTI_HOME/scripts/hurl/utils.sh" env=local diff --git a/scripts/hurl/utils.sh b/scripts/hurl/utils.sh index b9d8903f7..7cc839d82 100755 --- a/scripts/hurl/utils.sh +++ b/scripts/hurl/utils.sh @@ -17,39 +17,6 @@ TI_API_PRD_URL="https://cdcti-prd-api.azurewebsites.net:443" RS_CLIENT_LOCAL_PRIVATE_KEY_PATH="$CDCTI_HOME/mock_credentials/organization-trusted-intermediary-private-key-local.pem" TI_CLIENT_LOCAL_PRIVATE_KEY_PATH="$CDCTI_HOME/mock_credentials/organization-report-stream-private-key-local.pem" -fail() { - echo "Error: $1" >&2 - exit 1 -} - -check_installed_commands() { - for cmd in "$@"; do - if ! command -v "$cmd" &>/dev/null; then - echo "$cmd could not be found. Please install $cmd to proceed." - exit 1 - fi - done -} - -check_apis() { - for service in "$@"; do - if ! curl -s --head --fail "$service" | grep "200 OK" >/dev/null; then - echo "The service at $service is not reachable" - exit 1 - fi - done -} - -check_env_vars() { - local env_vars=("$@") - for var in "${env_vars[@]}"; do - if [ -z "${!var}" ]; then - echo "Error: Environment variable '$var' is not set" - exit 1 - fi - done -} - get_api_url() { local env=$1 local type=$2 diff --git a/scripts/rs/update_org_yaml.sh b/scripts/rs/update_org_yaml.sh index 5ccce812e..2360b35e9 100755 --- a/scripts/rs/update_org_yaml.sh +++ b/scripts/rs/update_org_yaml.sh @@ -1,6 +1,7 @@ #!/bin/bash -source "$CDCTI_HOME/scripts/hurl/utils.sh" +[ -z "${CDCTI_HOME}" ] && echo "Error: Environment variable CDCTI_HOME is not set" && exit 1 +source "$CDCTI_HOME/scripts/utils.sh" # This script updates the organization settings YAML files in RS to: # - use local REST transport settings for Flexion's etor-service-receiver receivers diff --git a/scripts/utils.sh b/scripts/utils.sh new file mode 100755 index 000000000..bb06d018f --- /dev/null +++ b/scripts/utils.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +fail() { + echo "Error: $1" >&2 + exit 1 +} + +check_env_vars() { + local env_vars=("$@") + for var in "${env_vars[@]}"; do + if [ -z "${!var}" ]; then + echo "Error: Environment variable '$var' is not set" + exit 1 + fi + done +} + +check_installed_commands() { + for cmd in "$@"; do + if ! command -v "$cmd" &>/dev/null; then + echo "$cmd could not be found. Please install $cmd to proceed." + exit 1 + fi + done +} + +check_apis() { + for service in "$@"; do + if ! curl -s --head --fail "$service" | grep "200 OK" >/dev/null; then + echo "The service at $service is not reachable" + exit 1 + fi + done +} From d3b92138967fa83d787b078d2c5b06d87d891ebf Mon Sep 17 00:00:00 2001 From: Basilio Bogado <541149+basiliskus@users.noreply.github.com> Date: Tue, 29 Oct 2024 14:14:26 -0700 Subject: [PATCH 04/29] Extract env variables to a shared .env file, updated docs, renamed some of the envars. Also working of having absolute paths so the scripts could run from anywhere --- scripts/.env.template | 25 ++++++++++++++++++++++++ scripts/README.md | 14 +++++++++++++- scripts/hurl/rs.sh | 6 +++--- scripts/hurl/submit_message.sh | 4 ++-- scripts/hurl/ti.sh | 6 +++--- scripts/hurl/update_examples.sh | 2 +- scripts/hurl/utils.sh | 29 ++++++---------------------- scripts/rs/load-etor-org-settings.sh | 9 ++++----- scripts/rs/reset.sh | 4 ++-- scripts/rs/setup-local-vault.sh | 16 +++++++-------- scripts/utils.sh | 11 +++++++++++ 11 files changed, 78 insertions(+), 48 deletions(-) create mode 100644 scripts/.env.template diff --git a/scripts/.env.template b/scripts/.env.template new file mode 100644 index 000000000..a9701e1c9 --- /dev/null +++ b/scripts/.env.template @@ -0,0 +1,25 @@ +# Core settings +CDCTI_HOME="/path/to/trusted-intermediary" +RS_HOME="/path/to/prime-reportstream" + +# API URLs +RS_LCL_API_URL="http://localhost:7071" +RS_STG_API_URL="https://staging.prime.cdc.gov:443" +RS_PRD_API_URL="https://prime.cdc.gov:443" +TI_LCL_API_URL="http://localhost:8080" +TI_STG_API_URL="https://cdcti-stg-api.azurewebsites.net:443" +TI_PRD_API_URL="https://cdcti-prd-api.azurewebsites.net:443" + +# Client keys +TI_LOCAL_PRIVATE_KEY_PATH="${CDCTI_HOME}/mock_credentials/organization-trusted-intermediary-private-key-local.pem" +TI_LOCAL_PUBLIC_KEY_PATH="${CDCTI_HOME}/mock_credentials/organization-trusted-intermediary-public-key-local.pem" +RS_LOCAL_PRIVATE_KEY_PATH="${CDCTI_HOME}/mock_credentials/organization-report-stream-private-key-local.pem" + +# Storage settings +AZURITE_CONNECTION_STRING="DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://localhost:10000/devstoreaccount1;" # pragma: allowlist secret + +# Message snapshot suffixes +FILE_NAME_SUFFIX_STEP_0="_0_initial_message" +FILE_NAME_SUFFIX_STEP_1="_1_hl7_translation" +FILE_NAME_SUFFIX_STEP_2="_2_fhir_transformation" +FILE_NAME_SUFFIX_STEP_3="_3_hl7_translation_final" diff --git a/scripts/README.md b/scripts/README.md index 3fa583ac1..6a53531b4 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -1,3 +1,15 @@ # Scripts -These scripts rely in a `CDCTI_HOME` environment variable that needs to be set in your environment to your local path to the CDC-TI codebase. You may update and run the `start-here.sh` script to set it. You may also want to add it to your shell's startup file to persist it. +## Instructions + +1. Copy `.env.template` to `.env` + ``` + cp .env.template .env + ``` +2. Edit `.env` and make sure to update at least `CDCTI_HOME` (local path to the `trusted-intermediary` codebase) and `RS_HOME` (local path to the `prime-reportstream` codebase) are set. **Note**: if you don't set `CDCTI_HOME`, none of these scripts will work +3. Load the environment variables in `.env` by running + ``` + source .env + ``` + **Note**: you may also want to add it to your shell's startup file so you don't need to run it for every terminal session. +4. Run you script diff --git a/scripts/hurl/rs.sh b/scripts/hurl/rs.sh index ff23f8081..26c5bac9e 100755 --- a/scripts/hurl/rs.sh +++ b/scripts/hurl/rs.sh @@ -66,10 +66,10 @@ parse_arguments() { setup_credentials() { if [ -z "$private_key" ] && [ "$client_id" = "flexion" ] && [ "$env" = "local" ]; then - if [ -f "$RS_CLIENT_LOCAL_PRIVATE_KEY_PATH" ]; then - private_key="$RS_CLIENT_LOCAL_PRIVATE_KEY_PATH" + if [ -f "$TI_LOCAL_PRIVATE_KEY_PATH" ]; then + private_key="$TI_LOCAL_PRIVATE_KEY_PATH" else - fail "Local environment client private key not found at: $RS_CLIENT_LOCAL_PRIVATE_KEY_PATH" + fail "Local environment client private key not found at: $TI_LOCAL_PRIVATE_KEY_PATH" fi fi diff --git a/scripts/hurl/submit_message.sh b/scripts/hurl/submit_message.sh index 09f7d1a0b..9440a6872 100755 --- a/scripts/hurl/submit_message.sh +++ b/scripts/hurl/submit_message.sh @@ -48,7 +48,7 @@ parse_arguments() { setup_credentials() { # Handle RS client key if [ "$env" = "local" ] && [ -z "$rs_client_private_key" ]; then - rs_client_private_key="$RS_CLIENT_LOCAL_PRIVATE_KEY_PATH" + rs_client_private_key="$TI_LOCAL_PRIVATE_KEY_PATH" fi [ "$env" != "local" ] && [ -z "$rs_client_private_key" ] && fail "RS client private key (-x) is required for non-local environments" @@ -56,7 +56,7 @@ setup_credentials() { # Handle optional TI client key if [ "$env" = "local" ] && [ -z "$ti_client_private_key" ]; then - ti_client_private_key="$TI_CLIENT_LOCAL_PRIVATE_KEY_PATH" + ti_client_private_key="$RS_LOCAL_PRIVATE_KEY_PATH" fi # Only verify TI key if provided diff --git a/scripts/hurl/ti.sh b/scripts/hurl/ti.sh index ad4ba73b8..4769c391e 100755 --- a/scripts/hurl/ti.sh +++ b/scripts/hurl/ti.sh @@ -60,10 +60,10 @@ parse_arguments() { setup_credentials() { if [ -z "$private_key" ] && [ "$client" = "report-stream" ] && [ "$env" = "local" ]; then - if [ -f "$TI_CLIENT_LOCAL_PRIVATE_KEY_PATH" ]; then - private_key="$TI_CLIENT_LOCAL_PRIVATE_KEY_PATH" + if [ -f "$RS_LOCAL_PRIVATE_KEY_PATH" ]; then + private_key="$RS_LOCAL_PRIVATE_KEY_PATH" else - fail "Local environment client private key not found at: $TI_CLIENT_LOCAL_PRIVATE_KEY_PATH" + fail "Local environment client private key not found at: $RS_LOCAL_PRIVATE_KEY_PATH" fi fi diff --git a/scripts/hurl/update_examples.sh b/scripts/hurl/update_examples.sh index aef8a1318..6c9728708 100755 --- a/scripts/hurl/update_examples.sh +++ b/scripts/hurl/update_examples.sh @@ -12,5 +12,5 @@ check_apis "$(get_api_url "$env" "rs")" "$(get_api_url "$env" "ti")" find "$CDCTI_HOME/examples" -type f -name "*$FILE_NAME_SUFFIX_STEP_0.hl7" | while read -r file; do echo "-----------------------------------------------------------------------------------------------------------" echo "Submitting message: $file" - submit_message "$env" "$file" "$RS_CLIENT_LOCAL_PRIVATE_KEY_PATH" "$TI_CLIENT_LOCAL_PRIVATE_KEY_PATH" + submit_message "$env" "$file" "$TI_LOCAL_PRIVATE_KEY_PATH" "$RS_LOCAL_PRIVATE_KEY_PATH" done diff --git a/scripts/hurl/utils.sh b/scripts/hurl/utils.sh index 7cc839d82..d138ffd61 100755 --- a/scripts/hurl/utils.sh +++ b/scripts/hurl/utils.sh @@ -1,22 +1,5 @@ #!/bin/bash -FILE_NAME_SUFFIX_STEP_0="_0_initial_message" -FILE_NAME_SUFFIX_STEP_1="_1_hl7_translation" -FILE_NAME_SUFFIX_STEP_2="_2_fhir_transformation" -FILE_NAME_SUFFIX_STEP_3="_3_hl7_translation_final" - -AZURITE_CONNECTION_STRING="DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://localhost:10000/devstoreaccount1;" # pragma: allowlist secret - -RS_API_LCL_URL="http://localhost:7071" -RS_API_STG_URL="https://staging.prime.cdc.gov:443" -RS_API_PRD_URL="https://prime.cdc.gov:443" -TI_API_LCL_URL="http://localhost:8080" -TI_API_STG_URL="https://cdcti-stg-api.azurewebsites.net:443" -TI_API_PRD_URL="https://cdcti-prd-api.azurewebsites.net:443" - -RS_CLIENT_LOCAL_PRIVATE_KEY_PATH="$CDCTI_HOME/mock_credentials/organization-trusted-intermediary-private-key-local.pem" -TI_CLIENT_LOCAL_PRIVATE_KEY_PATH="$CDCTI_HOME/mock_credentials/organization-report-stream-private-key-local.pem" - get_api_url() { local env=$1 local type=$2 @@ -24,9 +7,9 @@ get_api_url() { case "$type" in "rs") case "$env" in - "local") echo $RS_API_LCL_URL ;; - "staging") echo $RS_API_STG_URL ;; - "production") echo $RS_API_PRD_URL ;; + "local") echo $RS_LCL_API_URL ;; + "staging") echo $RS_STG_API_URL ;; + "production") echo $RS_PRD_API_URL ;; *) echo "Invalid environment: $env" >&2 exit 1 @@ -35,9 +18,9 @@ get_api_url() { ;; "ti") case "$env" in - "local") echo $TI_API_LCL_URL ;; - "staging") echo $TI_API_STG_URL ;; - "production") echo $TI_API_PRD_URL ;; + "local") echo $TI_LCL_API_URL ;; + "staging") echo $TI_STG_API_URL ;; + "production") echo $TI_PRD_API_URL ;; *) echo "Invalid environment: $env" >&2 exit 1 diff --git a/scripts/rs/load-etor-org-settings.sh b/scripts/rs/load-etor-org-settings.sh index c37b72ea4..521311eef 100755 --- a/scripts/rs/load-etor-org-settings.sh +++ b/scripts/rs/load-etor-org-settings.sh @@ -13,8 +13,7 @@ ./prime multiple-settings set -s -i ./settings/STLTs/LA/la-ochsner.yml # Add public keys for senders -flexion_key="$CDCTI_HOME/mock_credentials/organization-trusted-intermediary-public-key-local.pem" -./prime organization addkey --public-key $flexion_key --scope "flexion.*.report" --orgName flexion --kid flexion.etor-service-sender --doit -./prime organization addkey --public-key $flexion_key --scope "flexion.*.report" --orgName flexion --kid flexion.simulated-hospital --doit -./prime organization addkey --public-key $flexion_key --scope "flexion.*.report" --orgName flexion --kid flexion.simulated-lab --doit -./prime organization addkey --public-key $flexion_key --scope "flexion.*.report" --orgName flexion --kid flexion.simulated-sender --doit +./prime organization addkey --public-key "$TI_LOCAL_PUBLIC_KEY_PATH" --scope "flexion.*.report" --orgName flexion --kid flexion.etor-service-sender --doit +./prime organization addkey --public-key "$TI_LOCAL_PUBLIC_KEY_PATH" --scope "flexion.*.report" --orgName flexion --kid flexion.simulated-hospital --doit +./prime organization addkey --public-key "$TI_LOCAL_PUBLIC_KEY_PATH" --scope "flexion.*.report" --orgName flexion --kid flexion.simulated-lab --doit +./prime organization addkey --public-key "$TI_LOCAL_PUBLIC_KEY_PATH" --scope "flexion.*.report" --orgName flexion --kid flexion.simulated-sender --doit diff --git a/scripts/rs/reset.sh b/scripts/rs/reset.sh index 0153b64eb..d3a332a53 100755 --- a/scripts/rs/reset.sh +++ b/scripts/rs/reset.sh @@ -6,10 +6,10 @@ CURRENT_DIR=$(pwd) # NOTE: Remember to run this script inside the prime-router directory of the prime-reportstream codebase # Need to CD to the RS codebase local working copy to run the gradlew commands -cd "$RS_HOME" +cd "$RS_HOME" || exit ./gradlew resetDB ./gradlew reloadTable ./gradlew reloadSettings -cd "$CURRENT_DIR" +cd "$CURRENT_DIR" || exit diff --git a/scripts/rs/setup-local-vault.sh b/scripts/rs/setup-local-vault.sh index 953f66a0a..69ce3eed6 100755 --- a/scripts/rs/setup-local-vault.sh +++ b/scripts/rs/setup-local-vault.sh @@ -5,13 +5,13 @@ # Make sure to add a CDCTI_HOME environment variable pointing to the trusted-intermediary directory # export CDCTI_HOME="/path/to/trusted-intermediary" -private_key=$(cat $CDCTI_HOME/mock_credentials/organization-report-stream-private-key-local.pem) - -export $(xargs <.vault/env/.env.local) +source "$RS_HOME/prime-router/.vault/env/.env.local" ./prime create-credential --type UserPass --user foo --pass pass --persist DEFAULT-SFTP -./prime create-credential --type UserApiKey --apikey-user flexion --apikey "$private_key" --persist FLEXION--ETOR-SERVICE-RECEIVER-ORDERS -./prime create-credential --type UserApiKey --apikey-user flexion --apikey "$private_key" --persist FLEXION--ETOR-SERVICE-RECEIVER-RESULTS -./prime create-credential --type UserApiKey --apikey-user ucsd --apikey "$private_key" --persist UCSD--ETOR-NBS-RESULTS -./prime create-credential --type UserApiKey --apikey-user la-phl --apikey "$private_key" --persist LA-PHL--ETOR-NBS-ORDERS -./prime create-credential --type UserApiKey --apikey-user la-ochsner --apikey "$private_key" --persist LA-OCHSNER--ETOR-NBS-RESULTS + +rs_private_key=$(cat "$RS_LOCAL_PRIVATE_KEY_PATH") +./prime create-credential --type UserApiKey --apikey-user flexion --apikey "$rs_private_key" --persist FLEXION--ETOR-SERVICE-RECEIVER-ORDERS +./prime create-credential --type UserApiKey --apikey-user flexion --apikey "$rs_private_key" --persist FLEXION--ETOR-SERVICE-RECEIVER-RESULTS +./prime create-credential --type UserApiKey --apikey-user ucsd --apikey "$rs_private_key" --persist UCSD--ETOR-NBS-RESULTS +./prime create-credential --type UserApiKey --apikey-user la-phl --apikey "$rs_private_key" --persist LA-PHL--ETOR-NBS-ORDERS +./prime create-credential --type UserApiKey --apikey-user la-ochsner --apikey "$rs_private_key" --persist LA-OCHSNER--ETOR-NBS-RESULTS diff --git a/scripts/utils.sh b/scripts/utils.sh index bb06d018f..e40bb9ebb 100755 --- a/scripts/utils.sh +++ b/scripts/utils.sh @@ -1,5 +1,16 @@ #!/bin/bash +load_env() { + local env_file=".env" + if [[ -f "$env_file" ]]; then + source "$env_file" + else + echo "Warning: .env file not found at $env_file" >&2 + return 1 + fi +} +load_env || exit 1 + fail() { echo "Error: $1" >&2 exit 1 From 943dfda9962d6e5515ec3d75200b070dd761522d Mon Sep 17 00:00:00 2001 From: Basilio Bogado <541149+basiliskus@users.noreply.github.com> Date: Tue, 29 Oct 2024 14:30:19 -0700 Subject: [PATCH 05/29] Fixed .env loading and some cleanup --- scripts/.env.template | 1 + scripts/README.md | 2 +- scripts/start-here.sh | 4 ---- scripts/utils.sh | 6 ++++-- 4 files changed, 6 insertions(+), 7 deletions(-) delete mode 100755 scripts/start-here.sh diff --git a/scripts/.env.template b/scripts/.env.template index a9701e1c9..747dfb36b 100644 --- a/scripts/.env.template +++ b/scripts/.env.template @@ -1,4 +1,5 @@ # Core settings +# Use $HOME or the full path to your home directory instead of ~ CDCTI_HOME="/path/to/trusted-intermediary" RS_HOME="/path/to/prime-reportstream" diff --git a/scripts/README.md b/scripts/README.md index 6a53531b4..8f8d570cf 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -6,7 +6,7 @@ ``` cp .env.template .env ``` -2. Edit `.env` and make sure to update at least `CDCTI_HOME` (local path to the `trusted-intermediary` codebase) and `RS_HOME` (local path to the `prime-reportstream` codebase) are set. **Note**: if you don't set `CDCTI_HOME`, none of these scripts will work +2. Edit `.env` and make sure to update at least `CDCTI_HOME` (local path to the `trusted-intermediary` codebase) and `RS_HOME` (local path to the `prime-reportstream` codebase) are set. **Note**: if you don't set `CDCTI_HOME`, none of these scripts will work. Also, please use `$HOME` or the full path to your home directory instead of `~` 3. Load the environment variables in `.env` by running ``` source .env diff --git a/scripts/start-here.sh b/scripts/start-here.sh deleted file mode 100755 index e1d5a6c81..000000000 --- a/scripts/start-here.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash - -export CDCTI_HOME="/path/to/trusted-intermediary" -export RS_HOME="/path/to/prime-reportstream" diff --git a/scripts/utils.sh b/scripts/utils.sh index e40bb9ebb..10d2aea50 100755 --- a/scripts/utils.sh +++ b/scripts/utils.sh @@ -1,11 +1,13 @@ #!/bin/bash load_env() { - local env_file=".env" + local script_dir env_file + script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + env_file="${script_dir}/.env" if [[ -f "$env_file" ]]; then source "$env_file" else - echo "Warning: .env file not found at $env_file" >&2 + echo "Error: $env_file file not found" >&2 return 1 fi } From 9ff58cba70cb63252c2b7f1447c02830a6807d2b Mon Sep 17 00:00:00 2001 From: Basilio Bogado <541149+basiliskus@users.noreply.github.com> Date: Tue, 29 Oct 2024 14:53:23 -0700 Subject: [PATCH 06/29] Renamed reset.sh => setup.sh --- scripts/rs/{reset.sh => setup.sh} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename scripts/rs/{reset.sh => setup.sh} (100%) diff --git a/scripts/rs/reset.sh b/scripts/rs/setup.sh similarity index 100% rename from scripts/rs/reset.sh rename to scripts/rs/setup.sh From 42616090d3cbf22166e12ebf4311fd9cd25c8f7a Mon Sep 17 00:00:00 2001 From: Basilio Bogado <541149+basiliskus@users.noreply.github.com> Date: Tue, 29 Oct 2024 16:26:49 -0700 Subject: [PATCH 07/29] Consolidated RS setup scripts into one --- scripts/hurl/utils.sh | 35 -------------- scripts/rs/load-etor-org-settings.sh | 19 -------- scripts/rs/setup-local-vault.sh | 17 ------- scripts/rs/setup.sh | 72 ++++++++++++++++++++++++++-- scripts/rs/update_org_yaml.sh | 49 ------------------- scripts/utils.sh | 35 ++++++++++++++ 6 files changed, 104 insertions(+), 123 deletions(-) delete mode 100755 scripts/rs/load-etor-org-settings.sh delete mode 100755 scripts/rs/setup-local-vault.sh delete mode 100755 scripts/rs/update_org_yaml.sh diff --git a/scripts/hurl/utils.sh b/scripts/hurl/utils.sh index d138ffd61..6846d2745 100755 --- a/scripts/hurl/utils.sh +++ b/scripts/hurl/utils.sh @@ -1,40 +1,5 @@ #!/bin/bash -get_api_url() { - local env=$1 - local type=$2 - - case "$type" in - "rs") - case "$env" in - "local") echo $RS_LCL_API_URL ;; - "staging") echo $RS_STG_API_URL ;; - "production") echo $RS_PRD_API_URL ;; - *) - echo "Invalid environment: $env" >&2 - exit 1 - ;; - esac - ;; - "ti") - case "$env" in - "local") echo $TI_LCL_API_URL ;; - "staging") echo $TI_STG_API_URL ;; - "production") echo $TI_PRD_API_URL ;; - *) - echo "Invalid environment: $env" >&2 - exit 1 - ;; - esac - ;; - esac -} - -extract_host_from_url() { - local url=$1 - echo "$url" | sed 's|^.*://\([^/:]*\)[:/].*|\1|' -} - generate_jwt() { # requires: jwt-cli local client=$1 diff --git a/scripts/rs/load-etor-org-settings.sh b/scripts/rs/load-etor-org-settings.sh deleted file mode 100755 index 521311eef..000000000 --- a/scripts/rs/load-etor-org-settings.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env bash - -# This script loads the ETOR organization settings locally and adds the public keys for the senders. -# NOTE: Remember to run this script inside the prime-router directory of the prime-reportstream codebase -# Make sure to add a CDCTI_HOME environment variable pointing to the trusted-intermediary directory -# export CDCTI_HOME="/path/to/trusted-intermediary" -# You'll also need to set the path to the keys if running in a non-local environment - -# Load organization settings -./prime multiple-settings set -s -i ./settings/STLTs/Flexion/flexion.yml -./prime multiple-settings set -s -i ./settings/STLTs/CA/ucsd.yml -./prime multiple-settings set -s -i ./settings/STLTs/LA/la-phl.yml -./prime multiple-settings set -s -i ./settings/STLTs/LA/la-ochsner.yml - -# Add public keys for senders -./prime organization addkey --public-key "$TI_LOCAL_PUBLIC_KEY_PATH" --scope "flexion.*.report" --orgName flexion --kid flexion.etor-service-sender --doit -./prime organization addkey --public-key "$TI_LOCAL_PUBLIC_KEY_PATH" --scope "flexion.*.report" --orgName flexion --kid flexion.simulated-hospital --doit -./prime organization addkey --public-key "$TI_LOCAL_PUBLIC_KEY_PATH" --scope "flexion.*.report" --orgName flexion --kid flexion.simulated-lab --doit -./prime organization addkey --public-key "$TI_LOCAL_PUBLIC_KEY_PATH" --scope "flexion.*.report" --orgName flexion --kid flexion.simulated-sender --doit diff --git a/scripts/rs/setup-local-vault.sh b/scripts/rs/setup-local-vault.sh deleted file mode 100755 index 69ce3eed6..000000000 --- a/scripts/rs/setup-local-vault.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env bash - -# This script loads the credentials into the local vault to set up the ETOR receivers. -# NOTE: Remember to run this script inside the prime-router directory of the prime-reportstream codebase -# Make sure to add a CDCTI_HOME environment variable pointing to the trusted-intermediary directory -# export CDCTI_HOME="/path/to/trusted-intermediary" - -source "$RS_HOME/prime-router/.vault/env/.env.local" - -./prime create-credential --type UserPass --user foo --pass pass --persist DEFAULT-SFTP - -rs_private_key=$(cat "$RS_LOCAL_PRIVATE_KEY_PATH") -./prime create-credential --type UserApiKey --apikey-user flexion --apikey "$rs_private_key" --persist FLEXION--ETOR-SERVICE-RECEIVER-ORDERS -./prime create-credential --type UserApiKey --apikey-user flexion --apikey "$rs_private_key" --persist FLEXION--ETOR-SERVICE-RECEIVER-RESULTS -./prime create-credential --type UserApiKey --apikey-user ucsd --apikey "$rs_private_key" --persist UCSD--ETOR-NBS-RESULTS -./prime create-credential --type UserApiKey --apikey-user la-phl --apikey "$rs_private_key" --persist LA-PHL--ETOR-NBS-ORDERS -./prime create-credential --type UserApiKey --apikey-user la-ochsner --apikey "$rs_private_key" --persist LA-OCHSNER--ETOR-NBS-RESULTS diff --git a/scripts/rs/setup.sh b/scripts/rs/setup.sh index d3a332a53..ec04ed8e7 100755 --- a/scripts/rs/setup.sh +++ b/scripts/rs/setup.sh @@ -1,15 +1,81 @@ #!/usr/bin/env bash -CURRENT_DIR=$(pwd) +[ -z "${CDCTI_HOME}" ] && echo "Error: Environment variable CDCTI_HOME is not set" && exit 1 +source "$CDCTI_HOME/scripts/utils.sh" -# This script resets the database and loads the baseline settings. -# NOTE: Remember to run this script inside the prime-router directory of the prime-reportstream codebase +# Check requirements for this script +check_env_vars RS_HOME +check_installed_commands yq # Need to CD to the RS codebase local working copy to run the gradlew commands +CURRENT_DIR=$(pwd) cd "$RS_HOME" || exit +# source "./prime-router/.vault/env/.env.local" + +echo "Resetting the database and loading the baseline settings..." ./gradlew resetDB ./gradlew reloadTable ./gradlew reloadSettings +# Need to CD to prime-router to run the prime CLI +cd "prime-router" || exit + +echo "Updating transport settings in Flexion org file..." +yq eval '.[0].receivers[] |= ( + select(.name == "etor-service-receiver-orders") |= ( + .transport.authTokenUrl = "__TI_API_URL__/v1/auth/token" | + .transport.reportUrl = "__TI_API_URL__/v1/etor/orders" | + .transport.authHeaders.Host = "__TI_API_HOST__" + ) | + select(.name == "etor-service-receiver-results") |= ( + .transport.authTokenUrl = "__TI_API_URL__/v1/auth/token" | + .transport.reportUrl = "__TI_API_URL__/v1/etor/results" | + .transport.authHeaders.Host = "__TI_API_HOST__" + ) | + select(.name == "simulated-hospital" or .name == "simulated-lab").transport = { + "type": "SFTP", + "host": "sftp", + "port": 22, + "filePath": "./upload", + "credentialName": "DEFAULT-SFTP" + } +)' -i "settings/STLTs/Flexion/flexion.yml" + +echo "Updating local URL and host in transport settings..." +sed -i '' "s|__TI_API_URL__|${TI_LCL_API_URL}|g" "settings/STLTs/Flexion/flexion.yml" +sed -i '' "s|__TI_API_HOST__|$(extract_host_from_url ${TI_LCL_API_URL})|g" "settings/STLTs/Flexion/flexion.yml" + +echo "Updating transport settings in partner org files..." +for file in "settings/STLTs/CA/ucsd.yml" "settings/STLTs/LA/la-ochsner.yml" "settings/STLTs/LA/la-phl.yml"; do + yq eval '.[0].receivers[] |= select(.name == "etor-nbs-results" or .name == "etor-nbs-orders").transport = { + "type": "SFTP", + "host": "sftp", + "port": 22, + "filePath": "./upload", + "credentialName": "DEFAULT-SFTP" + }' -i "$file" +done + +echo "Setting up the organization settings..." +./prime multiple-settings set -s -i ./settings/STLTs/Flexion/flexion.yml +./prime multiple-settings set -s -i ./settings/STLTs/CA/ucsd.yml +./prime multiple-settings set -s -i ./settings/STLTs/LA/la-phl.yml +./prime multiple-settings set -s -i ./settings/STLTs/LA/la-ochsner.yml + +echo "Adding public keys for senders..." +./prime organization addkey --public-key "$TI_LOCAL_PUBLIC_KEY_PATH" --scope "flexion.*.report" --orgName flexion --kid flexion.etor-service-sender --doit +./prime organization addkey --public-key "$TI_LOCAL_PUBLIC_KEY_PATH" --scope "flexion.*.report" --orgName flexion --kid flexion.simulated-hospital --doit +./prime organization addkey --public-key "$TI_LOCAL_PUBLIC_KEY_PATH" --scope "flexion.*.report" --orgName flexion --kid flexion.simulated-lab --doit +./prime organization addkey --public-key "$TI_LOCAL_PUBLIC_KEY_PATH" --scope "flexion.*.report" --orgName flexion --kid flexion.simulated-sender --doit + +echo "Adding credentials for receivers..." +./prime create-credential --type UserPass --user foo --pass pass --persist DEFAULT-SFTP +rs_private_key=$(cat "$RS_LOCAL_PRIVATE_KEY_PATH") +./prime create-credential --type UserApiKey --apikey-user flexion --apikey "$rs_private_key" --persist FLEXION--ETOR-SERVICE-RECEIVER-ORDERS +./prime create-credential --type UserApiKey --apikey-user flexion --apikey "$rs_private_key" --persist FLEXION--ETOR-SERVICE-RECEIVER-RESULTS +./prime create-credential --type UserApiKey --apikey-user ucsd --apikey "$rs_private_key" --persist UCSD--ETOR-NBS-RESULTS +./prime create-credential --type UserApiKey --apikey-user la-phl --apikey "$rs_private_key" --persist LA-PHL--ETOR-NBS-ORDERS +./prime create-credential --type UserApiKey --apikey-user la-ochsner --apikey "$rs_private_key" --persist LA-OCHSNER--ETOR-NBS-RESULTS + cd "$CURRENT_DIR" || exit diff --git a/scripts/rs/update_org_yaml.sh b/scripts/rs/update_org_yaml.sh deleted file mode 100755 index 2360b35e9..000000000 --- a/scripts/rs/update_org_yaml.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/bash - -[ -z "${CDCTI_HOME}" ] && echo "Error: Environment variable CDCTI_HOME is not set" && exit 1 -source "$CDCTI_HOME/scripts/utils.sh" - -# This script updates the organization settings YAML files in RS to: -# - use local REST transport settings for Flexion's etor-service-receiver receivers -# - use local SFTP transport settings for Flexion's simulated-hospital and simulated-lab receivers -# - use local SFTP transport settings for partner organizations - -# Requirements: -# - yq (https://github.com/mikefarah/yq) -# - This script should run inside the prime-router directory of the prime-reportstream codebase - -ORG_SETTINGS_DIR="settings/STLTs" - -check_installed_commands yq - -echo "Updating transport in Flexion org settings file..." -yq eval '.[0].receivers[] |= ( - select(.name == "simulated-hospital" or .name == "simulated-lab").transport = { - "type": "SFTP", - "host": "sftp", - "port": 22, - "filePath": "./upload", - "credentialName": "DEFAULT-SFTP" - } | - select(.name == "etor-service-receiver-orders") |= ( - .transport.authTokenUrl = "http://host.docker.internal:8080/v1/auth/token" | - .transport.reportUrl = "http://host.docker.internal:8080/v1/etor/orders" - ) | - select(.name == "etor-service-receiver-results") |= ( - .transport.authTokenUrl = "http://host.docker.internal:8080/v1/auth/token" | - .transport.reportUrl = "http://host.docker.internal:8080/v1/etor/results" - ) -)' -i "$ORG_SETTINGS_DIR/Flexion/flexion.yml" - -echo "Updating transport in partner org settings files..." -for file in "$ORG_SETTINGS_DIR/CA/ucsd.yml" "$ORG_SETTINGS_DIR/LA/la-ochsner.yml" "$ORG_SETTINGS_DIR/LA/la-phl.yml"; do - yq eval '.[0].receivers[] |= select(.name == "etor-nbs-results" or .name == "etor-nbs-orders").transport = { - "type": "SFTP", - "host": "sftp", - "port": 22, - "filePath": "./upload", - "credentialName": "DEFAULT-SFTP" - }' -i "$file" -done - -echo "Updates completed." diff --git a/scripts/utils.sh b/scripts/utils.sh index 10d2aea50..43600b3c8 100755 --- a/scripts/utils.sh +++ b/scripts/utils.sh @@ -45,3 +45,38 @@ check_apis() { fi done } + +get_api_url() { + local env=$1 + local type=$2 + + case "$type" in + "rs") + case "$env" in + "local") echo $RS_LCL_API_URL ;; + "staging") echo $RS_STG_API_URL ;; + "production") echo $RS_PRD_API_URL ;; + *) + echo "Invalid environment: $env" >&2 + exit 1 + ;; + esac + ;; + "ti") + case "$env" in + "local") echo $TI_LCL_API_URL ;; + "staging") echo $TI_STG_API_URL ;; + "production") echo $TI_PRD_API_URL ;; + *) + echo "Invalid environment: $env" >&2 + exit 1 + ;; + esac + ;; + esac +} + +extract_host_from_url() { + local url=$1 + echo "$url" | sed 's|^.*://\([^/:]*\)[:/].*|\1|' +} From 4197def3e6dd6f4d65fd88454dd1ec872a33b7db Mon Sep 17 00:00:00 2001 From: Basilio Bogado <541149+basiliskus@users.noreply.github.com> Date: Tue, 29 Oct 2024 16:29:50 -0700 Subject: [PATCH 08/29] Moved rs/setup.sh to setup-rs.sh and removed rs/ folder --- scripts/rs/README.md | 3 --- scripts/{rs/setup.sh => setup-rs.sh} | 0 2 files changed, 3 deletions(-) delete mode 100644 scripts/rs/README.md rename scripts/{rs/setup.sh => setup-rs.sh} (100%) diff --git a/scripts/rs/README.md b/scripts/rs/README.md deleted file mode 100644 index ebf318acf..000000000 --- a/scripts/rs/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# ReportStream Scripts - -The scripts in this folder are meant to be copied and run in the [prime-reportstream](https://github.com/CDCgov/prime-reportstream) codebase inside the `prime-router` folder. You can also create symbolic links instead of copying the files in order to keep them up-to-date. diff --git a/scripts/rs/setup.sh b/scripts/setup-rs.sh similarity index 100% rename from scripts/rs/setup.sh rename to scripts/setup-rs.sh From 9af09853d495c34e933361ad2e318f3719f8eaa5 Mon Sep 17 00:00:00 2001 From: Basilio Bogado <541149+basiliskus@users.noreply.github.com> Date: Tue, 29 Oct 2024 16:49:56 -0700 Subject: [PATCH 09/29] Updated RS setup instructions in readme to: - Use new setup-rs.sh script - Add alternate ways to build and run RS - Fixed RS docs URL - Clean up and simplify --- README.md | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index dbc6dcde4..722ee07c1 100644 --- a/README.md +++ b/README.md @@ -341,17 +341,14 @@ After enabling this option it is recommended that you delete all docker images a with this option enabled. 1. Checkout `master` branch for `CDCgov/prime-reportstream` -2. Create a symbolic link or copy the scripts found at [/scripts/rs](/scripts/rs) to `prime-reportstream/prime-router` - - **Note**: follow the instructions in [/scripts/rs/readme.md](/scripts/rs/readme.md) to set up the environment variable -3. CD to `prime-reportstream/prime-router` -4. Run the `./cleanslate` script. For more information you can refer to the [ReportStream docs](https://github.com/CDCgov/prime-reportstream/blob/master/prime-router/docs/docs-deprecated/getting-started/getting-started.md#building-the-baseline) -5. If attempting to access the metadata endpoint in ReportStream add the variable `ETOR_TI_baseurl="http://host.docker.internal:8080"` to `.prime-router/.vault/env/.env.local` file before building the container -6. Run RS with `docker compose up --build -d` -7. Run the `reset.sh` script to reset the database -8. Run the `update_org_yaml.sh` script to update the RS organization settings -9. Run the `load-etor-org-settings.sh` to apply the ETOR organization settings -10. Run the `setup-local-vault.sh` script to set up the local vault secrets - - You can verify that the script created the secrets successfully by going to `http://localhost:8200/` in your browser, use the token in `prime-router/.vault/env/.env.local` to authenticate, and then go to `Secrets engines` > `secret/` to check the available secrets +2. Build RS (for more information please refer to the [ReportStream docs](https://github.com/CDCgov/prime-reportstream/blob/master/prime-router/docs/getting-started/README.md)): + - If building for the first time, run: `./cleanslate` in `prime-reportstream/prime-router` + - Otherwise run: `./gradlew clean package` in `prime-reportstream` root folder + - If attempting to access the metadata endpoint in RS add the variable `ETOR_TI_baseurl="http://host.docker.internal:8080"` to `prime-router/.vault/env/.env.local` file before building the container +3. Run RS with `docker compose up -d`. You may also use `./gradlew quickRun` +4. Run the RS setup script in this repository: `/scripts/setup-rs.sh` + - Before running the script, make sure to follow the instructions in [/scripts/README.md](/scripts/README.md) + - You can verify that the script created the secrets successfully by going to `http://localhost:8200/` in your browser, use the token in `prime-router/.vault/env/.env.local` to authenticate, and then go to `Secrets engines` > `secret/` to check the available secrets #### Submit request to ReportStream From 9e059aa75a6979c70c47beca66c95cd16ade9fef Mon Sep 17 00:00:00 2001 From: Basilio Bogado <541149+basiliskus@users.noreply.github.com> Date: Tue, 29 Oct 2024 17:09:17 -0700 Subject: [PATCH 10/29] Moved files to reorganize and simplify file structure --- scripts/{hurl => }/epic.sh | 0 scripts/{hurl/utils.sh => helper.sh} | 0 scripts/hurl/{epic/results.hurl => epic-results.hurl} | 0 scripts/hurl/{rs/delivery.hurl => rs-delivery.hurl} | 0 scripts/hurl/{rs/history.hurl => rs-history.hurl} | 0 scripts/hurl/{rs/token.hurl => rs-token.hurl} | 0 scripts/hurl/{rs/waters.hurl => rs-waters.hurl} | 0 scripts/hurl/{ti/auth.hurl => ti-auth.hurl} | 0 scripts/hurl/{ti/health.hurl => ti-health.hurl} | 0 scripts/hurl/{ti/metadata.hurl => ti-metadata.hurl} | 0 scripts/hurl/{ti/openapi.hurl => ti-openapi.hurl} | 0 scripts/hurl/{ti/orders.hurl => ti-orders.hurl} | 0 scripts/hurl/{ti/results.hurl => ti-results.hurl} | 0 scripts/{hurl => }/rs.sh | 0 scripts/{hurl/submit_message.sh => submit-message.sh} | 0 scripts/{hurl => }/ti.sh | 0 scripts/{hurl/update_examples.sh => update-examples.sh} | 0 17 files changed, 0 insertions(+), 0 deletions(-) rename scripts/{hurl => }/epic.sh (100%) rename scripts/{hurl/utils.sh => helper.sh} (100%) rename scripts/hurl/{epic/results.hurl => epic-results.hurl} (100%) rename scripts/hurl/{rs/delivery.hurl => rs-delivery.hurl} (100%) rename scripts/hurl/{rs/history.hurl => rs-history.hurl} (100%) rename scripts/hurl/{rs/token.hurl => rs-token.hurl} (100%) rename scripts/hurl/{rs/waters.hurl => rs-waters.hurl} (100%) rename scripts/hurl/{ti/auth.hurl => ti-auth.hurl} (100%) rename scripts/hurl/{ti/health.hurl => ti-health.hurl} (100%) rename scripts/hurl/{ti/metadata.hurl => ti-metadata.hurl} (100%) rename scripts/hurl/{ti/openapi.hurl => ti-openapi.hurl} (100%) rename scripts/hurl/{ti/orders.hurl => ti-orders.hurl} (100%) rename scripts/hurl/{ti/results.hurl => ti-results.hurl} (100%) rename scripts/{hurl => }/rs.sh (100%) rename scripts/{hurl/submit_message.sh => submit-message.sh} (100%) rename scripts/{hurl => }/ti.sh (100%) rename scripts/{hurl/update_examples.sh => update-examples.sh} (100%) diff --git a/scripts/hurl/epic.sh b/scripts/epic.sh similarity index 100% rename from scripts/hurl/epic.sh rename to scripts/epic.sh diff --git a/scripts/hurl/utils.sh b/scripts/helper.sh similarity index 100% rename from scripts/hurl/utils.sh rename to scripts/helper.sh diff --git a/scripts/hurl/epic/results.hurl b/scripts/hurl/epic-results.hurl similarity index 100% rename from scripts/hurl/epic/results.hurl rename to scripts/hurl/epic-results.hurl diff --git a/scripts/hurl/rs/delivery.hurl b/scripts/hurl/rs-delivery.hurl similarity index 100% rename from scripts/hurl/rs/delivery.hurl rename to scripts/hurl/rs-delivery.hurl diff --git a/scripts/hurl/rs/history.hurl b/scripts/hurl/rs-history.hurl similarity index 100% rename from scripts/hurl/rs/history.hurl rename to scripts/hurl/rs-history.hurl diff --git a/scripts/hurl/rs/token.hurl b/scripts/hurl/rs-token.hurl similarity index 100% rename from scripts/hurl/rs/token.hurl rename to scripts/hurl/rs-token.hurl diff --git a/scripts/hurl/rs/waters.hurl b/scripts/hurl/rs-waters.hurl similarity index 100% rename from scripts/hurl/rs/waters.hurl rename to scripts/hurl/rs-waters.hurl diff --git a/scripts/hurl/ti/auth.hurl b/scripts/hurl/ti-auth.hurl similarity index 100% rename from scripts/hurl/ti/auth.hurl rename to scripts/hurl/ti-auth.hurl diff --git a/scripts/hurl/ti/health.hurl b/scripts/hurl/ti-health.hurl similarity index 100% rename from scripts/hurl/ti/health.hurl rename to scripts/hurl/ti-health.hurl diff --git a/scripts/hurl/ti/metadata.hurl b/scripts/hurl/ti-metadata.hurl similarity index 100% rename from scripts/hurl/ti/metadata.hurl rename to scripts/hurl/ti-metadata.hurl diff --git a/scripts/hurl/ti/openapi.hurl b/scripts/hurl/ti-openapi.hurl similarity index 100% rename from scripts/hurl/ti/openapi.hurl rename to scripts/hurl/ti-openapi.hurl diff --git a/scripts/hurl/ti/orders.hurl b/scripts/hurl/ti-orders.hurl similarity index 100% rename from scripts/hurl/ti/orders.hurl rename to scripts/hurl/ti-orders.hurl diff --git a/scripts/hurl/ti/results.hurl b/scripts/hurl/ti-results.hurl similarity index 100% rename from scripts/hurl/ti/results.hurl rename to scripts/hurl/ti-results.hurl diff --git a/scripts/hurl/rs.sh b/scripts/rs.sh similarity index 100% rename from scripts/hurl/rs.sh rename to scripts/rs.sh diff --git a/scripts/hurl/submit_message.sh b/scripts/submit-message.sh similarity index 100% rename from scripts/hurl/submit_message.sh rename to scripts/submit-message.sh diff --git a/scripts/hurl/ti.sh b/scripts/ti.sh similarity index 100% rename from scripts/hurl/ti.sh rename to scripts/ti.sh diff --git a/scripts/hurl/update_examples.sh b/scripts/update-examples.sh similarity index 100% rename from scripts/hurl/update_examples.sh rename to scripts/update-examples.sh From abb1c74c329d09c86a372c22f9517784d685e2fd Mon Sep 17 00:00:00 2001 From: Basilio Bogado <541149+basiliskus@users.noreply.github.com> Date: Tue, 29 Oct 2024 17:14:21 -0700 Subject: [PATCH 11/29] Updated paths --- scripts/epic.sh | 4 ++-- scripts/rs.sh | 4 ++-- scripts/submit-message.sh | 2 +- scripts/ti.sh | 4 ++-- scripts/update-examples.sh | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/scripts/epic.sh b/scripts/epic.sh index e041bbcd4..64013efb1 100755 --- a/scripts/epic.sh +++ b/scripts/epic.sh @@ -2,7 +2,7 @@ [ -z "${CDCTI_HOME}" ] && echo "Error: Environment variable CDCTI_HOME is not set" && exit 1 source "$CDCTI_HOME/scripts/utils.sh" -source "$CDCTI_HOME/scripts/hurl/utils.sh" +source "$CDCTI_HOME/scripts/helper.sh" client= audience=https://epicproxy-np.et0502.epichosted.com/FhirProxy/oauth2/token @@ -17,5 +17,5 @@ hurl \ --variable "fpath=$fpath" \ --file-root "$root" \ --variable "jwt=$jwt_token" \ - epic/results.hurl \ + hurl/epic-results.hurl \ $@ diff --git a/scripts/rs.sh b/scripts/rs.sh index 26c5bac9e..9c3a5f994 100755 --- a/scripts/rs.sh +++ b/scripts/rs.sh @@ -2,7 +2,7 @@ [ -z "${CDCTI_HOME}" ] && echo "Error: Environment variable CDCTI_HOME is not set" && exit 1 source "$CDCTI_HOME/scripts/utils.sh" -source "$CDCTI_HOME/scripts/hurl/utils.sh" +source "$CDCTI_HOME/scripts/helper.sh" # default values env=local @@ -42,7 +42,7 @@ parse_arguments() { fi [ $# -eq 0 ] && fail "Missing required argument " - endpoint_name="rs/$1.hurl" + endpoint_name="hurl/rs-$1.hurl" shift # Remove endpoint name from args while getopts ':f:r:t:e:c:s:k:i:v' opt; do diff --git a/scripts/submit-message.sh b/scripts/submit-message.sh index 9440a6872..995f7ec19 100755 --- a/scripts/submit-message.sh +++ b/scripts/submit-message.sh @@ -2,7 +2,7 @@ [ -z "${CDCTI_HOME}" ] && echo "Error: Environment variable CDCTI_HOME is not set" && exit 1 source "$CDCTI_HOME/scripts/utils.sh" -source "$CDCTI_HOME/scripts/hurl/utils.sh" +source "$CDCTI_HOME/scripts/helper.sh" env="local" diff --git a/scripts/ti.sh b/scripts/ti.sh index 4769c391e..467eeb0f8 100755 --- a/scripts/ti.sh +++ b/scripts/ti.sh @@ -2,7 +2,7 @@ [ -z "${CDCTI_HOME}" ] && echo "Error: Environment variable CDCTI_HOME is not set" && exit 1 source "$CDCTI_HOME/scripts/utils.sh" -source "$CDCTI_HOME/scripts/hurl/utils.sh" +source "$CDCTI_HOME/scripts/helper.sh" # default values env=local @@ -38,7 +38,7 @@ parse_arguments() { fi [ $# -eq 0 ] && fail "Missing required argument " - endpoint_name="ti/$1.hurl" + endpoint_name="hurl/ti-$1.hurl" shift # Remove endpoint name from args while getopts ':f:r:e:c:k:i:v' opt; do diff --git a/scripts/update-examples.sh b/scripts/update-examples.sh index 6c9728708..6eb954973 100755 --- a/scripts/update-examples.sh +++ b/scripts/update-examples.sh @@ -2,7 +2,7 @@ [ -z "${CDCTI_HOME}" ] && echo "Error: Environment variable CDCTI_HOME is not set" && exit 1 source "$CDCTI_HOME/scripts/utils.sh" -source "$CDCTI_HOME/scripts/hurl/utils.sh" +source "$CDCTI_HOME/scripts/helper.sh" env=local From 08d7789f371b65c52380af70bea98c409b9f3b82 Mon Sep 17 00:00:00 2001 From: Basilio Bogado <541149+basiliskus@users.noreply.github.com> Date: Wed, 30 Oct 2024 05:58:27 -0700 Subject: [PATCH 12/29] Reverted moving hurl files --- scripts/epic.sh | 2 +- scripts/hurl/{epic-results.hurl => epic/results.hurl} | 0 scripts/hurl/{rs-delivery.hurl => rs/delivery.hurl} | 0 scripts/hurl/{rs-history.hurl => rs/history.hurl} | 0 scripts/hurl/{rs-token.hurl => rs/token.hurl} | 0 scripts/hurl/{rs-waters.hurl => rs/waters.hurl} | 0 scripts/hurl/{ti-auth.hurl => ti/auth.hurl} | 0 scripts/hurl/{ti-health.hurl => ti/health.hurl} | 0 scripts/hurl/{ti-metadata.hurl => ti/metadata.hurl} | 0 scripts/hurl/{ti-openapi.hurl => ti/openapi.hurl} | 0 scripts/hurl/{ti-orders.hurl => ti/orders.hurl} | 0 scripts/hurl/{ti-results.hurl => ti/results.hurl} | 0 scripts/rs.sh | 2 +- scripts/ti.sh | 2 +- 14 files changed, 3 insertions(+), 3 deletions(-) rename scripts/hurl/{epic-results.hurl => epic/results.hurl} (100%) rename scripts/hurl/{rs-delivery.hurl => rs/delivery.hurl} (100%) rename scripts/hurl/{rs-history.hurl => rs/history.hurl} (100%) rename scripts/hurl/{rs-token.hurl => rs/token.hurl} (100%) rename scripts/hurl/{rs-waters.hurl => rs/waters.hurl} (100%) rename scripts/hurl/{ti-auth.hurl => ti/auth.hurl} (100%) rename scripts/hurl/{ti-health.hurl => ti/health.hurl} (100%) rename scripts/hurl/{ti-metadata.hurl => ti/metadata.hurl} (100%) rename scripts/hurl/{ti-openapi.hurl => ti/openapi.hurl} (100%) rename scripts/hurl/{ti-orders.hurl => ti/orders.hurl} (100%) rename scripts/hurl/{ti-results.hurl => ti/results.hurl} (100%) diff --git a/scripts/epic.sh b/scripts/epic.sh index 64013efb1..2420a70e8 100755 --- a/scripts/epic.sh +++ b/scripts/epic.sh @@ -17,5 +17,5 @@ hurl \ --variable "fpath=$fpath" \ --file-root "$root" \ --variable "jwt=$jwt_token" \ - hurl/epic-results.hurl \ + epic/results.hurl \ $@ diff --git a/scripts/hurl/epic-results.hurl b/scripts/hurl/epic/results.hurl similarity index 100% rename from scripts/hurl/epic-results.hurl rename to scripts/hurl/epic/results.hurl diff --git a/scripts/hurl/rs-delivery.hurl b/scripts/hurl/rs/delivery.hurl similarity index 100% rename from scripts/hurl/rs-delivery.hurl rename to scripts/hurl/rs/delivery.hurl diff --git a/scripts/hurl/rs-history.hurl b/scripts/hurl/rs/history.hurl similarity index 100% rename from scripts/hurl/rs-history.hurl rename to scripts/hurl/rs/history.hurl diff --git a/scripts/hurl/rs-token.hurl b/scripts/hurl/rs/token.hurl similarity index 100% rename from scripts/hurl/rs-token.hurl rename to scripts/hurl/rs/token.hurl diff --git a/scripts/hurl/rs-waters.hurl b/scripts/hurl/rs/waters.hurl similarity index 100% rename from scripts/hurl/rs-waters.hurl rename to scripts/hurl/rs/waters.hurl diff --git a/scripts/hurl/ti-auth.hurl b/scripts/hurl/ti/auth.hurl similarity index 100% rename from scripts/hurl/ti-auth.hurl rename to scripts/hurl/ti/auth.hurl diff --git a/scripts/hurl/ti-health.hurl b/scripts/hurl/ti/health.hurl similarity index 100% rename from scripts/hurl/ti-health.hurl rename to scripts/hurl/ti/health.hurl diff --git a/scripts/hurl/ti-metadata.hurl b/scripts/hurl/ti/metadata.hurl similarity index 100% rename from scripts/hurl/ti-metadata.hurl rename to scripts/hurl/ti/metadata.hurl diff --git a/scripts/hurl/ti-openapi.hurl b/scripts/hurl/ti/openapi.hurl similarity index 100% rename from scripts/hurl/ti-openapi.hurl rename to scripts/hurl/ti/openapi.hurl diff --git a/scripts/hurl/ti-orders.hurl b/scripts/hurl/ti/orders.hurl similarity index 100% rename from scripts/hurl/ti-orders.hurl rename to scripts/hurl/ti/orders.hurl diff --git a/scripts/hurl/ti-results.hurl b/scripts/hurl/ti/results.hurl similarity index 100% rename from scripts/hurl/ti-results.hurl rename to scripts/hurl/ti/results.hurl diff --git a/scripts/rs.sh b/scripts/rs.sh index 9c3a5f994..e27a0d6f4 100755 --- a/scripts/rs.sh +++ b/scripts/rs.sh @@ -42,7 +42,7 @@ parse_arguments() { fi [ $# -eq 0 ] && fail "Missing required argument " - endpoint_name="hurl/rs-$1.hurl" + endpoint_name="hurl/rs/$1.hurl" shift # Remove endpoint name from args while getopts ':f:r:t:e:c:s:k:i:v' opt; do diff --git a/scripts/ti.sh b/scripts/ti.sh index 467eeb0f8..b9d6b1d96 100755 --- a/scripts/ti.sh +++ b/scripts/ti.sh @@ -38,7 +38,7 @@ parse_arguments() { fi [ $# -eq 0 ] && fail "Missing required argument " - endpoint_name="hurl/ti-$1.hurl" + endpoint_name="hurl/ti/$1.hurl" shift # Remove endpoint name from args while getopts ':f:r:e:c:k:i:v' opt; do From dc77d21e9a6e73caae8dd0feb273fd65c211d333 Mon Sep 17 00:00:00 2001 From: Basilio Bogado <541149+basiliskus@users.noreply.github.com> Date: Wed, 30 Oct 2024 06:09:26 -0700 Subject: [PATCH 13/29] Moved and renamed function scripts --- scripts/epic.sh | 4 ++-- scripts/{utils.sh => lib/common.sh} | 0 scripts/{helper.sh => lib/submission-utils.sh} | 0 scripts/rs.sh | 4 ++-- scripts/setup-rs.sh | 2 +- scripts/submit-message.sh | 4 ++-- scripts/ti.sh | 4 ++-- scripts/update-examples.sh | 4 ++-- 8 files changed, 11 insertions(+), 11 deletions(-) rename scripts/{utils.sh => lib/common.sh} (100%) rename scripts/{helper.sh => lib/submission-utils.sh} (100%) diff --git a/scripts/epic.sh b/scripts/epic.sh index 2420a70e8..59022f7d4 100755 --- a/scripts/epic.sh +++ b/scripts/epic.sh @@ -1,8 +1,8 @@ #!/bin/bash [ -z "${CDCTI_HOME}" ] && echo "Error: Environment variable CDCTI_HOME is not set" && exit 1 -source "$CDCTI_HOME/scripts/utils.sh" -source "$CDCTI_HOME/scripts/helper.sh" +source "$CDCTI_HOME/scripts/lib/common.sh" +source "$CDCTI_HOME/scripts/lib/submission-utils.sh" client= audience=https://epicproxy-np.et0502.epichosted.com/FhirProxy/oauth2/token diff --git a/scripts/utils.sh b/scripts/lib/common.sh similarity index 100% rename from scripts/utils.sh rename to scripts/lib/common.sh diff --git a/scripts/helper.sh b/scripts/lib/submission-utils.sh similarity index 100% rename from scripts/helper.sh rename to scripts/lib/submission-utils.sh diff --git a/scripts/rs.sh b/scripts/rs.sh index e27a0d6f4..dbb57c7ba 100755 --- a/scripts/rs.sh +++ b/scripts/rs.sh @@ -1,8 +1,8 @@ #!/bin/bash [ -z "${CDCTI_HOME}" ] && echo "Error: Environment variable CDCTI_HOME is not set" && exit 1 -source "$CDCTI_HOME/scripts/utils.sh" -source "$CDCTI_HOME/scripts/helper.sh" +source "$CDCTI_HOME/scripts/lib/common.sh" +source "$CDCTI_HOME/scripts/lib/submission-utils.sh" # default values env=local diff --git a/scripts/setup-rs.sh b/scripts/setup-rs.sh index ec04ed8e7..bd9fe3f96 100755 --- a/scripts/setup-rs.sh +++ b/scripts/setup-rs.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash [ -z "${CDCTI_HOME}" ] && echo "Error: Environment variable CDCTI_HOME is not set" && exit 1 -source "$CDCTI_HOME/scripts/utils.sh" +source "$CDCTI_HOME/scripts/lib/common.sh" # Check requirements for this script check_env_vars RS_HOME diff --git a/scripts/submit-message.sh b/scripts/submit-message.sh index 995f7ec19..c226807e8 100755 --- a/scripts/submit-message.sh +++ b/scripts/submit-message.sh @@ -1,8 +1,8 @@ #!/bin/bash [ -z "${CDCTI_HOME}" ] && echo "Error: Environment variable CDCTI_HOME is not set" && exit 1 -source "$CDCTI_HOME/scripts/utils.sh" -source "$CDCTI_HOME/scripts/helper.sh" +source "$CDCTI_HOME/scripts/lib/common.sh" +source "$CDCTI_HOME/scripts/lib/submission-utils.sh" env="local" diff --git a/scripts/ti.sh b/scripts/ti.sh index b9d6b1d96..b13404e9c 100755 --- a/scripts/ti.sh +++ b/scripts/ti.sh @@ -1,8 +1,8 @@ #!/bin/bash [ -z "${CDCTI_HOME}" ] && echo "Error: Environment variable CDCTI_HOME is not set" && exit 1 -source "$CDCTI_HOME/scripts/utils.sh" -source "$CDCTI_HOME/scripts/helper.sh" +source "$CDCTI_HOME/scripts/lib/common.sh" +source "$CDCTI_HOME/scripts/lib/submission-utils.sh" # default values env=local diff --git a/scripts/update-examples.sh b/scripts/update-examples.sh index 6eb954973..86dc697e8 100755 --- a/scripts/update-examples.sh +++ b/scripts/update-examples.sh @@ -1,8 +1,8 @@ #!/bin/bash [ -z "${CDCTI_HOME}" ] && echo "Error: Environment variable CDCTI_HOME is not set" && exit 1 -source "$CDCTI_HOME/scripts/utils.sh" -source "$CDCTI_HOME/scripts/helper.sh" +source "$CDCTI_HOME/scripts/lib/common.sh" +source "$CDCTI_HOME/scripts/lib/submission-utils.sh" env=local From 5e700e7c5c13813a515800117715fb7cbf77efc7 Mon Sep 17 00:00:00 2001 From: Basilio Bogado <541149+basiliskus@users.noreply.github.com> Date: Wed, 30 Oct 2024 06:35:09 -0700 Subject: [PATCH 14/29] Moved and renamed more scripts + added to readme --- README.md | 2 +- scripts/README.md | 216 ++++++++++++++++++ .../setup-reportstream.sh} | 0 .../update-examples-snapshots.sh} | 0 scripts/{submit-message.sh => submit.sh} | 0 5 files changed, 217 insertions(+), 1 deletion(-) rename scripts/{setup-rs.sh => setup/setup-reportstream.sh} (100%) rename scripts/{update-examples.sh => setup/update-examples-snapshots.sh} (100%) rename scripts/{submit-message.sh => submit.sh} (100%) diff --git a/README.md b/README.md index 722ee07c1..54843a054 100644 --- a/README.md +++ b/README.md @@ -346,7 +346,7 @@ with this option enabled. - Otherwise run: `./gradlew clean package` in `prime-reportstream` root folder - If attempting to access the metadata endpoint in RS add the variable `ETOR_TI_baseurl="http://host.docker.internal:8080"` to `prime-router/.vault/env/.env.local` file before building the container 3. Run RS with `docker compose up -d`. You may also use `./gradlew quickRun` -4. Run the RS setup script in this repository: `/scripts/setup-rs.sh` +4. Run the RS setup script in this repository: `/scripts/setup/setup-reportstream.sh` - Before running the script, make sure to follow the instructions in [/scripts/README.md](/scripts/README.md) - You can verify that the script created the secrets successfully by going to `http://localhost:8200/` in your browser, use the token in `prime-router/.vault/env/.env.local` to authenticate, and then go to `Secrets engines` > `secret/` to check the available secrets diff --git a/scripts/README.md b/scripts/README.md index 8f8d570cf..af58b2ea1 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -13,3 +13,219 @@ ``` **Note**: you may also want to add it to your shell's startup file so you don't need to run it for every terminal session. 4. Run you script + +## Available Scripts + +### submit.sh + +Sends a HL7 message to RS and tracks its status throughout the flow until final delivery. When running locally, it grabs the snapshots of the file in azurite after converting to FHIR, after applying transformations in TI, and after converting back to HL7; and it copies those files to the same folder where the submitted file is. If running in a deployed environment we currently don't have a way to download the files from Azure, but the script will print the relative path for the files in the blob storage container. + +#### Requirements + +- hurl +- jq +- azure-cli + +#### Usage + +``` +Usage: submit.sh -f [-e ] + +Options: + -f Message file path (Required) + -e Environment: local|staging|production (Default: ) + -x Path to the client private key for authentication with RS API (Required for non-local environments) + -z Path to the client private key for authentication with TI API (Optional for all environments) + -h Display this help and exit +``` + +### rs.sh + +#### Requirements + +- hurl +- jwt-cli + +#### Usage + +``` +Usage: ./rs.sh [OPTIONS] + +ENDPOINT_NAME: + The name of the endpoint to call (required) + +Options: + -f Path to the hl7/fhir file to submit (Required for waters API) + -r Root path to the hl7/fhir files (Default: /Users/bbogado/Code/Flexion/CDC-TI/trusted-intermediary/examples/) + -t Content type for the message (Default: application/hl7-v2) + -e Environment: local|staging|production (Default: local) + -c Client ID (Default: flexion) + -s Client sender (Default: simulated-sender) + -k Path to the client private key (Required for non-local environments) + -i Submission ID for history API (Required for history API) + -v Verbose mode + -h Display this help and exit + +Environment Variables: + CDCTI_HOME Base directory for CDC TI repository (Required) +``` + +#### Examples + +Sending an order to local environment + +``` +./rs.sh waters -f Test/Orders/003_AL_ORM_O01_NBS_Fully_Populated_0_initial_message.hl7 +``` + +Sending a result to local environment + +``` +./rs.sh waters -f Test/Results/002_AL_ORU_R01_NBS_Fully_Populated_0_initial_message.hl7 +``` + +Sending an order to staging + +``` +./rs.sh waters -f Test/Orders/003_AL_ORM_O01_NBS_Fully_Populated_0_initial_message.hl7 -e staging -k /path/to/client/staging/private/key +``` + +Checking the history in local environment for a submission id + +``` +./rs.sh history -i 100 +``` + +Checking the history in staging for a submission id + +``` +./rs.sh history -i 100 -e staging -k /path/to/client/staging/private/key +``` + +### ti.sh + +#### Requirements + +- hurl +- jwt-cli + +#### Usage + +``` +Usage: ./ti.sh [OPTIONS] + +ENDPOINT_NAME: + The name of the endpoint to call (required) + +Options: + -f Path to the hl7/fhir file to submit (Required for orders and results APIs) + -r Root path to the hl7/fhir files (Default: /Users/bbogado/Code/Flexion/CDC-TI/trusted-intermediary/examples/) + -e Environment: local|staging (Default: local) + -c Client ID to create JWT with (Default: report-stream) + -k Path to the client private key (Required for non-local environments) + -i Submission ID for metadata API (Required for orders, results and metadata API) + -v Verbose mode + -h Display this help and exit + +Environment Variables: + CDCTI_HOME Base directory for CDC TI repository (Required) +``` + +#### Examples + +Submit an order to local environment: +``` +./ti.sh orders -f Test/Orders/003_AL_ORM_O01_NBS_Fully_Populated_1_hl7_translation.fhir -i 100 +``` + +Submit an order to staging: +``` +./ti.sh orders -f Test/Orders/003_AL_ORM_O01_NBS_Fully_Populated_0_initial_message.hl7 -e staging -k /path/to/client/staging/private/key + +``` + +Submit a result to local environment: +``` +./ti.sh results -f Test/Results/002_AL_ORU_R01_NBS_Fully_Populated_1_hl7_translation.fhir -i 100 +``` + +Get metadata from local environment: +``` +./ti.sh metadata -i 100 +``` + +Authenticate to local environment: +``` +./ti.sh auth +``` + +Get OpenAPI docs from local environment: +``` +./ti.rs openapi +``` + +Get Health info from local environment: +``` +./ti.sh health +``` + +### epic.sh + +#### Requirements + +- hurl + +#### Before running the script + +- Add the `client` id to `epic.rs` +- Update the `secret` variable path + +#### Usage + +`./epic.sh results` + +### setup/update-examples-snapshots.sh + +Sends all the HL7 files with `_0_initial_message.hl7` suffix in the `/examples` folder to a locally running RS instance. As the previous script, it copies the snapshots at each stage + +#### Requirements + +- hurl +- jq +- azure-cli + +#### Usage + +``` +./update-examples-snapshots.sh +``` + +### setup/setup-reportstream.sh + +Setup script for ReportStream + +#### Requirements + +- yq + +#### Usage + +``` +./setup-reportstream.sh +``` + +### lib/common.sh + +Utility functions shared by scripts + +### lib/submission-utils.sh + +It has functions to submit requests to RS, check the submission status throughout the whole flow, and downloading snapshots from azurite + +## References + +- [hurl](https://hurl.dev/) +- [jq](https://jqlang.github.io/jq/) +- [yq](https://github.com/mikefarah/yq) +- [azure-cli](https://learn.microsoft.com/en-us/cli/azure/) +- [jwt-cli](https://github.com/mike-engel/jwt-cli) diff --git a/scripts/setup-rs.sh b/scripts/setup/setup-reportstream.sh similarity index 100% rename from scripts/setup-rs.sh rename to scripts/setup/setup-reportstream.sh diff --git a/scripts/update-examples.sh b/scripts/setup/update-examples-snapshots.sh similarity index 100% rename from scripts/update-examples.sh rename to scripts/setup/update-examples-snapshots.sh diff --git a/scripts/submit-message.sh b/scripts/submit.sh similarity index 100% rename from scripts/submit-message.sh rename to scripts/submit.sh From 5ecda592234ceb018df6dbd931be104b6de3766d Mon Sep 17 00:00:00 2001 From: Basilio Bogado <541149+basiliskus@users.noreply.github.com> Date: Wed, 30 Oct 2024 06:38:58 -0700 Subject: [PATCH 15/29] Moved function to common.sh --- scripts/epic.sh | 1 - scripts/lib/common.sh | 18 ++++++++++++++++++ scripts/lib/submission-utils.sh | 18 ------------------ scripts/rs.sh | 1 - scripts/ti.sh | 1 - 5 files changed, 18 insertions(+), 21 deletions(-) diff --git a/scripts/epic.sh b/scripts/epic.sh index 59022f7d4..53029356a 100755 --- a/scripts/epic.sh +++ b/scripts/epic.sh @@ -2,7 +2,6 @@ [ -z "${CDCTI_HOME}" ] && echo "Error: Environment variable CDCTI_HOME is not set" && exit 1 source "$CDCTI_HOME/scripts/lib/common.sh" -source "$CDCTI_HOME/scripts/lib/submission-utils.sh" client= audience=https://epicproxy-np.et0502.epichosted.com/FhirProxy/oauth2/token diff --git a/scripts/lib/common.sh b/scripts/lib/common.sh index 43600b3c8..d2f55db84 100755 --- a/scripts/lib/common.sh +++ b/scripts/lib/common.sh @@ -80,3 +80,21 @@ extract_host_from_url() { local url=$1 echo "$url" | sed 's|^.*://\([^/:]*\)[:/].*|\1|' } + +generate_jwt() { + # requires: jwt-cli + local client=$1 + local audience=$2 + local secret_path=$3 + + jwt encode \ + --exp='+5min' \ + --jti "$(uuidgen)" \ + --alg RS256 \ + -k "$client" \ + -i "$client" \ + -s "$client" \ + -a "$audience" \ + --no-iat \ + -S "@$secret_path" +} diff --git a/scripts/lib/submission-utils.sh b/scripts/lib/submission-utils.sh index 6846d2745..580a1dca9 100755 --- a/scripts/lib/submission-utils.sh +++ b/scripts/lib/submission-utils.sh @@ -1,23 +1,5 @@ #!/bin/bash -generate_jwt() { - # requires: jwt-cli - local client=$1 - local audience=$2 - local secret_path=$3 - - jwt encode \ - --exp='+5min' \ - --jti "$(uuidgen)" \ - --alg RS256 \ - -k "$client" \ - -i "$client" \ - -s "$client" \ - -a "$audience" \ - --no-iat \ - -S "@$secret_path" -} - extract_rs_history_submission_id() { # requires: jq local history_response=$1 diff --git a/scripts/rs.sh b/scripts/rs.sh index dbb57c7ba..76e7d590e 100755 --- a/scripts/rs.sh +++ b/scripts/rs.sh @@ -2,7 +2,6 @@ [ -z "${CDCTI_HOME}" ] && echo "Error: Environment variable CDCTI_HOME is not set" && exit 1 source "$CDCTI_HOME/scripts/lib/common.sh" -source "$CDCTI_HOME/scripts/lib/submission-utils.sh" # default values env=local diff --git a/scripts/ti.sh b/scripts/ti.sh index b13404e9c..51b2ab082 100755 --- a/scripts/ti.sh +++ b/scripts/ti.sh @@ -2,7 +2,6 @@ [ -z "${CDCTI_HOME}" ] && echo "Error: Environment variable CDCTI_HOME is not set" && exit 1 source "$CDCTI_HOME/scripts/lib/common.sh" -source "$CDCTI_HOME/scripts/lib/submission-utils.sh" # default values env=local From 2bdb7254bbb7e29b8b5f41e2b20c9464ace7d4bf Mon Sep 17 00:00:00 2001 From: Basilio Bogado <541149+basiliskus@users.noreply.github.com> Date: Wed, 30 Oct 2024 06:41:00 -0700 Subject: [PATCH 16/29] Removed unused hurl/readme.md --- scripts/hurl/README.md | 161 ----------------------------------------- 1 file changed, 161 deletions(-) delete mode 100644 scripts/hurl/README.md diff --git a/scripts/hurl/README.md b/scripts/hurl/README.md deleted file mode 100644 index 576a9fb75..000000000 --- a/scripts/hurl/README.md +++ /dev/null @@ -1,161 +0,0 @@ -# Hurl Scripts - -## Requirements - -- [hurl](https://hurl.dev/) -- [jq](https://jqlang.github.io/jq/) -- [azure-cli](https://learn.microsoft.com/en-us/cli/azure/) -- [jwt-cli](https://github.com/mike-engel/jwt-cli) -- `CDCTI_HOME` environment variable ([see here](../README.md)) - -## Available Hurl Scripts - -### ReportStream - -#### Usage - -``` -Usage: ./rs.sh [OPTIONS] - -ENDPOINT_NAME: - The name of the endpoint to call (required) - -Options: - -f Path to the hl7/fhir file to submit (Required for waters API) - -r Root path to the hl7/fhir files (Default: /Users/bbogado/Code/Flexion/CDC-TI/trusted-intermediary/examples/) - -t Content type for the message (Default: application/hl7-v2) - -e Environment: local|staging|production (Default: local) - -c Client ID (Default: flexion) - -s Client sender (Default: simulated-sender) - -k Path to the client private key (Required for non-local environments) - -i Submission ID for history API (Required for history API) - -v Verbose mode - -h Display this help and exit - -Environment Variables: - CDCTI_HOME Base directory for CDC TI repository (Required) -``` - -#### Examples - -Sending an order to local environment - -``` -./rs.sh waters -f Test/Orders/003_AL_ORM_O01_NBS_Fully_Populated_0_initial_message.hl7 -``` - -Sending a result to local environment - -``` -./rs.sh waters -f Test/Results/002_AL_ORU_R01_NBS_Fully_Populated_0_initial_message.hl7 -``` - -Sending an order to staging - -``` -./rs.sh waters -f Test/Orders/003_AL_ORM_O01_NBS_Fully_Populated_0_initial_message.hl7 -e staging -k /path/to/client/staging/private/key -``` - -Checking the history in local environment for a submission id - -``` -./rs.sh history -i 100 -``` - -Checking the history in staging for a submission id - -``` -./rs.sh history -i 100 -e staging -k /path/to/client/staging/private/key -``` - -### CDC Intermediary - -#### Usage - -``` -Usage: ./ti.sh [OPTIONS] - -ENDPOINT_NAME: - The name of the endpoint to call (required) - -Options: - -f Path to the hl7/fhir file to submit (Required for orders and results APIs) - -r Root path to the hl7/fhir files (Default: /Users/bbogado/Code/Flexion/CDC-TI/trusted-intermediary/examples/) - -e Environment: local|staging (Default: local) - -c Client ID to create JWT with (Default: report-stream) - -k Path to the client private key (Required for non-local environments) - -i Submission ID for metadata API (Required for orders, results and metadata API) - -v Verbose mode - -h Display this help and exit - -Environment Variables: - CDCTI_HOME Base directory for CDC TI repository (Required) -``` - -#### Examples - -Submit an order to local environment: -``` -./ti.sh orders -f Test/Orders/003_AL_ORM_O01_NBS_Fully_Populated_1_hl7_translation.fhir -i 100 -``` - -Submit an order to staging: -``` -./ti.sh orders -f Test/Orders/003_AL_ORM_O01_NBS_Fully_Populated_0_initial_message.hl7 -e staging -k /path/to/client/staging/private/key - -``` - -Submit a result to local environment: -``` -./ti.sh results -f Test/Results/002_AL_ORU_R01_NBS_Fully_Populated_1_hl7_translation.fhir -i 100 -``` - -Get metadata from local environment: -``` -./ti.sh metadata -i 100 -``` - -Authenticate to local environment: -``` -./ti.sh auth -``` - -Get OpenAPI docs from local environment: -``` -./ti.rs openapi -``` - -Get Health info from local environment: -``` -./ti.sh health -``` - -### Epic/UCSD - -#### Before running the script - -- Add the `client` id to `epic.rs` -- Update the `secret` variable path - -#### Usage - -`./epic.sh results` - -## High Level Scripts - -- `submit_message.sh`: sends a HL7 message to RS and tracks its status throughout the flow until final delivery. When running locally, it grabs the snapshots of the file in azurite after converting to FHIR, after applying transformations in TI, and after converting back to HL7; and it copies those files to the same folder where the submitted file is. If running in a deployed environment we currently don't have a way to download the files from Azure, but the script will print the relative path for the files in the blob storage container. - ``` - Usage: submit_message.sh -f [-e ] - - Options: - -f Message file path (Required) - -e Environment: local|staging|production (Default: ) - -x Path to the client private key for authentication with RS API (Required for non-local environments) - -z Path to the client private key for authentication with TI API (Optional for all environments) - -h Display this help and exit - ``` -- `update_examples.sh`: sends all the HL7 files with `_0_initial_message.hl7` suffix in the `/examples` folder to a locally running RS instance. As the previous script, it copies the snapshots at each stage - ``` - ./update_examples.sh - ``` -- `utils.sh`: utility functions for the previous scripts. It has functions to submit requests to RS, check the submission status throughout the whole flow, and downloading snapshots from azurite From bb8b0272cd1b6306ae7e115ec79629cfe84b1dc5 Mon Sep 17 00:00:00 2001 From: Basilio Bogado <541149+basiliskus@users.noreply.github.com> Date: Wed, 30 Oct 2024 06:49:29 -0700 Subject: [PATCH 17/29] Fixed .env file reference --- scripts/lib/common.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/lib/common.sh b/scripts/lib/common.sh index d2f55db84..82b853203 100755 --- a/scripts/lib/common.sh +++ b/scripts/lib/common.sh @@ -1,9 +1,7 @@ #!/bin/bash load_env() { - local script_dir env_file - script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" - env_file="${script_dir}/.env" + local env_file="$CDCTI_HOME/scripts/.env" if [[ -f "$env_file" ]]; then source "$env_file" else From caf441c0b4fae7c06a0a91f7e4468439c0f02a2d Mon Sep 17 00:00:00 2001 From: Basilio Bogado <541149+basiliskus@users.noreply.github.com> Date: Wed, 30 Oct 2024 07:03:31 -0700 Subject: [PATCH 18/29] Added to readme and added user message to find instructions --- scripts/README.md | 10 ++++++++-- scripts/epic.sh | 2 +- scripts/rs.sh | 2 +- scripts/setup/setup-reportstream.sh | 2 +- scripts/setup/update-examples-snapshots.sh | 2 +- scripts/submit.sh | 2 +- scripts/ti.sh | 2 +- 7 files changed, 14 insertions(+), 8 deletions(-) diff --git a/scripts/README.md b/scripts/README.md index af58b2ea1..bbf4dadd7 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -12,7 +12,7 @@ source .env ``` **Note**: you may also want to add it to your shell's startup file so you don't need to run it for every terminal session. -4. Run you script +4. Run your script ## Available Scripts @@ -41,6 +41,8 @@ Options: ### rs.sh +Submit requests to RS API endpoints + #### Requirements - hurl @@ -104,6 +106,8 @@ Checking the history in staging for a submission id ### ti.sh +Submit requests to TI API endpoints + #### Requirements - hurl @@ -171,6 +175,8 @@ Get Health info from local environment: ### epic.sh +Submit requests to Epic API endpoints + #### Requirements - hurl @@ -220,7 +226,7 @@ Utility functions shared by scripts ### lib/submission-utils.sh -It has functions to submit requests to RS, check the submission status throughout the whole flow, and downloading snapshots from azurite +Functions to submit requests to RS, check the submission status throughout the whole flow, and downloading snapshots from azurite ## References diff --git a/scripts/epic.sh b/scripts/epic.sh index 53029356a..bfe3c5bc5 100755 --- a/scripts/epic.sh +++ b/scripts/epic.sh @@ -1,6 +1,6 @@ #!/bin/bash -[ -z "${CDCTI_HOME}" ] && echo "Error: Environment variable CDCTI_HOME is not set" && exit 1 +[ -z "${CDCTI_HOME}" ] && echo "Error: Environment variable CDCTI_HOME is not set. Please refer to /scripts/README.md for instructions" && exit 1 source "$CDCTI_HOME/scripts/lib/common.sh" client= diff --git a/scripts/rs.sh b/scripts/rs.sh index 76e7d590e..5b14f9ca2 100755 --- a/scripts/rs.sh +++ b/scripts/rs.sh @@ -1,6 +1,6 @@ #!/bin/bash -[ -z "${CDCTI_HOME}" ] && echo "Error: Environment variable CDCTI_HOME is not set" && exit 1 +[ -z "${CDCTI_HOME}" ] && echo "Error: Environment variable CDCTI_HOME is not set. Please refer to /scripts/README.md for instructions" && exit 1 source "$CDCTI_HOME/scripts/lib/common.sh" # default values diff --git a/scripts/setup/setup-reportstream.sh b/scripts/setup/setup-reportstream.sh index bd9fe3f96..14c123af6 100755 --- a/scripts/setup/setup-reportstream.sh +++ b/scripts/setup/setup-reportstream.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -[ -z "${CDCTI_HOME}" ] && echo "Error: Environment variable CDCTI_HOME is not set" && exit 1 +[ -z "${CDCTI_HOME}" ] && echo "Error: Environment variable CDCTI_HOME is not set. Please refer to /scripts/README.md for instructions" && exit 1 source "$CDCTI_HOME/scripts/lib/common.sh" # Check requirements for this script diff --git a/scripts/setup/update-examples-snapshots.sh b/scripts/setup/update-examples-snapshots.sh index 86dc697e8..959457294 100755 --- a/scripts/setup/update-examples-snapshots.sh +++ b/scripts/setup/update-examples-snapshots.sh @@ -1,6 +1,6 @@ #!/bin/bash -[ -z "${CDCTI_HOME}" ] && echo "Error: Environment variable CDCTI_HOME is not set" && exit 1 +[ -z "${CDCTI_HOME}" ] && echo "Error: Environment variable CDCTI_HOME is not set. Please refer to /scripts/README.md for instructions" && exit 1 source "$CDCTI_HOME/scripts/lib/common.sh" source "$CDCTI_HOME/scripts/lib/submission-utils.sh" diff --git a/scripts/submit.sh b/scripts/submit.sh index c226807e8..9e8c1be2f 100755 --- a/scripts/submit.sh +++ b/scripts/submit.sh @@ -1,6 +1,6 @@ #!/bin/bash -[ -z "${CDCTI_HOME}" ] && echo "Error: Environment variable CDCTI_HOME is not set" && exit 1 +[ -z "${CDCTI_HOME}" ] && echo "Error: Environment variable CDCTI_HOME is not set. Please refer to /scripts/README.md for instructions" && exit 1 source "$CDCTI_HOME/scripts/lib/common.sh" source "$CDCTI_HOME/scripts/lib/submission-utils.sh" diff --git a/scripts/ti.sh b/scripts/ti.sh index 51b2ab082..3a1e1dffa 100755 --- a/scripts/ti.sh +++ b/scripts/ti.sh @@ -1,6 +1,6 @@ #!/bin/bash -[ -z "${CDCTI_HOME}" ] && echo "Error: Environment variable CDCTI_HOME is not set" && exit 1 +[ -z "${CDCTI_HOME}" ] && echo "Error: Environment variable CDCTI_HOME is not set. Please refer to /scripts/README.md for instructions" && exit 1 source "$CDCTI_HOME/scripts/lib/common.sh" # default values From 1f4cf891ff89c15f5ef05aec752f8fef281a42e6 Mon Sep 17 00:00:00 2001 From: Basilio Bogado <541149+basiliskus@users.noreply.github.com> Date: Wed, 30 Oct 2024 07:15:01 -0700 Subject: [PATCH 19/29] Added context to instruction --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 54843a054..958f9ccb5 100644 --- a/README.md +++ b/README.md @@ -348,7 +348,7 @@ with this option enabled. 3. Run RS with `docker compose up -d`. You may also use `./gradlew quickRun` 4. Run the RS setup script in this repository: `/scripts/setup/setup-reportstream.sh` - Before running the script, make sure to follow the instructions in [/scripts/README.md](/scripts/README.md) - - You can verify that the script created the secrets successfully by going to `http://localhost:8200/` in your browser, use the token in `prime-router/.vault/env/.env.local` to authenticate, and then go to `Secrets engines` > `secret/` to check the available secrets + - You can verify the script created vault secrets successfully by going to `http://localhost:8200/` in your browser, use the token in `prime-router/.vault/env/.env.local` to authenticate, and then go to `Secrets engines` > `secret/` to check the available secrets #### Submit request to ReportStream From 7a7909e85a55699a39b9bc59d169b27d1bc4f5ff Mon Sep 17 00:00:00 2001 From: Basilio Bogado <541149+basiliskus@users.noreply.github.com> Date: Wed, 30 Oct 2024 07:52:23 -0700 Subject: [PATCH 20/29] Added setup script for env vars --- scripts/README.md | 6 ++++-- scripts/start-here.sh | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100755 scripts/start-here.sh diff --git a/scripts/README.md b/scripts/README.md index bbf4dadd7..4bfd1f4a3 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -2,14 +2,16 @@ ## Instructions +You can either run `start-here.sh` or follow the instructions below to load the environments variables required for these scripts + 1. Copy `.env.template` to `.env` ``` cp .env.template .env ``` 2. Edit `.env` and make sure to update at least `CDCTI_HOME` (local path to the `trusted-intermediary` codebase) and `RS_HOME` (local path to the `prime-reportstream` codebase) are set. **Note**: if you don't set `CDCTI_HOME`, none of these scripts will work. Also, please use `$HOME` or the full path to your home directory instead of `~` -3. Load the environment variables in `.env` by running +3. Export the environment variables in `.env` by running ``` - source .env + set -a; source .env; set +a ``` **Note**: you may also want to add it to your shell's startup file so you don't need to run it for every terminal session. 4. Run your script diff --git a/scripts/start-here.sh b/scripts/start-here.sh new file mode 100755 index 000000000..5f306d0dc --- /dev/null +++ b/scripts/start-here.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +if [ ! -f .env ]; then + cp .env.template .env || { + echo "Failed to create .env file" + exit 1 + } + ${EDITOR:-vi} .env +fi + +# Export environment variables +set -a +source .env +set +a From c1043dfe74d518b28a9bf189f5ffd635f81525c6 Mon Sep 17 00:00:00 2001 From: Basilio Bogado <541149+basiliskus@users.noreply.github.com> Date: Wed, 30 Oct 2024 08:07:23 -0700 Subject: [PATCH 21/29] Changed relative path to hurl files for absolute paths --- scripts/epic.sh | 2 +- scripts/lib/submission-utils.sh | 6 +++--- scripts/rs.sh | 4 ++-- scripts/ti.sh | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/scripts/epic.sh b/scripts/epic.sh index bfe3c5bc5..e979829c5 100755 --- a/scripts/epic.sh +++ b/scripts/epic.sh @@ -16,5 +16,5 @@ hurl \ --variable "fpath=$fpath" \ --file-root "$root" \ --variable "jwt=$jwt_token" \ - epic/results.hurl \ + "$CDCTI_HOME"/scripts/epic/results.hurl \ $@ diff --git a/scripts/lib/submission-utils.sh b/scripts/lib/submission-utils.sh index 580a1dca9..21a72e2b7 100755 --- a/scripts/lib/submission-utils.sh +++ b/scripts/lib/submission-utils.sh @@ -50,7 +50,7 @@ check_submission_status() { start_time=$(date +%s) while true; do - history_response=$(./rs.sh history -i "$submission_id" -e "$env" -k "$private_key") || { + history_response=$("$CDCTI_HOME"/scripts/rs.sh history -i "$submission_id" -e "$env" -k "$private_key") || { exit_code=$? if [ $exit_code -ne 0 ]; then fail "Expected exit code 0 but got $exit_code for RS history API call" @@ -109,7 +109,7 @@ submit_message() { echo "Assuming receivers are '$first_leg_receiver' and '$second_leg_receiver' because of MSH-9 value '$msh9'" - waters_response=$(./rs.sh waters -f "$message_file_name" -r "$message_file_path" -e "$env" -k "$rs_client_private_key") || { + waters_response=$("$CDCTI_HOME"/scripts/rs.sh waters -f "$message_file_name" -r "$message_file_path" -e "$env" -k "$rs_client_private_key") || { exit_code=$? if [ $exit_code -ne 0 ]; then fail "Expected exit code 0 but got $exit_code for RS waters API call" @@ -136,7 +136,7 @@ submit_message() { echo "[Intermediary] Getting outbound submission ID" if [ -n "$ti_client_private_key" ]; then echo " Attempting to get outbound submission ID from TI's metadata API..." - metadata_response=$(./ti.sh metadata -i "$inbound_submission_id" -e "$env" -k "$ti_client_private_key") || { + metadata_response=$("$CDCTI_HOME"/scripts/ti.sh metadata -i "$inbound_submission_id" -e "$env" -k "$ti_client_private_key") || { echo "Failed to get metadata for inbound submission ID: $inbound_submission_id" outbound_submission_id="" } diff --git a/scripts/rs.sh b/scripts/rs.sh index 5b14f9ca2..d8f0d6b1a 100755 --- a/scripts/rs.sh +++ b/scripts/rs.sh @@ -41,7 +41,7 @@ parse_arguments() { fi [ $# -eq 0 ] && fail "Missing required argument " - endpoint_name="hurl/rs/$1.hurl" + hurl_file_path="$CDCTI_HOME/scripts/hurl/rs/$1.hurl" shift # Remove endpoint name from args while getopts ':f:r:t:e:c:s:k:i:v' opt; do @@ -94,7 +94,7 @@ run_hurl_command() { --variable "jwt=$jwt_token" \ ${submission_id:-} \ ${verbose:-} \ - "$endpoint_name" \ + "$hurl_file_path" \ ${remaining_args:+$remaining_args} } diff --git a/scripts/ti.sh b/scripts/ti.sh index 3a1e1dffa..73b5fd2ec 100755 --- a/scripts/ti.sh +++ b/scripts/ti.sh @@ -37,7 +37,7 @@ parse_arguments() { fi [ $# -eq 0 ] && fail "Missing required argument " - endpoint_name="hurl/ti/$1.hurl" + hurl_file_path="$CDCTI_HOME/scripts/hurl/ti/$1.hurl" shift # Remove endpoint name from args while getopts ':f:r:e:c:k:i:v' opt; do @@ -86,7 +86,7 @@ run_hurl_command() { --variable "jwt=$jwt_token" \ ${submission_id:-} \ ${verbose:-} \ - "$endpoint_name" \ + "$hurl_file_path" \ ${remaining_args:+$remaining_args} } From 5935548442c4bc608a3409ffb41659563f78d76f Mon Sep 17 00:00:00 2001 From: Basilio Bogado <541149+basiliskus@users.noreply.github.com> Date: Wed, 30 Oct 2024 09:39:07 -0700 Subject: [PATCH 22/29] Fixed typos and cleanup --- scripts/README.md | 21 +++++++++------------ scripts/rs.sh | 5 +---- scripts/ti.sh | 5 +---- 3 files changed, 11 insertions(+), 20 deletions(-) diff --git a/scripts/README.md b/scripts/README.md index 4bfd1f4a3..be7ff2178 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -1,6 +1,6 @@ # Scripts -## Instructions +## Setup You can either run `start-here.sh` or follow the instructions below to load the environments variables required for these scripts @@ -8,7 +8,10 @@ You can either run `start-here.sh` or follow the instructions below to load the ``` cp .env.template .env ``` -2. Edit `.env` and make sure to update at least `CDCTI_HOME` (local path to the `trusted-intermediary` codebase) and `RS_HOME` (local path to the `prime-reportstream` codebase) are set. **Note**: if you don't set `CDCTI_HOME`, none of these scripts will work. Also, please use `$HOME` or the full path to your home directory instead of `~` +2. Edit `.env` and make sure to update at least: + - `CDCTI_HOME`: local path to the `trusted-intermediary` codebase + - `RS_HOME`: local path to the `prime-reportstream` codebase + - **Note**: if you don't set `CDCTI_HOME`, none of these scripts will work. Also, please use `$HOME` or the full path to your home directory instead of `~` 3. Export the environment variables in `.env` by running ``` set -a; source .env; set +a @@ -31,7 +34,7 @@ Sends a HL7 message to RS and tracks its status throughout the flow until final #### Usage ``` -Usage: submit.sh -f [-e ] +Usage: ./submit.sh -f [-e ] Options: -f Message file path (Required) @@ -69,9 +72,6 @@ Options: -i Submission ID for history API (Required for history API) -v Verbose mode -h Display this help and exit - -Environment Variables: - CDCTI_HOME Base directory for CDC TI repository (Required) ``` #### Examples @@ -132,9 +132,6 @@ Options: -i Submission ID for metadata API (Required for orders, results and metadata API) -v Verbose mode -h Display this help and exit - -Environment Variables: - CDCTI_HOME Base directory for CDC TI repository (Required) ``` #### Examples @@ -167,7 +164,7 @@ Authenticate to local environment: Get OpenAPI docs from local environment: ``` -./ti.rs openapi +./ti.sh openapi ``` Get Health info from local environment: @@ -185,7 +182,7 @@ Submit requests to Epic API endpoints #### Before running the script -- Add the `client` id to `epic.rs` +- Add the `client` id to `epic.sh` - Update the `secret` variable path #### Usage @@ -194,7 +191,7 @@ Submit requests to Epic API endpoints ### setup/update-examples-snapshots.sh -Sends all the HL7 files with `_0_initial_message.hl7` suffix in the `/examples` folder to a locally running RS instance. As the previous script, it copies the snapshots at each stage +Sends all the HL7 files with `_0_initial_message.hl7` suffix in the `/examples` folder to a locally running RS instance. As the `submit.sh` script, it downloads the snapshots at each stage. This script is helpful to keep all the message snapshots in the examples folder up to date #### Requirements diff --git a/scripts/rs.sh b/scripts/rs.sh index d8f0d6b1a..05fa94c8e 100755 --- a/scripts/rs.sh +++ b/scripts/rs.sh @@ -12,7 +12,7 @@ client_sender=simulated-sender show_usage() { cat < [OPTIONS] +Usage: ./$(basename "$0") [OPTIONS] ENDPOINT_NAME: The name of the endpoint to call (required) @@ -28,9 +28,6 @@ Options: -i Submission ID for history API (Required for history API) -v Verbose mode -h Display this help and exit - -Environment Variables: - CDCTI_HOME Base directory for CDC TI repository (Required) EOF } diff --git a/scripts/ti.sh b/scripts/ti.sh index 73b5fd2ec..d6a44f8f5 100755 --- a/scripts/ti.sh +++ b/scripts/ti.sh @@ -10,7 +10,7 @@ client=report-stream show_usage() { cat < [OPTIONS] +Usage: ./$(basename "$0") [OPTIONS] ENDPOINT_NAME: The name of the endpoint to call (required) @@ -24,9 +24,6 @@ Options: -i Submission ID for metadata API (Required for orders, results and metadata API) -v Verbose mode -h Display this help and exit - -Environment Variables: - CDCTI_HOME Base directory for CDC TI repository (Required) EOF } From d70bb4923f7da16cb9fdd74f31a482d6ade847b9 Mon Sep 17 00:00:00 2001 From: Basilio Bogado <541149+basiliskus@users.noreply.github.com> Date: Wed, 30 Oct 2024 10:03:43 -0700 Subject: [PATCH 23/29] Removed setup script not working as intended --- scripts/README.md | 2 +- scripts/start-here.sh | 14 -------------- 2 files changed, 1 insertion(+), 15 deletions(-) delete mode 100755 scripts/start-here.sh diff --git a/scripts/README.md b/scripts/README.md index be7ff2178..852eed6bd 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -2,7 +2,7 @@ ## Setup -You can either run `start-here.sh` or follow the instructions below to load the environments variables required for these scripts +Follow the instructions below to load the environments variables required for these scripts 1. Copy `.env.template` to `.env` ``` diff --git a/scripts/start-here.sh b/scripts/start-here.sh deleted file mode 100755 index 5f306d0dc..000000000 --- a/scripts/start-here.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -if [ ! -f .env ]; then - cp .env.template .env || { - echo "Failed to create .env file" - exit 1 - } - ${EDITOR:-vi} .env -fi - -# Export environment variables -set -a -source .env -set +a From da784d7c41812f4b632056af3ec0d65eb6cb798b Mon Sep 17 00:00:00 2001 From: Basilio Bogado <541149+basiliskus@users.noreply.github.com> Date: Wed, 30 Oct 2024 10:04:04 -0700 Subject: [PATCH 24/29] Readme update --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 958f9ccb5..c649125a0 100644 --- a/README.md +++ b/README.md @@ -332,7 +332,7 @@ For database documentation: [/docs/database.md](/docs/database.md) 1. Checkout `main` branch for `CDCgov/trusted-intermediary` 2. Run `./generate_env.sh` to generate `.env` file with required environment variables -3. Run TI with `./gradlew clean app:run` +3. Run TI with `./gradlew clean run` #### ReportStream Setup From 66c1ed8c1460698b9caaa1f51b027aa36b5d558b Mon Sep 17 00:00:00 2001 From: Basilio Bogado <541149+basiliskus@users.noreply.github.com> Date: Wed, 30 Oct 2024 10:37:35 -0700 Subject: [PATCH 25/29] Fixed issues after running shellcheck --- .shellcheckrc | 2 ++ scripts/epic.sh | 2 +- scripts/lib/common.sh | 12 ++++++------ scripts/rs.sh | 6 +++--- scripts/setup/setup-reportstream.sh | 2 +- scripts/ti.sh | 6 +++--- 6 files changed, 16 insertions(+), 14 deletions(-) create mode 100644 .shellcheckrc diff --git a/.shellcheckrc b/.shellcheckrc new file mode 100644 index 000000000..6d17a4e9c --- /dev/null +++ b/.shellcheckrc @@ -0,0 +1,2 @@ + +disable=SC1090,SC1091 diff --git a/scripts/epic.sh b/scripts/epic.sh index e979829c5..e1aabbb00 100755 --- a/scripts/epic.sh +++ b/scripts/epic.sh @@ -17,4 +17,4 @@ hurl \ --file-root "$root" \ --variable "jwt=$jwt_token" \ "$CDCTI_HOME"/scripts/epic/results.hurl \ - $@ + "$@" diff --git a/scripts/lib/common.sh b/scripts/lib/common.sh index 82b853203..a4702d178 100755 --- a/scripts/lib/common.sh +++ b/scripts/lib/common.sh @@ -51,9 +51,9 @@ get_api_url() { case "$type" in "rs") case "$env" in - "local") echo $RS_LCL_API_URL ;; - "staging") echo $RS_STG_API_URL ;; - "production") echo $RS_PRD_API_URL ;; + "local") echo "$RS_LCL_API_URL" ;; + "staging") echo "$RS_STG_API_URL" ;; + "production") echo "$RS_PRD_API_URL" ;; *) echo "Invalid environment: $env" >&2 exit 1 @@ -62,9 +62,9 @@ get_api_url() { ;; "ti") case "$env" in - "local") echo $TI_LCL_API_URL ;; - "staging") echo $TI_STG_API_URL ;; - "production") echo $TI_PRD_API_URL ;; + "local") echo "$TI_LCL_API_URL" ;; + "staging") echo "$TI_STG_API_URL" ;; + "production") echo "$TI_PRD_API_URL" ;; *) echo "Invalid environment: $env" >&2 exit 1 diff --git a/scripts/rs.sh b/scripts/rs.sh index 05fa94c8e..694b0c632 100755 --- a/scripts/rs.sh +++ b/scripts/rs.sh @@ -56,7 +56,7 @@ parse_arguments() { esac done - shift "$(($OPTIND - 1))" + shift "$((OPTIND - 1))" remaining_args="$*" } @@ -89,8 +89,8 @@ run_hurl_command() { --variable "client-id=$client_id" \ --variable "client-sender=$client_sender" \ --variable "jwt=$jwt_token" \ - ${submission_id:-} \ - ${verbose:-} \ + "${submission_id:-}" \ + "${verbose:-}" \ "$hurl_file_path" \ ${remaining_args:+$remaining_args} } diff --git a/scripts/setup/setup-reportstream.sh b/scripts/setup/setup-reportstream.sh index 14c123af6..bcbe93f9b 100755 --- a/scripts/setup/setup-reportstream.sh +++ b/scripts/setup/setup-reportstream.sh @@ -44,7 +44,7 @@ yq eval '.[0].receivers[] |= ( echo "Updating local URL and host in transport settings..." sed -i '' "s|__TI_API_URL__|${TI_LCL_API_URL}|g" "settings/STLTs/Flexion/flexion.yml" -sed -i '' "s|__TI_API_HOST__|$(extract_host_from_url ${TI_LCL_API_URL})|g" "settings/STLTs/Flexion/flexion.yml" +sed -i '' "s|__TI_API_HOST__|$(extract_host_from_url "${TI_LCL_API_URL}")|g" "settings/STLTs/Flexion/flexion.yml" echo "Updating transport settings in partner org files..." for file in "settings/STLTs/CA/ucsd.yml" "settings/STLTs/LA/la-ochsner.yml" "settings/STLTs/LA/la-phl.yml"; do diff --git a/scripts/ti.sh b/scripts/ti.sh index d6a44f8f5..f96473cfe 100755 --- a/scripts/ti.sh +++ b/scripts/ti.sh @@ -50,7 +50,7 @@ parse_arguments() { esac done - shift "$(($OPTIND - 1))" + shift "$((OPTIND - 1))" remaining_args="$*" } @@ -81,8 +81,8 @@ run_hurl_command() { --variable "url=$url" \ --variable "client=$client" \ --variable "jwt=$jwt_token" \ - ${submission_id:-} \ - ${verbose:-} \ + "${submission_id:-}" \ + "${verbose:-}" \ "$hurl_file_path" \ ${remaining_args:+$remaining_args} } From 32c027f5722bba34f4ef0fa703c60ae56420981c Mon Sep 17 00:00:00 2001 From: Basilio Bogado <541149+basiliskus@users.noreply.github.com> Date: Wed, 30 Oct 2024 10:43:08 -0700 Subject: [PATCH 26/29] Removed dead code and renamed readme section --- scripts/README.md | 2 +- scripts/setup/setup-reportstream.sh | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/README.md b/scripts/README.md index 852eed6bd..b503ca971 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -227,7 +227,7 @@ Utility functions shared by scripts Functions to submit requests to RS, check the submission status throughout the whole flow, and downloading snapshots from azurite -## References +## Resources - [hurl](https://hurl.dev/) - [jq](https://jqlang.github.io/jq/) diff --git a/scripts/setup/setup-reportstream.sh b/scripts/setup/setup-reportstream.sh index bcbe93f9b..3e89434ac 100755 --- a/scripts/setup/setup-reportstream.sh +++ b/scripts/setup/setup-reportstream.sh @@ -11,8 +11,6 @@ check_installed_commands yq CURRENT_DIR=$(pwd) cd "$RS_HOME" || exit -# source "./prime-router/.vault/env/.env.local" - echo "Resetting the database and loading the baseline settings..." ./gradlew resetDB ./gradlew reloadTable From 802b6355b04a2b8e64c8cd767f47475fcc5fd57a Mon Sep 17 00:00:00 2001 From: Basilio Bogado <541149+basiliskus@users.noreply.github.com> Date: Wed, 30 Oct 2024 10:52:26 -0700 Subject: [PATCH 27/29] Reverted adding double quotes as it introduces a bug --- scripts/rs.sh | 4 ++-- scripts/ti.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/rs.sh b/scripts/rs.sh index 694b0c632..1a5da946a 100755 --- a/scripts/rs.sh +++ b/scripts/rs.sh @@ -89,8 +89,8 @@ run_hurl_command() { --variable "client-id=$client_id" \ --variable "client-sender=$client_sender" \ --variable "jwt=$jwt_token" \ - "${submission_id:-}" \ - "${verbose:-}" \ + ${submission_id:-} \ + ${verbose:-} \ "$hurl_file_path" \ ${remaining_args:+$remaining_args} } diff --git a/scripts/ti.sh b/scripts/ti.sh index f96473cfe..6df6c342c 100755 --- a/scripts/ti.sh +++ b/scripts/ti.sh @@ -81,8 +81,8 @@ run_hurl_command() { --variable "url=$url" \ --variable "client=$client" \ --variable "jwt=$jwt_token" \ - "${submission_id:-}" \ - "${verbose:-}" \ + ${submission_id:-} \ + ${verbose:-} \ "$hurl_file_path" \ ${remaining_args:+$remaining_args} } From 52e14babde6509779df694cd566aa2e06135d7cf Mon Sep 17 00:00:00 2001 From: Basilio Bogado <541149+basiliskus@users.noreply.github.com> Date: Thu, 31 Oct 2024 12:14:21 -0700 Subject: [PATCH 28/29] Added missing export of env vars that are required to create vault credentials --- scripts/setup/setup-reportstream.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/setup/setup-reportstream.sh b/scripts/setup/setup-reportstream.sh index 3e89434ac..2fdc3710c 100755 --- a/scripts/setup/setup-reportstream.sh +++ b/scripts/setup/setup-reportstream.sh @@ -68,10 +68,12 @@ echo "Adding public keys for senders..." ./prime organization addkey --public-key "$TI_LOCAL_PUBLIC_KEY_PATH" --scope "flexion.*.report" --orgName flexion --kid flexion.simulated-sender --doit echo "Adding credentials for receivers..." -./prime create-credential --type UserPass --user foo --pass pass --persist DEFAULT-SFTP +export $(xargs <"$RS_HOME/prime-router/.vault/env/.env.local") rs_private_key=$(cat "$RS_LOCAL_PRIVATE_KEY_PATH") + +./prime create-credential --type UserPass --user foo --pass pass --persist DEFAULT-SFTP ./prime create-credential --type UserApiKey --apikey-user flexion --apikey "$rs_private_key" --persist FLEXION--ETOR-SERVICE-RECEIVER-ORDERS -./prime create-credential --type UserApiKey --apikey-user flexion --apikey "$rs_private_key" --persist FLEXION--ETOR-SERVICE-RECEIVER-RESULTS +./prime create-credential --type UserApiKey --apikey-user flexion --apikey "$(cat "$RS_LOCAL_PRIVATE_KEY_PATH")" --persist FLEXION--ETOR-SERVICE-RECEIVER-RESULTS ./prime create-credential --type UserApiKey --apikey-user ucsd --apikey "$rs_private_key" --persist UCSD--ETOR-NBS-RESULTS ./prime create-credential --type UserApiKey --apikey-user la-phl --apikey "$rs_private_key" --persist LA-PHL--ETOR-NBS-ORDERS ./prime create-credential --type UserApiKey --apikey-user la-ochsner --apikey "$rs_private_key" --persist LA-OCHSNER--ETOR-NBS-RESULTS From eec024b2487a7b5c2f051cd9ac7218a0deab9dbd Mon Sep 17 00:00:00 2001 From: Basilio Bogado <541149+basiliskus@users.noreply.github.com> Date: Thu, 31 Oct 2024 16:33:03 -0700 Subject: [PATCH 29/29] Fixed typo --- scripts/README.md | 2 +- scripts/submit.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/README.md b/scripts/README.md index b503ca971..2e8ae53b4 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -38,7 +38,7 @@ Usage: ./submit.sh -f [-e ] Options: -f Message file path (Required) - -e Environment: local|staging|production (Default: ) + -e Environment: local|staging|production (Default: local) -x Path to the client private key for authentication with RS API (Required for non-local environments) -z Path to the client private key for authentication with TI API (Optional for all environments) -h Display this help and exit diff --git a/scripts/submit.sh b/scripts/submit.sh index 9e8c1be2f..1a93990b5 100755 --- a/scripts/submit.sh +++ b/scripts/submit.sh @@ -12,7 +12,7 @@ Usage: $(basename "$0") -f [-e ] Options: -f Message file path (Required) - -e Environment: local|staging|production (Default: $DEFAULT_ENV) + -e Environment: local|staging|production (Default: $env) -x Path to the client private key for authentication with RS API (Required for non-local environments) -z Path to the client private key for authentication with TI API (Optional for all environments) -h Display this help and exit