2022-03-23 16:45:39 +00:00
|
|
|
#!/bin/bash
|
2018-11-05 20:24:39 +00:00
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# Generate an OpenAPI document for all backends.
|
|
|
|
#
|
|
|
|
# Assumptions:
|
|
|
|
#
|
|
|
|
# 1. Vault has been checked out at an appropriate version and built
|
|
|
|
# 2. vault executable is in your path
|
2018-11-30 00:08:44 +00:00
|
|
|
# 3. Vault isn't already running
|
2022-03-23 16:45:39 +00:00
|
|
|
# 4. jq is installed
|
|
|
|
|
|
|
|
cd "$(dirname "${BASH_SOURCE[0]}")"
|
2018-11-05 20:24:39 +00:00
|
|
|
|
|
|
|
echo "Starting Vault..."
|
|
|
|
if pgrep -x "vault" > /dev/null
|
|
|
|
then
|
|
|
|
echo "Vault is already running. Aborting."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
vault server -dev -dev-root-token-id=root &
|
|
|
|
sleep 2
|
|
|
|
VAULT_PID=$!
|
|
|
|
|
|
|
|
echo "Mounting all builtin backends..."
|
|
|
|
|
2022-03-23 16:45:39 +00:00
|
|
|
# Read auth backends
|
|
|
|
codeLinesStarted=false
|
|
|
|
inQuotesRegex='".*"'
|
2022-03-23 21:43:02 +00:00
|
|
|
while read -r line; do
|
2022-03-23 16:45:39 +00:00
|
|
|
if [[ $line == *"credentialBackends:"* ]] ; then
|
|
|
|
codeLinesStarted=true
|
|
|
|
elif [ $codeLinesStarted = true ] && [[ $line = *"}"* ]] ; then
|
|
|
|
break
|
|
|
|
elif [ $codeLinesStarted = true ] && [[ $line =~ $inQuotesRegex ]] && [[ $line != *"Deprecated"* ]] ; then
|
|
|
|
backend=${BASH_REMATCH[0]}
|
2022-03-23 21:43:02 +00:00
|
|
|
plugin=$(sed -e 's/^"//' -e 's/"$//' <<<"$backend")
|
2022-03-23 16:45:39 +00:00
|
|
|
vault auth enable "${plugin}"
|
|
|
|
fi
|
|
|
|
done <../../vault/helper/builtinplugins/registry.go
|
|
|
|
|
|
|
|
# Read secrets backends
|
|
|
|
codeLinesStarted=false
|
2022-03-23 21:43:02 +00:00
|
|
|
while read -r line; do
|
2022-03-23 16:45:39 +00:00
|
|
|
if [[ $line == *"logicalBackends:"* ]] ; then
|
|
|
|
codeLinesStarted=true
|
|
|
|
elif [ $codeLinesStarted = true ] && [[ $line = *"}"* ]] ; then
|
|
|
|
break
|
|
|
|
elif [ $codeLinesStarted = true ] && [[ $line =~ $inQuotesRegex ]] && [[ $line != *"Deprecated"* ]] ; then
|
|
|
|
backend=${BASH_REMATCH[0]}
|
2022-03-23 21:43:02 +00:00
|
|
|
plugin=$(sed -e 's/^"//' -e 's/"$//' <<<"$backend")
|
2022-03-23 16:45:39 +00:00
|
|
|
vault secrets enable "${plugin}"
|
|
|
|
fi
|
|
|
|
done <../../vault/helper/builtinplugins/registry.go
|
2018-11-05 20:24:39 +00:00
|
|
|
|
|
|
|
|
2020-04-15 16:12:12 +00:00
|
|
|
# Enable enterprise features
|
2022-03-23 16:45:39 +00:00
|
|
|
entRegFile=../../vault/helper/builtinplugins/registry_util_ent.go
|
2022-03-23 21:43:02 +00:00
|
|
|
if [ -f $entRegFile ] && [[ -n "$VAULT_LICENSE" ]]; then
|
2020-04-15 16:12:12 +00:00
|
|
|
vault write sys/license text="$VAULT_LICENSE"
|
2022-03-23 16:45:39 +00:00
|
|
|
|
|
|
|
inQuotesRegex='".*"'
|
|
|
|
codeLinesStarted=false
|
2022-03-23 21:43:02 +00:00
|
|
|
while read -r line; do
|
2022-03-23 16:45:39 +00:00
|
|
|
if [[ $line == *"ExternalPluginsEnt"* ]] ; then
|
|
|
|
codeLinesStarted=true
|
|
|
|
elif [ $codeLinesStarted = true ] && [[ $line = *"}"* ]] ; then
|
|
|
|
break
|
|
|
|
elif [ $codeLinesStarted = true ] && [[ $line =~ $inQuotesRegex ]] && [[ $line != *"Deprecated"* ]] ; then
|
|
|
|
backend=${BASH_REMATCH[0]}
|
2022-03-23 21:43:02 +00:00
|
|
|
plugin=$(sed -e 's/^"//' -e 's/"$//' <<<"$backend")
|
2022-03-23 16:45:39 +00:00
|
|
|
vault secrets enable "${plugin}"
|
|
|
|
fi
|
|
|
|
done <$entRegFile
|
2019-07-25 00:03:03 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Output OpenAPI, optionally formatted
|
2019-05-03 22:12:24 +00:00
|
|
|
if [ "$1" == "-p" ]; then
|
|
|
|
curl -H "X-Vault-Token: root" "http://127.0.0.1:8200/v1/sys/internal/specs/openapi" | jq > openapi.json
|
|
|
|
else
|
|
|
|
curl -H "X-Vault-Token: root" "http://127.0.0.1:8200/v1/sys/internal/specs/openapi" > openapi.json
|
|
|
|
fi
|
2018-11-05 20:24:39 +00:00
|
|
|
|
|
|
|
kill $VAULT_PID
|
|
|
|
sleep 1
|
|
|
|
|
2022-03-23 21:43:02 +00:00
|
|
|
echo
|
|
|
|
echo "openapi.json generated"
|