commit d8a7818: [Feature] Add query_specific endpoint
Vsevolod Stakhov
vsevolod at highsecure.ru
Wed Jul 1 11:28:09 UTC 2020
Author: Vsevolod Stakhov
Date: 2020-07-01 12:26:02 +0100
URL: https://github.com/rspamd/rspamd/commit/d8a7818f0eff3dbfe9cf25eb68df91d74ca4cb4a (HEAD -> master)
[Feature] Add query_specific endpoint
---
rules/controller/maps.lua | 64 +++++++++++++++++++++++++++++++++++++++--------
1 file changed, 54 insertions(+), 10 deletions(-)
diff --git a/rules/controller/maps.lua b/rules/controller/maps.lua
index ec2392d56..be93e0a6d 100644
--- a/rules/controller/maps.lua
+++ b/rules/controller/maps.lua
@@ -44,22 +44,60 @@ local function maybe_fill_maps_cache()
end
end
+local function check_specific_map(value, uri, m, results)
+ local value = m:get_key(value)
+
+ if value then
+ local result = {
+ map = uri,
+ alias = uri:match('/([^/]+)$'),
+ value = value
+ }
+ table.insert(results, result)
+ end
+end
+
local function handle_query_map(_, conn, req_params)
maybe_fill_maps_cache()
if req_params.value and req_params.value ~= '' then
local results = {}
for uri,m in pairs(maps_cache) do
- local value = m:get_key(req_params.value)
+ check_specific_map(req_params.value, uri, m, results)
+ end
+ conn:send_ucl{
+ success = (#results > 0),
+ results = results
+ }
+ else
+ conn:send_error(404, 'missing value')
+ end
+end
+
+local function handle_query_specific_map(_, conn, req_params)
+ maybe_fill_maps_cache()
+ if req_params.value and req_params.value ~= '' then
+ local maps_to_check = maps_cache
+ if req_params.maps then
+ local map_names = lua_util.str_split(req_params.maps, ',')
+ maps_to_check = {}
+ for _,mn in ipairs(map_names) do
+ if maps_cache[mn] then
+ maps_to_check[mn] = maps_cache[mn]
+ else
+ local alias = maps_aliases[mn]
- if value then
- local result = {
- map = uri,
- alias = uri:match('/([^/]+)$'),
- value = value
- }
- table.insert(results, result)
+ if alias then
+ maps_to_check[alias] = maps_cache[alias]
+ else
+ conn:send_error(404, 'no such map: ' .. mn)
+ end
+ end
end
end
+ local results = {}
+ for uri,m in pairs(maps_to_check) do
+ check_specific_map(req_params.value, uri, m, results)
+ end
conn:send_ucl{
success = (#results > 0),
results = results
@@ -71,8 +109,10 @@ end
local function handle_list_maps(_, conn, _)
maybe_fill_maps_cache()
- conn:send_ucl({maps = lua_util.keys(maps_cache),
- aliases = maps_aliases})
+ conn:send_ucl{
+ maps = lua_util.keys(maps_cache),
+ aliases = maps_aliases
+ }
end
return {
@@ -80,6 +120,10 @@ return {
handler = handle_query_map,
enable = false,
},
+ query_specific = {
+ handler = handle_query_specific_map,
+ enable = false,
+ },
list = {
handler = handle_list_maps,
enable = false,
More information about the Commits
mailing list