Browse Source

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

kb-light 7 years ago
parent
commit
c9563cdebd

+ 1 - 1
package/gluon-autoupdater/check_site.lua

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

+ 1 - 1
package/gluon-core/check_site.lua

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

+ 6 - 0
scripts/check_site_lib.lua

@@ -138,6 +138,12 @@ function need_string_array(varname, required)
    return var
 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)
    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))