generated from CDCgov/template
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into db-terraform-fix
- Loading branch information
Showing
19 changed files
with
219 additions
and
262 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
# curl --header 'Content-Type: application/x-www-form-urlencoded' --data 'scope=flexion.*.report' --data 'client_assertion=$(jwt encode --exp=+5min --jti $(uuidgen) --alg RS256 -k $client -i $client -s $client -a $host --no-iat -S @/path/to/ucsd-epic-private-key.pem) --data 'client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer' --data 'grant_type=client_credentials' 'http://localhost:7071/api/token' | ||
# curl --header 'Content-Type: application/x-www-form-urlencoded' --data 'scope=flexion.*.report' --data 'client_assertion=$(jwt encode --exp=+5min --jti $(uuidgen) --alg RS256 -k $sender -i $sender -s $sender -a $host --no-iat -S @/path/to/ucsd-epic-private-key.pem) --data 'client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer' --data 'grant_type=client_credentials' 'http://localhost:7071/api/token' | ||
POST {{url}}/api/token | ||
Content-Type: application/x-www-form-urlencoded | ||
[FormParams] | ||
scope: {{client-id}}.*.report | ||
scope: {{sender-org}}.*.report | ||
client_assertion: {{jwt}} | ||
client_assertion_type: urn:ietf:params:oauth:client-assertion-type:jwt-bearer | ||
grant_type: client_credentials |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
POST {{url}}/v1/auth/token | ||
Content-Type: application/x-www-form-urlencoded | ||
[FormParams] | ||
scope: {{client}} | ||
scope: {{sender}} | ||
client_assertion: {{jwt}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
#!/bin/bash | ||
|
||
show_usage() { | ||
local script_name=$1 | ||
|
||
cat <<EOF | ||
Usage: ./$script_name <ENDPOINT_NAME> [OPTIONS] | ||
ENDPOINT_NAME: | ||
The name of the endpoint to call (required) | ||
Options: | ||
-e <ENVIRONMENT> Environment: local|staging (Default: $ENVIRONMENT) | ||
-f <REL_PATH> Path to the message file to submit (Required for submission endpoints) | ||
-r <ROOT_PATH> Root path to the message files (Default: $ROOT_PATH) | ||
-t <CONTENT_TYPE> Content type for the message file (Default: $CONTENT_TYPE) | ||
-k <KEY_PATH> Path to the sender private key (Required for non-local environments) | ||
-s <SENDER> Sender ID used for authentication (Default: $SENDER) | ||
-u <URL> URL root for the API endpoint (Default: auto-detected) | ||
-i <SUBMISSION_ID> Submission ID (Required for query endpoints) | ||
-v Verbose mode | ||
-h Display this help and exit | ||
EOF | ||
} | ||
|
||
parse_args() { | ||
local type=$1 | ||
shift | ||
|
||
[ "$1" = "-h" ] || [ "$1" = "--help" ] && return 1 | ||
[ $# -eq 0 ] && fail "Missing required argument <ENDPOINT_NAME>" | ||
|
||
HURL_FILE_PATH="$CDCTI_HOME/scripts/hurl/$type/$1.hurl" | ||
shift | ||
|
||
while getopts ':e:f:r:t:k:s:u:i:v' opt; do | ||
case "$opt" in | ||
e) ENVIRONMENT="$OPTARG" ;; | ||
f) REL_PATH="$OPTARG" ;; | ||
r) ROOT_PATH="$OPTARG" ;; | ||
t) CONTENT_TYPE="$OPTARG" ;; | ||
k) SENDER_PRIVATE_KEY="$OPTARG" ;; | ||
s) SENDER="$OPTARG" ;; | ||
u) URL="$OPTARG" ;; | ||
i) SUBMISSION_ID="$OPTARG" ;; | ||
v) VERBOSE="--verbose" ;; | ||
?) fail "Invalid option -$OPTARG" ;; | ||
esac | ||
done | ||
|
||
parse_sender_string "$SENDER" | ||
|
||
if [ -z "$SENDER_PRIVATE_KEY" ] && [ "$ENVIRONMENT" = "local" ] && [ -f "$DEFAULT_SENDER_PRIVATE_KEY_PATH" ] && [ "$SENDER_ORG" = "$DEFAULT_SENDER_PRIVATE_KEY_ORG" ]; then | ||
SENDER_PRIVATE_KEY="$DEFAULT_SENDER_PRIVATE_KEY_PATH" | ||
elif [ -z "$SENDER_PRIVATE_KEY" ] && [ "$ENVIRONMENT" != "local" ]; then | ||
fail "Sender private key (-k) is required for non-local environments" | ||
fi | ||
|
||
[ ! -f "$SENDER_PRIVATE_KEY" ] && fail "Sender private key file not found: $SENDER_PRIVATE_KEY" | ||
|
||
shift "$((OPTIND - 1))" | ||
REMAINING_ARGS="$*" | ||
} | ||
|
||
handle_api_request() { | ||
local api_type=$1 | ||
shift | ||
|
||
local host jwt_token | ||
[ -z "$URL" ] && URL=$(get_api_url "$ENVIRONMENT" "$api_type") | ||
host=$(extract_host_from_url "$URL") | ||
jwt_token=$(generate_jwt "$SENDER" "$host" "$SENDER_PRIVATE_KEY") | ||
|
||
local vars=( | ||
--variable fpath=$REL_PATH | ||
--file-root $ROOT_PATH | ||
--variable url=$URL | ||
--variable jwt=$jwt_token | ||
--variable content-type=$CONTENT_TYPE | ||
) | ||
|
||
if [ "$api_type" = "rs" ]; then | ||
vars+=( | ||
--variable sender-org=$SENDER_ORG | ||
--variable sender-name=$SENDER_NAME | ||
) | ||
else | ||
vars+=(--variable sender=$SENDER) | ||
fi | ||
|
||
if [ -n "$SUBMISSION_ID" ]; then vars+=(--variable submissionid="$SUBMISSION_ID"); fi | ||
if [ -n "$VERBOSE" ]; then vars+=("$VERBOSE"); fi | ||
|
||
hurl "${vars[@]}" "$HURL_FILE_PATH" ${REMAINING_ARGS:+$REMAINING_ARGS} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.