From: Petr Špaček Date: Wed, 18 Apr 2018 07:46:28 +0000 (+0200) Subject: prefill: configation syntax for multiple zones X-Git-Tag: v2.3.0~6^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6b4ce1f68ebebe035fb07e6d92eb430e9d99bf88;p=thirdparty%2Fknot-resolver.git prefill: configation syntax for multiple zones Only root zone can be imported (for now) but we want to avoid changing syntax when support for other zones is added. --- diff --git a/modules/prefill/prefill.lua b/modules/prefill/prefill.lua index 2f00984a0..2b30738f7 100644 --- a/modules/prefill/prefill.lua +++ b/modules/prefill/prefill.lua @@ -151,29 +151,50 @@ function prefill.deinit() end end -function prefill.config(config) - if not config or type(config) ~= 'table' then - error('[prefill] configuration must be in table') - end - if config.interval then - config.interval = tonumber(config.interval) - if config.interval < rz_interval_min then +-- process one item from configuration table +-- right now it supports only root zone because +-- prefill module uses global variables +local function config_zone(zone_cfg) + if zone_cfg.interval then + zone_cfg.interval = tonumber(zone_cfg.interval) + if zone_cfg.interval < rz_interval_min then error(string.format('[prefill] refresh interval %d s is too short, ' .. 'minimal interval is %d s', - config.interval, rz_interval_min)) + zone_cfg.interval, rz_interval_min)) end - rz_default_interval = config.interval - rz_cur_interval = config.interval + rz_default_interval = zone_cfg.interval + rz_cur_interval = zone_cfg.interval end - if not config.ca_dir then + if not zone_cfg.ca_dir then error('[prefill] option ca_dir must point ' .. 'to a directory with CA certificates in PEM format') else - local _, dir_obj = lfs.dir(config.ca_dir) + local _, dir_obj = lfs.dir(zone_cfg.ca_dir) dir_obj:close() end - rz_ca_dir = config.ca_dir + rz_ca_dir = zone_cfg.ca_dir +end + +function prefill.config(config) + local root_configured = false + if not config or type(config) ~= 'table' then + error('[prefill] configuration must be in table ' + .. '{owner name = {per-zone config}}') + end + for owner, zone_cfg in pairs(config) do + if owner ~= '.' then + error('[prefill] only root zone can be imported ' + .. 'at the moment') + else + config_zone(zone_cfg) + root_configured = true + end + end + if not root_configured then + error('[prefill] this module version requires configuration ' + .. 'for root zone') + end -- ability to change intervals prefill.deinit()