add config file validation #2

Merged
luna merged 7 commits from config-validation into mistress 2022-12-07 18:50:30 +00:00
2 changed files with 13 additions and 7 deletions
Showing only changes of commit 06b8173ecb - Show all commits

View file

@ -109,17 +109,23 @@ local function writeSchemaErrors(errors, out)
out('sex')
end
local function loadConfigFile()
local function loadConfigFile(options)
local options = options or {}
local config_file_data = assert(findConfigFile(), 'no config file found, config path: ' .. config_path)
local config_file_function = assert(loadstring(config_file_data))
local config_object = config_file_function()
local schema_errors = validateConfigFile(config_object)
local total_count = table.pprint(schema_errors, {call=function() end})
if total_count > 0 then
log('CONFIG ERROR')
table.pprint(schema_errors, {call=log})
if options.validate then
local schema_errors = validateConfigFile(config_object)
local total_count = table.pprint(schema_errors, {call=function() end})
if total_count > 0 then
log('CONFIG ERROR')
table.pprint(schema_errors, {call=log})
end
end
return config_object
end

View file

@ -15,7 +15,7 @@ ctx:loadFromConfig(config.loadConfigFile())
return {
init=function ()
-- validate config and print out errors
config.loadConfigFile()
config.loadConfigFile({validate = true})
end,
access=function()
ctx:onRequest()