2 changed files with 72 additions and 0 deletions
@ -0,0 +1,71 @@
@@ -0,0 +1,71 @@
|
||||
#!/bin/bash |
||||
|
||||
# Copyright (C) 2020, Maxim Lihachev, <envrm@yandex.ru> |
||||
# |
||||
# This program is free software: you can redistribute it and/or modify it |
||||
# under the terms of the GNU General Public License as published by the Free |
||||
# Software Foundation, version 3. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, but WITHOUT |
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
||||
# more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License along with |
||||
# this program. If not, see <https://www.gnu.org/licenses/>. |
||||
|
||||
# |
||||
# Show all Vault paths and keys recursively |
||||
# |
||||
# Requirements: |
||||
# - vault-cli |
||||
# - jq |
||||
# |
||||
|
||||
export VAULT_ADDR=${VAULT_ADDR:-http://127.0.0.1:8200} |
||||
|
||||
rstc="\033[00m" |
||||
blue="\033[0;36m" |
||||
green="\033[1;32m" |
||||
|
||||
vault_list() { |
||||
vault kv list -format=yaml "$1" |
||||
} |
||||
|
||||
vault_keys() { |
||||
path=${1//\/\//\/} |
||||
keys=$(vault kv get -format=json "$path" 2>&- | jq -r -j '.data.data | keys | join("\n")' 2>&-) |
||||
|
||||
if [ -n "$keys" ]; then |
||||
while read -r key; do |
||||
echo -e "${blue}${path}/${green}${key}$rstc" |
||||
done <<<"$keys" |
||||
fi |
||||
} |
||||
|
||||
vault_tree() { |
||||
path=${1//\/\//\/} |
||||
list=$(vault_list "$path") |
||||
|
||||
echo -e "${blue}${path}${rstc}" |
||||
|
||||
if [ -n "$list" ] && [ "$list" != '{}' ]; then |
||||
while read -r dir; do |
||||
# printf "%s%s\n" "$INDENT" "$dir" |
||||
# echo "LIST ${path}/${dir#- }" |
||||
( vault_tree "${path}/${dir#- }"; ) |
||||
done <<<"$list" |
||||
# INDENT+=" " |
||||
else |
||||
: |
||||
vault_keys "$path" |
||||
fi |
||||
} |
||||
|
||||
if [ $# -eq 0 ]; then |
||||
echo "USAGE: $(basename "$0") [path]" |
||||
exit 1 |
||||
else |
||||
vault_tree "$1" |
||||
fi |
||||
|
Loading…
Reference in new issue