Skip to content

Commit

Permalink
fix: add debug yaml validation
Browse files Browse the repository at this point in the history
  • Loading branch information
qizhendong1 committed Jun 7, 2022
1 parent 22e23ba commit c48a0ab
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions apisix/debug.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ local log = require("apisix.core.log")
local profile = require("apisix.core.profile")
local lfs = require("lfs")
local inspect = require("inspect")
local jsonschema = require("jsonschema")
local io = io
local ngx = ngx
local re_find = ngx.re.find
Expand All @@ -38,6 +39,58 @@ local debug_yaml_ctime
local _M = {version = 0.1}


local config_schema = {
type = "object",
properties = {
basic = {
properties = {
enable = {
type = "boolean",
},
}
},
http_filter = {
properties = {
enable = {
type = "boolean",
},
enable_header_name = {
type = "string",
},
}
},
hook_conf = {
properties = {
enable = {
type = "boolean",
},
name = {
type = "string",
},
log_level = {
enum = {"debug", "info", "notice", "warn", "error",
"crit", "alert","emerg"},
},
is_print_input_args = {
type = "boolean",
},
is_print_return_value = {
type = "boolean",
},
}
},
hook_phase = {
properties = {
apisix = {
type = "array",
}
},
},
},
required = {"basic", "http_filter", "hook_conf", "hook_phase"}
}


local function read_debug_yaml()
local attributes, err = lfs.attributes(debug_yaml_path)
if not attributes then
Expand Down Expand Up @@ -93,6 +146,13 @@ local function read_debug_yaml()
debug_yaml_new.hooks = debug_yaml_new.hooks or {}
debug_yaml = debug_yaml_new
debug_yaml_ctime = last_change_time

-- validate the yaml config
local validator = jsonschema.generate_validator(config_schema)
local ok, err = validator(debug_yaml)
if not ok then
log.error("failed to validate config" .. err)
end
end


Expand Down

0 comments on commit c48a0ab

Please sign in to comment.