From: Vsevolod Stakhov Date: Tue, 18 Nov 2025 09:33:57 +0000 (+0000) Subject: [Minor] Migrate src/plugins/lua/external_relay.lua to lua_shape X-Git-Tag: 3.14.1~11^2~34 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0aa5f1a9175f3445156b804ea8b8d9bbfe46c236;p=thirdparty%2Frspamd.git [Minor] Migrate src/plugins/lua/external_relay.lua to lua_shape Replace tableshape with lua_shape in external relay plugin. Changes: - ts.shape { ... } → T.table({ ... }) - ts.map_of(ts.string, schema) → T.table({}, {open=true, extra=schema}) - ts.one_of with 5 strategy variants → T.one_of with named variants - Created rule_common mixin for priority/symbol fields - All 5 strategy variants (authenticated, count, local, hostname_map, ip_map) use mixin for common fields - Added comprehensive documentation Schema: config_schema with rules map where each value is one of 5 strategy types, using mixins for field origin tracking. --- diff --git a/src/plugins/lua/external_relay.lua b/src/plugins/lua/external_relay.lua index 3660f921e1..95d3ce2e38 100644 --- a/src/plugins/lua/external_relay.lua +++ b/src/plugins/lua/external_relay.lua @@ -25,7 +25,7 @@ end local lua_maps = require "lua_maps" local lua_util = require "lua_util" local rspamd_logger = require "rspamd_logger" -local ts = require("tableshape").types +local T = require "lua_shape.core" local E = {} local N = "external_relay" @@ -34,42 +34,63 @@ local settings = { rules = {}, } -local config_schema = ts.shape { - enabled = ts.boolean:is_optional(), - rules = ts.map_of( - ts.string, ts.one_of { - ts.shape { - priority = ts.number:is_optional(), - strategy = 'authenticated', - symbol = ts.string:is_optional(), - user_map = lua_maps.map_schema:is_optional(), - }, - ts.shape { - count = ts.number, - priority = ts.number:is_optional(), - strategy = 'count', - symbol = ts.string:is_optional(), - }, - ts.shape { - priority = ts.number:is_optional(), - strategy = 'local', - symbol = ts.string:is_optional(), - }, - ts.shape { - hostname_map = lua_maps.map_schema, - priority = ts.number:is_optional(), - strategy = 'hostname_map', - symbol = ts.string:is_optional(), - }, - ts.shape { - ip_map = lua_maps.map_schema, - priority = ts.number:is_optional(), - strategy = 'ip_map', - symbol = ts.string:is_optional(), - }, - } - ), -} +local rule_common = T.table({ + priority = T.number():optional():doc({ summary = "Symbol priority" }), + symbol = T.string():optional():doc({ summary = "Symbol name" }), +}):doc({ summary = "Common rule fields" }) + +local config_schema = T.table({ + enabled = T.boolean():optional():doc({ summary = "Enable the plugin" }), + rules = T.table({}, { + open = true, + extra = T.one_of({ + { + name = "authenticated", + schema = T.table({ + strategy = T.literal('authenticated'):doc({ summary = "Authenticated strategy" }), + user_map = lua_maps.map_schema:optional():doc({ summary = "User map for filtering" }), + }, { + mixins = { T.mixin(rule_common, { as = "rule_common" }) } + }) + }, + { + name = "count", + schema = T.table({ + strategy = T.literal('count'):doc({ summary = "Count strategy" }), + count = T.number():doc({ summary = "Number of received headers to skip" }), + }, { + mixins = { T.mixin(rule_common, { as = "rule_common" }) } + }) + }, + { + name = "local", + schema = T.table({ + strategy = T.literal('local'):doc({ summary = "Local IP strategy" }), + }, { + mixins = { T.mixin(rule_common, { as = "rule_common" }) } + }) + }, + { + name = "hostname_map", + schema = T.table({ + strategy = T.literal('hostname_map'):doc({ summary = "Hostname map strategy" }), + hostname_map = lua_maps.map_schema:doc({ summary = "Map of external relay hostnames" }), + }, { + mixins = { T.mixin(rule_common, { as = "rule_common" }) } + }) + }, + { + name = "ip_map", + schema = T.table({ + strategy = T.literal('ip_map'):doc({ summary = "IP map strategy" }), + ip_map = lua_maps.map_schema:doc({ summary = "Map of external relay IPs" }), + }, { + mixins = { T.mixin(rule_common, { as = "rule_common" }) } + }) + }, + }) + }):doc({ summary = "External relay rules keyed by name" }), +}):doc({ summary = "External relay plugin configuration" }) local function set_from_rcvd(task, rcvd) local rcvd_ip = rcvd.real_ip