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=$!
|
|
|
|
|
2022-11-01 21:32:54 +00:00
|
|
|
export VAULT_ADDR=http://127.0.0.1:8200
|
2018-11-05 20:24:39 +00:00
|
|
|
|
2022-11-01 21:32:54 +00:00
|
|
|
echo "Mounting all builtin plugins..."
|
|
|
|
|
|
|
|
# Enable auth plugins
|
2022-03-23 16:45:39 +00:00
|
|
|
codeLinesStarted=false
|
2022-11-01 21:32:54 +00:00
|
|
|
|
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
|
2022-11-01 21:32:54 +00:00
|
|
|
elif [[ $line == *"databasePlugins:"* ]] ; then
|
2022-03-23 16:45:39 +00:00
|
|
|
break
|
2023-01-31 23:37:19 +00:00
|
|
|
elif [ $codeLinesStarted = true ] && [[ $line == *"consts.Deprecated"* || $line == *"consts.PendingRemoval"* || $line == *"consts.Removed"* ]] ; then
|
2022-11-01 21:32:54 +00:00
|
|
|
auth_plugin_previous=""
|
|
|
|
elif [ $codeLinesStarted = true ] && [[ $line =~ ^\s*\"(.*)\"\:.*$ ]] ; then
|
|
|
|
auth_plugin_current=${BASH_REMATCH[1]}
|
|
|
|
|
|
|
|
if [[ -n "${auth_plugin_previous}" ]] ; then
|
|
|
|
echo "enabling auth plugin: ${auth_plugin_previous}"
|
|
|
|
vault auth enable "${auth_plugin_previous}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
auth_plugin_previous="${auth_plugin_current}"
|
2022-03-23 16:45:39 +00:00
|
|
|
fi
|
|
|
|
done <../../vault/helper/builtinplugins/registry.go
|
|
|
|
|
2022-11-01 21:32:54 +00:00
|
|
|
if [[ -n "${auth_plugin_previous}" ]] ; then
|
|
|
|
echo "enabling auth plugin: ${auth_plugin_previous}"
|
|
|
|
vault auth enable "${auth_plugin_previous}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Enable secrets plugins
|
2022-03-23 16:45:39 +00:00
|
|
|
codeLinesStarted=false
|
2022-11-01 21:32:54 +00:00
|
|
|
|
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
|
2022-11-01 21:32:54 +00:00
|
|
|
elif [[ $line == *"addExternalPlugins("* ]] ; then
|
2022-03-23 16:45:39 +00:00
|
|
|
break
|
2023-01-31 23:37:19 +00:00
|
|
|
elif [ $codeLinesStarted = true ] && [[ $line == *"consts.Deprecated"* || $line == *"consts.PendingRemoval"* || $line == *"consts.Removed"* ]] ; then
|
2022-11-01 21:32:54 +00:00
|
|
|
secrets_plugin_previous=""
|
|
|
|
elif [ $codeLinesStarted = true ] && [[ $line =~ ^\s*\"(.*)\"\:.*$ ]] ; then
|
|
|
|
secrets_plugin_current=${BASH_REMATCH[1]}
|
|
|
|
|
|
|
|
if [[ -n "${secrets_plugin_previous}" ]] ; then
|
|
|
|
echo "enabling secrets plugin: ${secrets_plugin_previous}"
|
|
|
|
vault secrets enable "${secrets_plugin_previous}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
secrets_plugin_previous="${secrets_plugin_current}"
|
2022-03-23 16:45:39 +00:00
|
|
|
fi
|
|
|
|
done <../../vault/helper/builtinplugins/registry.go
|
2018-11-05 20:24:39 +00:00
|
|
|
|
2022-11-01 21:32:54 +00:00
|
|
|
if [[ -n "${secrets_plugin_previous}" ]] ; then
|
|
|
|
echo "enabling secrets plugin: ${secrets_plugin_previous}"
|
|
|
|
vault secrets enable "${secrets_plugin_previous}"
|
|
|
|
fi
|
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-11-01 21:32:54 +00:00
|
|
|
if [ -f $entRegFile ] && [[ -n "${VAULT_LICENSE}" ]]; then
|
|
|
|
vault write sys/license text="${VAULT_LICENSE}"
|
2022-03-23 16:45:39 +00:00
|
|
|
|
2022-11-01 21:32:54 +00:00
|
|
|
codeLinesStarted=false
|
|
|
|
|
|
|
|
while read -r line; do
|
|
|
|
if [[ $line == *"ExternalPluginsEnt:"* ]] ; then
|
|
|
|
codeLinesStarted=true
|
|
|
|
elif [[ $line == *"addExtPluginsEntImpl("* ]] ; then
|
|
|
|
break
|
2023-01-31 23:37:19 +00:00
|
|
|
elif [ $codeLinesStarted = true ] && [[ $line == *"consts.Deprecated"* || $line == *"consts.PendingRemoval"* || $line == *"consts.Removed"* ]] ; then
|
2022-11-01 21:32:54 +00:00
|
|
|
secrets_plugin_previous=""
|
|
|
|
elif [ $codeLinesStarted = true ] && [[ $line =~ ^\s*\"(.*)\"\:.*$ ]] ; then
|
|
|
|
ent_plugin_current=${BASH_REMATCH[1]}
|
|
|
|
|
|
|
|
if [[ -n "${ent_plugin_previous}" ]] ; then
|
|
|
|
echo "enabling enterprise plugin: ${ent_plugin_previous}"
|
|
|
|
vault secrets enable "${ent_plugin_previous}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
ent_plugin_previous="${ent_plugin_current}"
|
|
|
|
fi
|
|
|
|
done <$entRegFile
|
|
|
|
|
|
|
|
if [[ -n "${ent_plugin_previous}" ]] ; then
|
|
|
|
echo "enabling enterprise plugin: ${ent_plugin_previous}"
|
|
|
|
vault secrets enable "${ent_plugin_previous}"
|
2022-03-23 16:45:39 +00:00
|
|
|
fi
|
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
|
2023-01-31 23:37:19 +00:00
|
|
|
curl --header 'X-Vault-Token: root' \
|
|
|
|
--data '{"generic_mount_paths": true}' \
|
|
|
|
'http://127.0.0.1:8200/v1/sys/internal/specs/openapi' | jq > openapi.json
|
2019-05-03 22:12:24 +00:00
|
|
|
else
|
2023-01-31 23:37:19 +00:00
|
|
|
curl --header 'X-Vault-Token: root' \
|
|
|
|
--data '{"generic_mount_paths": true}' \
|
|
|
|
'http://127.0.0.1:8200/v1/sys/internal/specs/openapi' > openapi.json
|
2019-05-03 22:12:24 +00:00
|
|
|
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"
|