From: Vsevolod Stakhov Date: Sun, 22 May 2022 11:54:54 +0000 (+0100) Subject: [Minor] Hisory_redis: Add configuration schema X-Git-Tag: 3.3~227 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=da946d93d0014bb7ae2bd43a9df32c9a76da0725;p=rspamd.git [Minor] Hisory_redis: Add configuration schema --- diff --git a/src/plugins/lua/aws_s3.lua b/src/plugins/lua/aws_s3.lua index 3168f3638..6f9f74c06 100644 --- a/src/plugins/lua/aws_s3.lua +++ b/src/plugins/lua/aws_s3.lua @@ -237,7 +237,7 @@ local res,err = settings_schema:transform(settings) if not res then rspamd_logger.warnx(rspamd_config, 'plugin is misconfigured: %s', err) - + lua_util.disable_module(N, "config") return end diff --git a/src/plugins/lua/history_redis.lua b/src/plugins/lua/history_redis.lua index 9c0220551..9f8196c1c 100644 --- a/src/plugins/lua/history_redis.lua +++ b/src/plugins/lua/history_redis.lua @@ -40,6 +40,17 @@ redis_history { return end +local rspamd_logger = require "rspamd_logger" +local rspamd_util = require "rspamd_util" +local lua_util = require "lua_util" +local lua_redis = require "lua_redis" +local fun = require "fun" +local ucl = require "ucl" +local ts = (require "tableshape").types +local E = {} +local N = "history_redis" +local hostname = rspamd_util.get_hostname() + local redis_params local settings = { @@ -53,15 +64,16 @@ local settings = { subject_privacy_length = 16, -- cut the length of the hash } -local rspamd_logger = require "rspamd_logger" -local rspamd_util = require "rspamd_util" -local lua_util = require "lua_util" -local lua_redis = require "lua_redis" -local fun = require "fun" -local ucl = require("ucl") -local E = {} -local N = "history_redis" -local hostname = rspamd_util.get_hostname() +local settings_schema = ts.shape({ + key_prefix = ts.string, + expire = (ts.number + ts.string / lua_util.parse_time_interval):is_optional(), + nrows = ts.number, + compress = ts.boolean, + subject_privacy = ts.boolean:is_optional(), + subject_privacy_alg = ts.string:is_optional(), + subject_privacy_prefix = ts.string:is_optional(), + subject_privacy_length = ts.number:is_optional(), +}, {extra_fields = lua_redis.config_schema}) local function process_addr(addr) if addr then @@ -258,9 +270,15 @@ end local opts = rspamd_config:get_all_opt('history_redis') if opts then - for k,v in pairs(opts) do - settings[k] = v + settings = lua_util.override_defaults(settings, opts) + local res,err = settings_schema:transform(settings) + + if not res then + rspamd_logger.warnx(rspamd_config, '%s: plugin is misconfigured: %s', N, err) + lua_util.disable_module(N, "config") + return end + settings = res redis_params = lua_redis.parse_redis_server('history_redis') if not redis_params then