Created
July 15, 2022 17:42
-
-
Save ml4/2d9d6205dbc5d8c15e9ed782f77206d9 to your computer and use it in GitHub Desktop.
Recursive list of Vault Enterprise namespaces
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 | |
function list_namespace { | |
entry_point=$(echo ${1} | sed 's/\/$//') | |
echo "${entry_point}" | |
## first, check if root ns, and if so collect children slightly differently due to path specification | |
# | |
if [[ "${entry_point}" == "root" ]] | |
then | |
child_namespaces=$(vault namespace list -format=json | jq -r .[] | tr '\012' ' ' | tr -d '/') | |
entry_point= | |
else | |
child_namespaces=$(vault namespace list -namespace ${entry_point} -format=json | jq -r .[] | tr '\012' ' ') | |
child_namespaces=$(echo ${child_namespaces} | sed 's/ $//') | |
if [[ -n ${child_namespaces} ]] | |
then | |
child_namespaces=$(echo ${child_namespaces} | sed -e "s~^~${entry_point}/~" -e "s~ ~ ${entry_point}/~") | |
fi | |
fi | |
## iterate found child namespaces | |
# | |
if [[ -n ${child_namespaces} ]] | |
then | |
for namespace in $(echo ${child_namespaces}) | |
do | |
list_namespace "${namespace}" | |
done | |
fi | |
} | |
if [[ -z "${1}" ]] | |
then | |
list_namespace root | |
else | |
list_namespace ${1} | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment