Skip to content

Commit

Permalink
Modify setup_secrets.sh to use hcp instead of vlt
Browse files Browse the repository at this point in the history
  • Loading branch information
aadhyaaamashru committed Sep 23, 2024
1 parent 3c99421 commit 258766f
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions setup_secrets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ ENV_FILE=".env"

# Login to Vault
echo "Logging into Vault..."
vlt login
hcp auth login
if [ $? -ne 0 ]; then
echo "Failed to login to Vault. Please check your credentials."
exit 1
fi

vlt config init
hcp profile init

# Check if .env file exists and delete it if it does
if [ -f "$ENV_FILE" ]; then
rm "$ENV_FILE"
fi

# Fetch all secret keys from Vault
SECRET_KEYS=$(vlt secrets list -format=json | grep -Eo '"([^"]*)"\s*:\s*"([^"]*)"' | sed -E 's/^"([^"]*)"\s*:\s*"([^"]*)"$/\1=\2/' | grep "^name=" | grep -v "@" | sed 's/^name=//')
SECRET_KEYS=$(hcp vault-secrets secrets list --format=json | grep -Eo '"([^"]*)"\s*:\s*"([^"]*)"' | sed -E 's/"([^"]+)": "([^"]+)"/\1=\2/g' | grep "^name=" | grep -v "@" | sed 's/^name=//')

if [ $? -ne 0 ] || [ -z "$SECRET_KEYS" ]; then
echo "Failed to retrieve secret keys from Vault."
Expand All @@ -28,7 +28,7 @@ fi

# Iterate over each secret key and fetch the secret value
for key in $SECRET_KEYS; do
SECRET_VALUE=$(vlt secrets get --plaintext $key 2>/dev/null)
SECRET_VALUE=$(hcp vault-secrets secrets open $key | grep "Value:" | sed -E 's/Value:\s*(.*)/\1/; s/^[ \t]+|[ \t]+$//g' 2>/dev/null)

if [ $? -ne 0 ] || [ -z "$SECRET_VALUE" ]; then
echo "Failed to retrieve secret for key $key. Skipping."
Expand Down

0 comments on commit 258766f

Please sign in to comment.