scripts: check_site_lib: introduce need_string_array_match() (#1016)

This commit is contained in:
kb-light 2017-02-21 09:45:33 +01:00 committed by Matthias Schiffer
parent 1fdaee080a
commit c9563cdebd
3 changed files with 8 additions and 2 deletions

View File

@ -8,7 +8,7 @@ local function check_branch(k, _)
need_string(prefix .. 'name') need_string(prefix .. 'name')
need_string_array(prefix .. 'mirrors') need_string_array(prefix .. 'mirrors')
need_number(prefix .. 'good_signatures') need_number(prefix .. 'good_signatures')
need_string_array(prefix .. 'pubkeys') need_string_array_match(prefix .. 'pubkeys', '^%x+$')
end end
need_table('autoupdater.branches', check_branch) need_table('autoupdater.branches', check_branch)

View File

@ -41,7 +41,7 @@ end
need_boolean('poe_passthrough', false) need_boolean('poe_passthrough', false)
if need_table('dns', nil, false) then if need_table('dns', nil, false) then
need_number('dns.cacheentries', false) need_number('dns.cacheentries', false)
need_string_array('dns.servers', false) need_string_array_match('dns.servers', '^[%x:]+$', false)
end end
if need_table('next_node', nil, false) then if need_table('next_node', nil, false) then

View File

@ -138,6 +138,12 @@ function need_string_array(varname, required)
return var return var
end end
function need_string_array_match(varname, pat, required)
local ok, var = pcall(need_array, varname, function(e) assert(e:match(pat)) end, required)
assert(ok, "site.conf error: expected `" .. varname .. "' to be a string array matching pattern `" .. pat .. "'")
return var
end
function need_array_of(varname, array, required) function need_array_of(varname, array, required)
local ok, var = pcall(need_array, varname, function(e) assert_one_of(e, array) end,required) local ok, var = pcall(need_array, varname, function(e) assert_one_of(e, array) end,required)
assert(ok, "site.conf error: expected `" .. varname .. "' to be a subset of given array: " .. array_to_string(array)) assert(ok, "site.conf error: expected `" .. varname .. "' to be a subset of given array: " .. array_to_string(array))