Skip to content

Commit

Permalink
Update push_secrets.sh to use hcp instead of vlt
Browse files Browse the repository at this point in the history
  • Loading branch information
kenzysoror committed Sep 21, 2024
1 parent 883489f commit 43e4aa1
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions push_secrets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ 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 exit if it doesn't
if [ ! -f "$ENV_FILE" ]; then
Expand All @@ -21,19 +21,19 @@ fi

# Fetch all existing secret keys and delete them
echo "Fetching and deleting all existing secrets..."
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/^"([^"]*)"\s*:\s*"([^"]*)"$/\1=\2/' | grep "^name=" | grep -v "@" | sed 's/^name=//')

for secret_key in $SECRET_KEYS; do
echo "Deleting secret with name $secret_key"
vlt secrets delete "$secret_key" || echo "Failed to delete secret $secret_key."
hcp vault-secrets secrets delete "$secret_key" --app=sistema || echo "Failed to delete secret $secret_key."
echo ""
done

# Read the secrets from the .env file and create them
while IFS='=' read -r key value; do
if [ -n "$key" ] && [ -n "$value" ]; then
# Create the secret with the new value
vlt secrets create "$key"="$value" || echo "Failed to create secret for $key."
echo -n "$value" | hcp vault-secrets secrets create "$key" --app=sistema --data-file=- || echo "Failed to create secret for $key."
echo ""
fi
done < "$ENV_FILE"
Expand Down

0 comments on commit 43e4aa1

Please sign in to comment.