local E = {}
local N = "lua_redis"
+local db_schema = (ts.number / tostring + ts.string):is_optional():describe("Database number")
local common_schema = {
timeout = (ts.number + ts.string / lutil.parse_time_interval):is_optional():describe("Connection timeout"),
- db = ts.string:is_optional():describe("Database number"),
- database = ts.string:is_optional():describe("Database number"),
- dbname = ts.string:is_optional():describe("Database number"),
+ db = db_schema,
+ database = db_schema,
+ dbname = db_schema,
prefix = ts.string:is_optional():describe("Key prefix"),
username = ts.string:is_optional():describe("Username"),
password = ts.string:is_optional():describe("Password"),
local enrich_schema = function(external)
return ts.one_of {
- ts.shape(external), -- no specific redis parameters
+ ts.shape(lutil.table_merge(common_schema,
+ external)), -- no specific redis servers (e.g when global settings are used)
ts.shape(lutil.table_merge(read_schema, external)), -- read_servers specified
ts.shape(lutil.table_merge(write_schema, external)), -- write_servers specified
ts.shape(lutil.table_merge(rw_schema, external)), -- both read and write servers defined
local res, err = settings_schema:transform(settings)
if not res then
- rspamd_logger.warnx(rspamd_config, 'plugin is misconfigured: %s', err)
+ rspamd_logger.warnx(rspamd_config, 'plugin %s is misconfigured: %s', N, err)
lua_util.disable_module(N, "config")
return
end
end
if redis_params.username then
if redis_params.password then
- password = string.format( '%s:%s@', redis_params.username, redis_params.password)
+ password = string.format('%s:%s@', redis_params.username, redis_params.password)
else
rspamd_logger.warnx(task, "Redis requires a password when username is supplied")
end
local res, err = settings_schema:transform(settings)
if not res then
- rspamd_logger.warnx(rspamd_config, 'plugin is misconfigured: %s', err)
+ rspamd_logger.warnx(rspamd_config, 'plugin %s is misconfigured: %s', N, err)
local err_msg = string.format("schema error: %s", res)
lua_util.config_utils.push_config_error(N, err_msg)
lua_util.disable_module(N, "failed", err_msg)
local res, err = settings_schema:transform(settings)
if not res then
- rspamd_logger.warnx(rspamd_config, '%s: plugin is misconfigured: %s', N, err)
+ rspamd_logger.warnx(rspamd_config, 'plugin %s is misconfigured: %s', N, err)
lua_util.disable_module(N, "config")
return
end