Software /
code /
prosody
Comparison
core/configmanager.lua @ 13744:34ac05f6bd10 13.0
core.configmanager: Fix reporting delayed warnings from global section
A Credential in the global section would be stored at
delayed_warnings["*/secret"], but get("example.com","secret") would look
for delayed_warnings["example.com/secret"]
Storing the warnings in the config itself has the unfortunate
side-effect that the config now contains util.error objects, which may
be awkward if something bypasses get(). Should rawget() also do this
filtering? getconfig() too?
Currently this only affects prosodyctl, so maybe it won't be much of a
problem.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 22 Feb 2025 00:08:18 +0100 |
parent | 13743:0c7e11c11968 |
child | 13745:994ea8d54b72 |
comparison
equal
deleted
inserted
replaced
13743:0c7e11c11968 | 13744:34ac05f6bd10 |
---|---|
32 | 32 |
33 local parser = nil; | 33 local parser = nil; |
34 | 34 |
35 local config_mt = { __index = function (t, _) return rawget(t, "*"); end}; | 35 local config_mt = { __index = function (t, _) return rawget(t, "*"); end}; |
36 local config = setmetatable({ ["*"] = { } }, config_mt); | 36 local config = setmetatable({ ["*"] = { } }, config_mt); |
37 local delayed_warnings = {}; | |
38 local files = {}; | 37 local files = {}; |
39 local credentials_directory = nil; | 38 local credentials_directory = nil; |
40 local credential_fallback_fatal = true; | 39 local credential_fallback_fatal = true; |
41 | 40 |
42 -- When host not found, use global | 41 -- When host not found, use global |
45 function _M.getconfig() | 44 function _M.getconfig() |
46 return config; | 45 return config; |
47 end | 46 end |
48 | 47 |
49 function _M.get(host, key) | 48 function _M.get(host, key) |
50 if host and key and delayed_warnings[host.."/"..key] then | 49 local v = config[host][key]; |
51 local warning = delayed_warnings[host.."/"..key]; | 50 if v and errors.is_error(v) then |
52 log("warn", "%s", warning.text); | 51 log("warn", "%s", v.text); |
53 end | 52 return nil; |
54 return config[host][key]; | 53 end |
54 return v; | |
55 end | 55 end |
56 function _M.rawget(host, key) | 56 function _M.rawget(host, key) |
57 local hostconfig = rawget(config, host); | 57 local hostconfig = rawget(config, host); |
58 if hostconfig then | 58 if hostconfig then |
59 return rawget(hostconfig, key); | 59 return rawget(hostconfig, key); |
250 local option_path = host.."/"..k; | 250 local option_path = host.."/"..k; |
251 if set_options[option_path] then | 251 if set_options[option_path] then |
252 t_insert(warnings, ("%s:%d: Duplicate option '%s'"):format(config_file, get_line_number(config_file), k)); | 252 t_insert(warnings, ("%s:%d: Duplicate option '%s'"):format(config_file, get_line_number(config_file), k)); |
253 end | 253 end |
254 set_options[option_path] = true; | 254 set_options[option_path] = true; |
255 if errors.is_error(v) then | |
256 delayed_warnings[option_path] = v; | |
257 return; | |
258 end | |
259 set(config_table, env.__currenthost or "*", k, v); | 255 set(config_table, env.__currenthost or "*", k, v); |
260 end | 256 end |
261 }); | 257 }); |
262 | 258 |
263 rawset(env, "__currenthost", "*") -- Default is global | 259 rawset(env, "__currenthost", "*") -- Default is global |
383 type = "continue", | 379 type = "continue", |
384 text = ("%s:%d: Credential() requires the $CREDENTIALS_DIRECTORY environment variable to be set") | 380 text = ("%s:%d: Credential() requires the $CREDENTIALS_DIRECTORY environment variable to be set") |
385 :format(config_file, get_line_number(config_file)); | 381 :format(config_file, get_line_number(config_file)); |
386 }); | 382 }); |
387 end | 383 end |
388 | |
389 end | 384 end |
390 | 385 |
391 local chunk, err = envload(data, "@"..config_file, env); | 386 local chunk, err = envload(data, "@"..config_file, env); |
392 | 387 |
393 if not chunk then | 388 if not chunk then |