Skip to content

Instantly share code, notes, and snippets.

@SnuktheGreat
Created July 18, 2017 11:57
Show Gist options
  • Save SnuktheGreat/292602e97ce28ae42593fe039e5f8da2 to your computer and use it in GitHub Desktop.
Save SnuktheGreat/292602e97ce28ae42593fe039e5f8da2 to your computer and use it in GitHub Desktop.
Script to use "vault list" to find stuff in vault.
#!/usr/bin/env bash
if [ $# -lt 1 ] || [ $# -gt 2 ]; then
cat << EOF
Usage: vault_find [needle] [haystack*]
Searches through the entire vault directory to find the given needle in the given haystack.
Warning: This script uses "vault list" and can be quite slow.
options:
needle: The literal string to look for.
haystack: (Optional, defaults to "secret/") The root from which to start the search.
EOF
exit 1
fi
function find {
local VAULT_PATHS=($(vault list $1));
local I=0
for VP in "${VAULT_PATHS[@]}"; do
if [ "$I" -ne "0" ] || [ "${VP}" != "Keys" ]; then
if [[ "${VP}" == *"$2"* ]]; then
echo "$1${VP}"
fi
if [ "${VP: -1}" == "/" ]; then
find "$1${VP}" "$2"
fi
fi
((I++))
done
}
find "${2:-secret/}" $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment