Skip to content

Instantly share code, notes, and snippets.

@ml4
Created July 15, 2022 17:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ml4/2d9d6205dbc5d8c15e9ed782f77206d9 to your computer and use it in GitHub Desktop.
Save ml4/2d9d6205dbc5d8c15e9ed782f77206d9 to your computer and use it in GitHub Desktop.
Recursive list of Vault Enterprise namespaces
#!/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