aboutsummaryrefslogtreecommitdiffstats
path: root/lualib/rspamd_config_transform.lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2017-11-06 08:15:48 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2017-11-06 08:15:48 +0000
commitec03ec15402c65ebe69576ef7d6aa3782ab83a2f (patch)
treec95a5fc33d5f3c698b31ff2d3c906276a77f35cb /lualib/rspamd_config_transform.lua
parent429a88038080bd9684d06f4fac5c9476579cb874 (diff)
downloadrspamd-ec03ec15402c65ebe69576ef7d6aa3782ab83a2f.tar.gz
rspamd-ec03ec15402c65ebe69576ef7d6aa3782ab83a2f.zip
[Minor] Another transform merge fix
Diffstat (limited to 'lualib/rspamd_config_transform.lua')
-rw-r--r--lualib/rspamd_config_transform.lua53
1 files changed, 39 insertions, 14 deletions
diff --git a/lualib/rspamd_config_transform.lua b/lualib/rspamd_config_transform.lua
index 006c22d45..08072d7ff 100644
--- a/lualib/rspamd_config_transform.lua
+++ b/lualib/rspamd_config_transform.lua
@@ -21,26 +21,34 @@ local function override_defaults(def, override)
if not override then
return def
end
+ if not def then
+ return override
+ end
for k,v in pairs(override) do
- if k ~= 'selector' and k ~= 'backend' then
- if def[k] then
- if type(v) == 'table' then
- override_defaults(def[k], v)
- else
- def[k] = v
- end
+ if def[k] then
+ if type(v) == 'table' then
+ def[k] = override_defaults(def[k], v)
else
def[k] = v
end
+ else
+ def[k] = v
end
end
+
+ return def
+end
+
+local function is_implicit(t)
+ local mt = getmetatable(t)
+
+ return mt and mt.class and mt.class == 'ucl.type.impl_array'
end
local function metric_pairs(t)
-- collect the keys
local keys = {}
- local mt = getmetatable(t)
- local implicit_array = mt and mt.class and mt.class == 'ucl.type.impl_array'
+ local implicit_array = is_implicit(t)
local function gen_keys(tbl)
if implicit_array then
@@ -53,7 +61,16 @@ local function metric_pairs(t)
-- group {name = "foo" ... } + group "blah" { ... }
for gr_name,gr in pairs(v) do
if type(gr_name) ~= 'number' then
- table.insert(keys, {gr_name, gr})
+ -- We can also have implicit arrays here
+ local gr_implicit = is_implicit(gr)
+
+ if gr_implicit then
+ for _,gr_elt in ipairs(gr) do
+ table.insert(keys, {gr_name, gr_elt})
+ end
+ else
+ table.insert(keys, {gr_name, gr})
+ end
end
end
end
@@ -65,7 +82,16 @@ local function metric_pairs(t)
else
for k,v in pairs(tbl) do
if type(k) ~= 'number' then
- table.insert(keys, {k, v})
+ -- We can also have implicit arrays here
+ local is_implicit = is_implicit(v)
+
+ if is_implicit then
+ for _,elt in ipairs(v) do
+ table.insert(keys, {k, elt})
+ end
+ else
+ table.insert(keys, {k, v})
+ end
end
end
end
@@ -109,8 +135,7 @@ local function group_transform(cfg, k, v)
if not cfg.group then cfg.group = {} end
if cfg.group[k] then
- local merged = override_defaults(new_group, cfg.group[k])
- cfg.group[k] = merged
+ cfg.group[k] = override_defaults(cfg.group[k], new_group)
else
cfg.group[k] = new_group
end
@@ -160,7 +185,7 @@ end
local function convert_metric(cfg, metric)
if metric.actions then
- cfg.actions = override_defaults(metric.actions)
+ cfg.actions = override_defaults(cfg.actions, metric.actions)
logger.warnx("overriding actions from the legacy metric settings")
end
if metric.unknown_weight then