Skip to content

Commit

Permalink
feat: support default values for plugins (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
lingsamuel committed Sep 20, 2023
1 parent 523dfd8 commit 198d901
Show file tree
Hide file tree
Showing 17 changed files with 1,695 additions and 39 deletions.
2 changes: 1 addition & 1 deletion cmd/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func newDumpCmd() *cobra.Command {
},
}

cmd.Flags().StringP("output", "o", "", "output file path")
cmd.Flags().StringP("output", "o", "/dev/stdout", "output file path")

return cmd
}
Expand Down
52 changes: 52 additions & 0 deletions pkg/api/apisix/types/data/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# APISIX Plugins Default Values Generation From Schema

The `default_values.json` file contains default values of all APISIX plugins.

It is generated by the script `plugin_schemas.lua`.

## How to Use

Put the `plugin_schemas.lua` under `<APISIX_ROOT>/apisix/admin/` folder.

Then edit `<APISIX_ROOT>/apisix/admin/init.lua`, add the utility function we need.

```lua
local function get_plugins_filtered_schema_list()
set_ctx_and_check_token()
local args = get_uri_args()
local subsystem = args["subsystem"]
-- If subsystem is passed then it should be either http or stream.
-- If it is not passed/nil then http will be default.
subsystem = subsystem or "http"
if subsystem == "http" or subsystem == "stream" then
local plugins = require("apisix.admin.plugin_schemas").get_plugins_filtered_schema_list(subsystem)
core.response.exit(200, plugins)
end
core.response.exit(400,"invalid subsystem passed")
end
```

After this, find `uri_route` variable and add the entry we need:
```lua
local uri_route = {
// ...
{
paths = [[/apisix/admin/plugins/list]],
methods = {"GET"},
handler = get_plugins_list,
},
{
paths = [[/apisix/admin/plugins/filtered_schema_list]],
methods = {"GET"},
handler = get_plugins_filtered_schema_list,
},
// ...
```

Restart the APISIX, run the following command to generate default values file:

```bash
curl http://127.0.0.1:9180/apisix/admin/plugins/filtered_schema_list -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X GET | jq --sort-keys . > default_values.json
```

We use `jq` here to sort the output keys.

0 comments on commit 198d901

Please sign in to comment.