-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: fix script + test #1756
Merged
Merged
chore: fix script + test #1756
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,38 @@ | ||
#!/usr/bin/env bash | ||
secret_to_call="$1" | ||
secret_name="$2" | ||
set +x | ||
#!/bin/bash | ||
|
||
SECRET_JSON=$(aws secretsmanager get-secret-value --secret-id $secret_to_call --region "us-east-1" --output json) | ||
# Check the exit status of the AWS CLI command | ||
extract_value_from_json() { | ||
local json="$1" | ||
local key="$2" | ||
local value=$(echo "$json" | jq -r ".$key") | ||
} | ||
|
||
extract_and_store_secret_value() { | ||
fetch_whole_secret() { | ||
local secret_name="$1" | ||
local variable_name="$2" | ||
local secret_value=$(aws secretsmanager get-secret-value --secret-id "$secret_name" --query "SecretString" --output text) | ||
#set whole file as env var | ||
declare "${secret_name%=*}=${secret_value}" | ||
} | ||
|
||
value=$(echo "$SECRET_JSON" | jq -r ".SecretString | fromjson.$secret_name" 2>/dev/null) | ||
eval "$secret_name"='$value' | ||
fetch_specific_key() { | ||
local secret_name="$1" | ||
local key="$2" | ||
local secret_value=$(aws secretsmanager get-secret-value --secret-id "$secret_name" --query "SecretString" --output text) | ||
local extracted_value=$(extract_value_from_json "$secret_value" "$key") | ||
declare "${key%=*}=${extracted_value}" | ||
} | ||
|
||
if [ $? -eq 0 ]; then | ||
# Use jq to extract the values from the JSON response | ||
extract_and_store_secret_value $SECRET_JSON $secret_name | ||
# Main script | ||
if [[ "$1" == "-w" ]]; then | ||
if [ $# -ne 3 ]; then | ||
echo "Usage: $0 -w <name_of_file> <name_of_variable>" | ||
exit 1 | ||
fi | ||
fetch_whole_secret "$2" "$3" | ||
else | ||
echo "AWS CLI command failed" | ||
if [ $# -ne 2 ]; then | ||
echo "Usage: $0 <name_of_file> <name_of_key>" | ||
exit 1 | ||
fi | ||
fetch_specific_key "$1" "$2" | ||
fi |
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 |
---|---|---|
|
@@ -14,19 +14,20 @@ make requirements | |
source $WORKSPACE/secrets-manager.sh | ||
# Fetch the secrets from AWS | ||
set +x | ||
get_secret_value analytics-secure/job-configs/SNOWFLAKE_REFRESH_SNOWPIPE_JOB_EXTRA_VARS KEY_PATH | ||
get_secret_value analytics-secure/job-configs/SNOWFLAKE_REFRESH_SNOWPIPE_JOB_EXTRA_VARS PASSPHRASE_PATH | ||
get_secret_value analytics-secure/job-configs/SNOWFLAKE_REFRESH_SNOWPIPE_JOB_EXTRA_VARS USER | ||
get_secret_value analytics-secure/job-configs/SNOWFLAKE_REFRESH_SNOWPIPE_JOB_EXTRA_VARS ACCOUNT | ||
|
||
|
||
secrets-manager.sh -w analytics-secure/job-configs/SNOWFLAKE_REFRESH_SNOWPIPE_JOB_EXTRA_VARS snowflake/rsa_key_snowpipe_user.p8 | ||
secrets-manager.sh -w analytics-secure/job-configs/SNOWFLAKE_REFRESH_SNOWPIPE_JOB_EXTRA_VARS snowflake/rsa_key_passphrase_snowpipe_user | ||
|
||
set -x | ||
|
||
python refresh_snowpipe.py \ | ||
--key_path $WORKSPACE/analytics-secure/$KEY_PATH \ | ||
--passphrase_path $WORKSPACE/analytics-secure/$PASSPHRASE_PATH \ | ||
--user $USER \ | ||
--user 'SNOWPIPE' \ | ||
--schema $SCHEMA \ | ||
--account $ACCOUNT \ | ||
--account 'edx.us-east-1' \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as the user, I think we can leave that as is. |
||
--pipe_name $PIPE_NAME \ | ||
--table_name $TABLE_NAME \ | ||
--delay $DELAY \ | ||
--limit $LIMIT | ||
--key_file $KEY_PATH \ | ||
--passphrase_file $PASSPHRASE_PATH |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to do this ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nah, but we arent going to call the extra_vars unless we really need to, so i replaced all of the vars