Created
May 22, 2020 14:21
-
-
Save antonu17/6f87d2320502b3f2880e07a6bd5c2ba8 to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
set -e | |
function replace { | |
local readonly secret="$1" | |
data="$(vault kv get -format=json -field=data "$secret")" | |
updated=$(sed -e s/"$search"/"$replace"/g <(echo "$data")) | |
if [ "$data" != "$updated" ]; then | |
echo "Updating $secret" | |
echo "$updated" | vault kv put "$secret" - | |
fi | |
} | |
function traverse { | |
local readonly path="$1" | |
result=$(vault kv list -format=json "$path" 2>&1) || return | |
for secret in $(echo "$result" | jq -r '.[]'); do | |
if [[ "$secret" == */ ]]; then | |
traverse "$path$secret" | |
else | |
replace "$path$secret" | |
fi | |
done | |
} | |
path="${1%"/"}/" | |
search="$2" | |
replace="$3" | |
traverse "$path" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment