From fd4badc09486e35e239a76eb9086159960ffd79e Mon Sep 17 00:00:00 2001 From: YuanSheng Wang Date: Sat, 14 Mar 2020 09:34:34 +0800 Subject: [PATCH] bugfix: plugin node-status and heartbeat don't have schema. (#1249) --- lua/apisix/plugins/heartbeat.lua | 17 +++++++++++++++++ lua/apisix/plugins/node-status.lua | 17 +++++++++++++++++ t/admin/plugins.t | 20 ++++++++++++++++++++ 3 files changed, 54 insertions(+) diff --git a/lua/apisix/plugins/heartbeat.lua b/lua/apisix/plugins/heartbeat.lua index 66e0faaa0cc6..0a6cf76cbdc5 100644 --- a/lua/apisix/plugins/heartbeat.lua +++ b/lua/apisix/plugins/heartbeat.lua @@ -24,13 +24,30 @@ local ngx = ngx local apisix_heartbeat_addr = "https://www.iresty.com/apisix/heartbeat?" +local schema = { + type = "object", + additionalProperties = false, +} + + local _M = { version = 0.1, priority = 100, name = plugin_name, + schema = schema, } +function _M.check_schema(conf) + local ok, err = core.schema.check(schema, conf) + if not ok then + return false, err + end + + return true +end + + local function request_apisix_svr(args) local http_cli, err = http.new() if err then diff --git a/lua/apisix/plugins/node-status.lua b/lua/apisix/plugins/node-status.lua index 112813a0e93e..15c65bb4f6d3 100644 --- a/lua/apisix/plugins/node-status.lua +++ b/lua/apisix/plugins/node-status.lua @@ -23,10 +23,17 @@ local apisix_id = core.id.get() local ipairs = ipairs +local schema = { + type = "object", + additionalProperties = false, +} + + local _M = { version = 0.1, priority = 1000, name = plugin_name, + schema = schema, } @@ -67,6 +74,16 @@ local function collect() end +function _M.check_schema(conf) + local ok, err = core.schema.check(schema, conf) + if not ok then + return false, err + end + + return true +end + + function _M.api() return { { diff --git a/t/admin/plugins.t b/t/admin/plugins.t index 106b0363151a..85a9c10386d3 100644 --- a/t/admin/plugins.t +++ b/t/admin/plugins.t @@ -54,3 +54,23 @@ GET /apisix/admin/plugins/limit-req {"properties":{"rate":{"minimum":0,"type":"number"},"burst":{"minimum":0,"type":"number"},"key":{"enum":["remote_addr","server_addr","http_x_real_ip","http_x_forwarded_for"],"type":"string"},"rejected_code":{"minimum":200,"type":"integer"}},"required":["rate","burst","key","rejected_code"],"type":"object"} --- no_error_log [error] + + + +=== TEST 4: get plugin node-status schema +--- request +GET /apisix/admin/plugins/node-status +--- response_body +{"additionalProperties":false,"type":"object"} +--- no_error_log +[error] + + + +=== TEST 5: get plugin heartbeat schema +--- request +GET /apisix/admin/plugins/heartbeat +--- response_body +{"additionalProperties":false,"type":"object"} +--- no_error_log +[error]