Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix gen_openapi.sh script to load plugins #17752

Merged
merged 3 commits into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog/17752.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
openapi: fix gen_openapi.sh script to correctly load vault plugins
```
94 changes: 66 additions & 28 deletions scripts/gen_openapi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,56 +24,94 @@ vault server -dev -dev-root-token-id=root &
sleep 2
VAULT_PID=$!

echo "Mounting all builtin backends..."
export VAULT_ADDR=http://127.0.0.1:8200

# Read auth backends
echo "Mounting all builtin plugins..."

# Enable auth plugins
codeLinesStarted=false
inQuotesRegex='".*"'

while read -r line; do
if [[ $line == *"credentialBackends:"* ]] ; then
codeLinesStarted=true
elif [ $codeLinesStarted = true ] && [[ $line = *"}"* ]] ; then
elif [[ $line == *"databasePlugins:"* ]] ; then
break
elif [ $codeLinesStarted = true ] && [[ $line =~ $inQuotesRegex ]] && [[ $line != *"Deprecated"* ]] ; then
backend=${BASH_REMATCH[0]}
plugin=$(sed -e 's/^"//' -e 's/"$//' <<<"$backend")
vault auth enable "${plugin}"
elif [ $codeLinesStarted = true ] && [[ $line == *"consts.Deprecated"* || $line == *"consts.PendingRemoval"* ]] ; then
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}"
fi
done <../../vault/helper/builtinplugins/registry.go

# Read secrets backends
if [[ -n "${auth_plugin_previous}" ]] ; then
echo "enabling auth plugin: ${auth_plugin_previous}"
vault auth enable "${auth_plugin_previous}"
fi

# Enable secrets plugins
codeLinesStarted=false

while read -r line; do
if [[ $line == *"logicalBackends:"* ]] ; then
codeLinesStarted=true
elif [ $codeLinesStarted = true ] && [[ $line = *"}"* ]] ; then
elif [[ $line == *"addExternalPlugins("* ]] ; then
break
elif [ $codeLinesStarted = true ] && [[ $line =~ $inQuotesRegex ]] && [[ $line != *"Deprecated"* ]] ; then
backend=${BASH_REMATCH[0]}
plugin=$(sed -e 's/^"//' -e 's/"$//' <<<"$backend")
vault secrets enable "${plugin}"
elif [ $codeLinesStarted = true ] && [[ $line == *"consts.Deprecated"* || $line == *"consts.PendingRemoval"* ]] ; then
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}"
fi
done <../../vault/helper/builtinplugins/registry.go

if [[ -n "${secrets_plugin_previous}" ]] ; then
echo "enabling secrets plugin: ${secrets_plugin_previous}"
vault secrets enable "${secrets_plugin_previous}"
fi

# Enable enterprise features
entRegFile=../../vault/helper/builtinplugins/registry_util_ent.go
if [ -f $entRegFile ] && [[ -n "$VAULT_LICENSE" ]]; then
vault write sys/license text="$VAULT_LICENSE"
if [ -f $entRegFile ] && [[ -n "${VAULT_LICENSE}" ]]; then
vault write sys/license text="${VAULT_LICENSE}"

inQuotesRegex='".*"'
codeLinesStarted=false
while read -r line; do
if [[ $line == *"ExternalPluginsEnt"* ]] ; then
codeLinesStarted=true
elif [ $codeLinesStarted = true ] && [[ $line = *"}"* ]] ; then
break
elif [ $codeLinesStarted = true ] && [[ $line =~ $inQuotesRegex ]] && [[ $line != *"Deprecated"* ]] ; then
backend=${BASH_REMATCH[0]}
plugin=$(sed -e 's/^"//' -e 's/"$//' <<<"$backend")
vault secrets enable "${plugin}"
codeLinesStarted=false

while read -r line; do
if [[ $line == *"ExternalPluginsEnt:"* ]] ; then
codeLinesStarted=true
elif [[ $line == *"addExtPluginsEntImpl("* ]] ; then
break
elif [ $codeLinesStarted = true ] && [[ $line == *"consts.Deprecated"* || $line == *"consts.PendingRemoval"* ]] ; then
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}"
fi
done <$entRegFile
fi

# Output OpenAPI, optionally formatted
Expand Down