Skip to content

Commit

Permalink
Merge pull request #32 from uwblueprint/aadhyaaa/use-hcp-in-setup_sec…
Browse files Browse the repository at this point in the history
…rets

Modify setup_secrets.sh to use hcp instead of vlt
  • Loading branch information
ChinemeremChigbo authored Sep 23, 2024
2 parents 3c99421 + 937dade commit d37e440
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ npm install
- In the folder where you cloned the Sistema repository, log into Vault

```bash
vlt login
hcp auth login
```

- Configure the Vault Command Line Interface

```bash
vlt config init
hcp profile init
```

- Select the `sistema` Organization and Project
Expand Down
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 d37e440

Please sign in to comment.