Last active
July 4, 2022 15:50
-
-
Save daemswibowo/42995eefb25a13da0dede80fe476040f to your computer and use it in GitHub Desktop.
Bash generate .env file from vault
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
if [ -z "$TOKEN" ]; then | |
echo "Token not provided!" | |
else | |
if [ -z "$API_URL" ]; then | |
echo "Missing the API url, I don't know where the env is :/" | |
else | |
echo "Getting environment variable from $API_URL" | |
if [ -z "$OUTPUT" ]; then | |
# set default output name | |
OUTPUT=.env | |
fi | |
curl -X 'GET' \ | |
"$API_URL" \ | |
-H 'accept: */*' \ | |
-H "X-Vault-Token: $TOKEN" | jq '.data.data' | jq -r 'to_entries|map("\(.key)=\(.value|tostring)")|.[]' | sed 's,.\(.*\).$,\1,g' > $OUTPUT | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Generating ENV file from Vault
Requirements: jq => https://stedolan.github.io/jq/
Run this on your terminal:
Disclaimer: This command tested only on Mac OS, not sure if it work or not for windows or linux
This will generate
.env
file if success getting the environment secret from vault.Envronment Variables
.env