aboutsummaryrefslogtreecommitdiffstats
path: root/lualib/lua_selectors
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2023-10-31 15:18:22 +0000
committerVsevolod Stakhov <vsevolod@rspamd.com>2023-10-31 15:18:22 +0000
commit3a3c66d232b6e91e3baf8cf6c9c64b48d63e57a8 (patch)
treebaeefb911bbf13e7bf80b51fb7cef55078d381df /lualib/lua_selectors
parentbfa09768e54ffe92d330d4c095c6002fa4a36db4 (diff)
downloadrspamd-3a3c66d232b6e91e3baf8cf6c9c64b48d63e57a8.tar.gz
rspamd-3a3c66d232b6e91e3baf8cf6c9c64b48d63e57a8.zip
[Minor] Add selector transformer `filter_method`
Diffstat (limited to 'lualib/lua_selectors')
-rw-r--r--lualib/lua_selectors/transforms.lua23
1 files changed, 22 insertions, 1 deletions
diff --git a/lualib/lua_selectors/transforms.lua b/lualib/lua_selectors/transforms.lua
index 4b839de28..6c6bc7117 100644
--- a/lualib/lua_selectors/transforms.lua
+++ b/lualib/lua_selectors/transforms.lua
@@ -542,7 +542,28 @@ Empty string comes the first argument or 'true', non-empty string comes nil]],
return res, 'string_list'
end,
['description'] = 'Apply a list of method calls to the userdata object',
- }
+ },
+ -- Apply method to list of userdata and use it as a filter, excluding elements for which method returns false/nil
+ ['filter_method'] = {
+ ['types'] = {
+ ['userdata_list'] = true
+ },
+ ['process'] = function(inp, t, args)
+ local meth = args[1]
+
+ if not meth then
+ logger.errx('invalid method name: %s', args[1])
+ return nil
+ end
+
+ return fun.filter(function(val)
+ return val[meth](val)
+ end, inp), 'userdata_list'
+ end,
+ ['description'] = 'Apply method to list of userdata and use it as a filter,' ..
+ ' excluding elements for which method returns false/nil',
+ ['args_schema'] = { ts.string }
+ },
}
transform_function.match = transform_function.regexp