Last active
August 18, 2021 10:09
-
-
Save pulecp/4b6834c806c5f3e667e5ca99ef568b34 to your computer and use it in GitHub Desktop.
Recursively search a key-value storage in Vault for a regex
This file contains hidden or 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 | |
prefix_input="$1" | |
prefix=${prefix_input:=puppet/vault_hiera/} | |
read -p "Regex to search: " search | |
search_for_keys() { | |
if grep -q '\/$' <<< $1; then | |
subkeys=`vault kv list $1 | sed '1,2d'` | |
for subkey in $subkeys; do | |
search_for_keys "${1}${subkey}" | |
done | |
else | |
if egrep -q "$search" <<< `vault kv get -field=value $1 2>/dev/null`; then | |
printf "$1\n" | |
fi | |
fi | |
} | |
root_keys=`vault kv list $prefix | sed '1,2d'` | |
for key in $root_keys; do | |
search_for_keys "${prefix}${key}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment