Skip to content

Commit

Permalink
Fix gen_openapi.sh script to load plugins (hashicorp#17752)
Browse files Browse the repository at this point in the history
  • Loading branch information
averche authored and jayant07-yb committed Mar 15, 2023
1 parent 14cbea5 commit 8acccc3
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 28 deletions.
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

0 comments on commit 8acccc3

Please sign in to comment.