Created
November 11, 2019 17:06
-
-
Save mdjnewman/85e1ef147e0ff4e059a713f24871b354 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
# Usage (assumes you're logged in): | |
# vault-list secret/ | |
set -o nounset | |
set -o pipefail | |
set -o errexit | |
set -o pipefail | |
# Recursive function that will | |
# - List all the secrets in the given $path | |
# - Call itself for all path values in the given $path | |
function traverse() { | |
local readonly path="$1" | |
result=$(vault kv list -format=json $path 2>&1) | |
status=$? | |
if [ ! $status -eq 0 ]; then | |
if [[ $result =~ "permission denied" ]]; then | |
return | |
fi | |
echo >&2 "$result" | |
fi | |
for secret in $(echo "$result" | jq -r '.[]'); do | |
if [[ "$secret" == */ ]]; then | |
traverse "$path$secret" | |
else | |
echo "$path$secret" | |
fi | |
done | |
} | |
traverse $1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment