Skip to content

Commit

Permalink
fix: always inject disable field into plugin schema
Browse files Browse the repository at this point in the history
Fix apache/apisix-dashboard#1227

Signed-off-by: spacewander <[email protected]>
  • Loading branch information
spacewander committed Jan 13, 2021
1 parent 3e19b06 commit 686e080
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
25 changes: 20 additions & 5 deletions apisix/plugin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,27 @@ local function load_plugin(name, plugins_list, is_stream_plugin)
return
end

if plugin.schema and plugin.schema.type == "object" then
if not plugin.schema.properties or
core.table.nkeys(plugin.schema.properties) == 0
then
plugin.schema.properties = core.schema.plugin_disable_schema
if type(plugin.schema) ~= "table" then
core.log.error("invalid plugin [", name, "] schema field")
return
end

if not plugin.schema.properties then
plugin.schema.properties = {}
end

local properties = plugin.schema.properties
local plugin_injected_schema = core.schema.plugin_injected_schema

if properties['$comment'] ~= plugin_injected_schema['$comment'] then
if properties.disable then
core.log.error("invalid plugin [", name,
"]: found forbidden 'disable' field in the schema")
return
end

properties.disable = plugin_injected_schema.disable
properties['$comment'] = plugin_injected_schema['$comment']
end

plugin.name = name
Expand Down
7 changes: 5 additions & 2 deletions apisix/schema_def.lua
Original file line number Diff line number Diff line change
Expand Up @@ -739,8 +739,11 @@ _M.plugins = {
_M.id_schema = id_schema


_M.plugin_disable_schema = {
disable = {type = "boolean"}
_M.plugin_injected_schema = {
["$comment"] = "this is a mark for our injected plugin schema",
disable = {
type = "boolean",
}
}


Expand Down
16 changes: 13 additions & 3 deletions t/control/schema.t
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,26 @@ __DATA__
"upstream": {"type":"object"},
"upstream_hash_header_schema": {"type":"string"},
"upstream_hash_vars_schema": {"type":"string"},
},
},]] .. [[
"plugins": {
"example-plugin": {
"version": 0.1,
"priority": 0,
"schema": {"type":"object"},
"schema": {
"type":"object",
"properties": {
"disable": {"type": "boolean"}
}
},
"metadata_schema": {"type":"object"}
},
"mqtt-proxy": {
"schema": {"type":"object"},
"schema": {
"type":"object",
"properties": {
"disable": {"type": "boolean"}
}
},
"priority": 1000
},
"basic-auth": {
Expand Down

0 comments on commit 686e080

Please sign in to comment.