commit 884b114: [Project] Add schema for external maps
Vsevolod Stakhov
vsevolod at rspamd.com
Sat Nov 19 20:28:06 UTC 2022
Author: Vsevolod Stakhov
Date: 2022-11-05 14:57:04 +0000
URL: https://github.com/rspamd/rspamd/commit/884b11488ebc49fdea9fad8de9e5ff71199f3aeb
[Project] Add schema for external maps
---
lualib/lua_maps.lua | 38 +++++++++++++++++++++++---------------
1 file 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
More information about the Commits
mailing list