Skip to content

Commit

Permalink
Merge branch 'main' into vihaan/seeding-script
Browse files Browse the repository at this point in the history
  • Loading branch information
ChinemeremChigbo committed Sep 28, 2024
2 parents 52ccaae + 01dcb40 commit d4ef83b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
7 changes: 4 additions & 3 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ EMAIL_PASS=
EMAIL_SERVICE=
EMAIL_USER=
GDRIVE_CLIENT_EMAIL=
GDRIVE_CLIENTID=
GDRIVE_PRIVTKEY=
GDRIVE_PROJECTID=
GDRIVE_CLIENT_ID=
GDRIVE_PRIVATE_KEY=
GDRIVE_PROJECT_ID=
POSTGRES_DATABASE=
POSTGRES_PASSWORD=
POSTGRES_PORT=
POSTGRES_URL_NON_POOLING=
POSTGRES_USER=
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
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ services:
- POSTGRES_DATABASE=${POSTGRES_DATABASE}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- POSTGRES_PORT=${POSTGRES_PORT}
- DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DATABASE}
db:
image: postgres:16-alpine
ports:
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 d4ef83b

Please sign in to comment.