-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support default values for plugins (#52)
- Loading branch information
1 parent
523dfd8
commit 198d901
Showing
17 changed files
with
1,695 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
Oops, something went wrong.