aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Lewis <nerf@judo.za.org>2025-03-04 12:52:45 +0200
committerAndrew Lewis <nerf@judo.za.org>2025-03-24 13:54:51 +0200
commit1d18172fe691c666e7279dcac2ff5fb3d999e7d8 (patch)
tree44e5462d75c2a733401dae16ecc150e6d8e1dde5
parent9e086cb96603e909aa1ad0c69e96a6d6a73aa31d (diff)
downloadrspamd-1d18172fe691c666e7279dcac2ff5fb3d999e7d8.tar.gz
rspamd-1d18172fe691c666e7279dcac2ff5fb3d999e7d8.zip
[Minor] Add config schema
-rw-r--r--src/plugins/lua/contextal.lua29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/plugins/lua/contextal.lua b/src/plugins/lua/contextal.lua
index 8f152828f..5cebff238 100644
--- a/src/plugins/lua/contextal.lua
+++ b/src/plugins/lua/contextal.lua
@@ -32,6 +32,7 @@ local redis_cache = require "lua_cache"
local rspamd_http = require "rspamd_http"
local rspamd_logger = require "rspamd_logger"
local rspamd_util = require "rspamd_util"
+local ts = require("tableshape").types
local ucl = require "ucl"
local cache_context, redis_params
@@ -44,6 +45,21 @@ local contextal_actions = {
'SPAM',
}
+local config_schema = lua_redis.enrich_schema {
+ action_symbol_prefix = ts.string:is_optional(),
+ base_url = ts.string:is_optional(),
+ cache_prefix = ts.string:is_optional(),
+ cache_timeout = ts.number:is_optional(),
+ cache_ttl = ts.number:is_optional(),
+ custom_actions = ts.array_of(ts.string):is_optional(),
+ defer_if_no_result = ts.boolean:is_optional(),
+ defer_message = ts.string:is_optional(),
+ enabled = ts.boolean:is_optional(),
+ http_timeout = ts.number:is_optional(),
+ request_ttl = ts.number:is_optional(),
+ submission_symbol = ts.string:is_optional(),
+}
+
local settings = {
action_symbol_prefix = 'CONTEXTAL_ACTION',
base_url = 'http://localhost:8080',
@@ -232,12 +248,21 @@ local function action_cb(task)
end
local function set_url_path(base, path)
- local ts = base:sub(#base) == '/' and '' or '/'
- return base .. ts .. path
+ local slash = base:sub(#base) == '/' and '' or '/'
+ return base .. slash .. path
end
settings = lua_util.override_defaults(settings, opts)
+local res, err = config_schema:transform(settings)
+if not res then
+ 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)
+ return
+end
+
contextal_actions = lua_util.list_to_hash(contextal_actions)
for _, k in ipairs(settings.custom_actions) do
contextal_actions[k] = true