Browse Source

++vault-kv-tree

master
Maxim Likhachev 5 years ago
parent
commit
ed1e6cedf2
  1. 1
      README.md
  2. 71
      vault-kv-tree

1
README.md

@ -85,6 +85,7 @@ will create the symbolic link for each script in the \<path> directory. @@ -85,6 +85,7 @@ will create the symbolic link for each script in the \<path> directory.
- [how](how) shows dev cheat sheets using [cheat.sh](https://cheat.sh).
- [robodoc2html](robodoc2html) converts a documentation in the robodoc format into html.
- [todolist](todolist) shows all `TODO` notes in current git repository.
- [vault-kv-tree](vault-kv-tree) shows all HashiCorp Vault's paths and keys recursively.
- [utable](utable) shows a Unicode table.
### Git

71
vault-kv-tree

@ -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…
Cancel
Save