diff options
author | Vsevolod Stakhov <vsevolod@rspamd.com> | 2022-11-05 14:57:04 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rspamd.com> | 2022-11-19 12:44:13 +0000 |
commit | 884b11488ebc49fdea9fad8de9e5ff71199f3aeb (patch) | |
tree | e346659baa64c43205fa747649230cf4fca71345 /lualib/lua_maps.lua | |
parent | 78a67ee1754f245995887f5c1909b5e3caa4a313 (diff) | |
download | rspamd-884b11488ebc49fdea9fad8de9e5ff71199f3aeb.tar.gz rspamd-884b11488ebc49fdea9fad8de9e5ff71199f3aeb.zip |
[Project] Add schema for external maps
Diffstat (limited to 'lualib/lua_maps.lua')
-rw-r--r-- | lualib/lua_maps.lua | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/lualib/lua_maps.lua b/lualib/lua_maps.lua index 95828fe13..75d999d8c 100644 --- a/lualib/lua_maps.lua +++ b/lualib/lua_maps.lua @@ -396,24 +396,32 @@ exports.fill_config_maps = function(mname, opts, map_defs) return true end +local external_map_schema = ts.shape{ + external = ts.equivalent(true), -- must be true + backend = ts.string, -- where to get data, required + method = ts.one_of{"body", "header", "query", "form"}, -- how to pass input + encode = ts.one_of{"json", "messagepack"}:is_optional(), -- how to encode input (if relevant) +} +local direct_map_schema = ts.shape{ -- complex object + name = ts.string:is_optional(), + description = ts.string:is_optional(), + timeout = ts.number, + data = ts.array_of(ts.string):is_optional(), + -- Tableshape has no options support for something like key1 or key2? + upstreams = ts.one_of{ + ts.string, + ts.array_of(ts.string), + }:is_optional(), + url = ts.one_of{ + ts.string, + ts.array_of(ts.string), + }:is_optional(), +} + exports.map_schema = ts.one_of{ ts.string, -- 'http://some_map' ts.array_of(ts.string), -- ['foo', 'bar'] - ts.shape{ -- complex object - name = ts.string:is_optional(), - description = ts.string:is_optional(), - timeout = ts.number, - data = ts.array_of(ts.string):is_optional(), - -- Tableshape has no options support for something like key1 or key2? - upstreams = ts.one_of{ - ts.string, - ts.array_of(ts.string), - }:is_optional(), - url = ts.one_of{ - ts.string, - ts.array_of(ts.string), - }:is_optional(), - } + ts.one_of{direct_map_schema, external_map_schema} } return exports |