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

Change gen_openapi.sh to generate schema with generic mount paths #18934

Merged
merged 3 commits into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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/18934.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
openapi: Change gen_openapi.sh to generate schema with generic mount paths
```
16 changes: 10 additions & 6 deletions scripts/gen_openapi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ then
exit 1
fi

vault server -dev -dev-root-token-id=root &
../bin/vault server -dev -dev-root-token-id=root &
averche marked this conversation as resolved.
Show resolved Hide resolved
sleep 2
VAULT_PID=$!

Expand All @@ -36,7 +36,7 @@ while read -r line; do
codeLinesStarted=true
elif [[ $line == *"databasePlugins:"* ]] ; then
break
elif [ $codeLinesStarted = true ] && [[ $line == *"consts.Deprecated"* || $line == *"consts.PendingRemoval"* ]] ; then
elif [ $codeLinesStarted = true ] && [[ $line == *"consts.Deprecated"* || $line == *"consts.PendingRemoval"* || $line == *"consts.Removed"* ]] ; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this based off the comments in the registry like we previously had it? Or is this something new?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just out of curiosity b/c I don't remember anything that had said PendingRemoval or Removed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are no longer comments but actual struct values:

"app-id": {
Factory: removedFactory,
DeprecationStatus: consts.Removed,
},

What we are doing here (parsing Go code in shell) is kind of gross. I'm just fixing the script while we are still using it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh okay! gotcha. At least the deprecation status is codified in here though.

auth_plugin_previous=""
elif [ $codeLinesStarted = true ] && [[ $line =~ ^\s*\"(.*)\"\:.*$ ]] ; then
auth_plugin_current=${BASH_REMATCH[1]}
Expand All @@ -63,7 +63,7 @@ while read -r line; do
codeLinesStarted=true
elif [[ $line == *"addExternalPlugins("* ]] ; then
break
elif [ $codeLinesStarted = true ] && [[ $line == *"consts.Deprecated"* || $line == *"consts.PendingRemoval"* ]] ; then
elif [ $codeLinesStarted = true ] && [[ $line == *"consts.Deprecated"* || $line == *"consts.PendingRemoval"* || $line == *"consts.Removed"* ]] ; then
secrets_plugin_previous=""
elif [ $codeLinesStarted = true ] && [[ $line =~ ^\s*\"(.*)\"\:.*$ ]] ; then
secrets_plugin_current=${BASH_REMATCH[1]}
Expand Down Expand Up @@ -94,7 +94,7 @@ if [ -f $entRegFile ] && [[ -n "${VAULT_LICENSE}" ]]; then
codeLinesStarted=true
elif [[ $line == *"addExtPluginsEntImpl("* ]] ; then
break
elif [ $codeLinesStarted = true ] && [[ $line == *"consts.Deprecated"* || $line == *"consts.PendingRemoval"* ]] ; then
elif [ $codeLinesStarted = true ] && [[ $line == *"consts.Deprecated"* || $line == *"consts.PendingRemoval"* || $line == *"consts.Removed"* ]] ; then
secrets_plugin_previous=""
elif [ $codeLinesStarted = true ] && [[ $line =~ ^\s*\"(.*)\"\:.*$ ]] ; then
ent_plugin_current=${BASH_REMATCH[1]}
Expand All @@ -116,9 +116,13 @@ fi

# Output OpenAPI, optionally formatted
if [ "$1" == "-p" ]; then
curl -H "X-Vault-Token: root" "http://127.0.0.1:8200/v1/sys/internal/specs/openapi" | jq > openapi.json
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
else
curl -H "X-Vault-Token: root" "http://127.0.0.1:8200/v1/sys/internal/specs/openapi" > openapi.json
curl --header 'X-Vault-Token: root' \
--data '{"generic_mount_paths": true}' \
'http://127.0.0.1:8200/v1/sys/internal/specs/openapi' > openapi.json
fi

kill $VAULT_PID
Expand Down