comparison core/configmanager.lua @ 13672:db145fd892ed

Merge 13.0->trunk
author Kim Alvefur <zash@zash.se>
date Wed, 12 Feb 2025 22:41:19 +0100
parents 0c8c1a8338d1
children 0c7e11c11968
comparison
equal deleted inserted replaced
13670:cb44753db100 13672:db145fd892ed
16 local it = require"prosody.util.iterators"; 16 local it = require"prosody.util.iterators";
17 local resolve_relative_path = require"prosody.util.paths".resolve_relative_path; 17 local resolve_relative_path = require"prosody.util.paths".resolve_relative_path;
18 local glob_to_pattern = require"prosody.util.paths".glob_to_pattern; 18 local glob_to_pattern = require"prosody.util.paths".glob_to_pattern;
19 local path_sep = package.config:sub(1,1); 19 local path_sep = package.config:sub(1,1);
20 local get_traceback_table = require "prosody.util.debug".get_traceback_table; 20 local get_traceback_table = require "prosody.util.debug".get_traceback_table;
21 local errors = require "prosody.util.error";
22 local log = require "prosody.util.logger".init("config");
21 23
22 local encodings = deps.softreq"prosody.util.encodings"; 24 local encodings = deps.softreq"prosody.util.encodings";
23 local nameprep = encodings and encodings.stringprep.nameprep or function (host) return host:lower(); end 25 local nameprep = encodings and encodings.stringprep.nameprep or function (host) return host:lower(); end
24 26
25 local _M = {}; 27 local _M = {};
30 32
31 local parser = nil; 33 local parser = nil;
32 34
33 local config_mt = { __index = function (t, _) return rawget(t, "*"); end}; 35 local config_mt = { __index = function (t, _) return rawget(t, "*"); end};
34 local config = setmetatable({ ["*"] = { } }, config_mt); 36 local config = setmetatable({ ["*"] = { } }, config_mt);
37 local delayed_warnings = {};
35 local files = {}; 38 local files = {};
36 39
37 -- When host not found, use global 40 -- When host not found, use global
38 local host_mt = { __index = function(_, k) return config["*"][k] end } 41 local host_mt = { __index = function(_, k) return config["*"][k] end }
39 42
40 function _M.getconfig() 43 function _M.getconfig()
41 return config; 44 return config;
42 end 45 end
43 46
44 function _M.get(host, key) 47 function _M.get(host, key)
48 if host and key and delayed_warnings[host.."/"..key] then
49 local warning = delayed_warnings[host.."/"..key];
50 log("warn", "%s", warning.text);
51 end
45 return config[host][key]; 52 return config[host][key];
46 end 53 end
47 function _M.rawget(host, key) 54 function _M.rawget(host, key)
48 local hostconfig = rawget(config, host); 55 local hostconfig = rawget(config, host);
49 if hostconfig then 56 if hostconfig then
241 local option_path = host.."/"..k; 248 local option_path = host.."/"..k;
242 if set_options[option_path] then 249 if set_options[option_path] then
243 t_insert(warnings, ("%s:%d: Duplicate option '%s'"):format(config_file, get_line_number(config_file), k)); 250 t_insert(warnings, ("%s:%d: Duplicate option '%s'"):format(config_file, get_line_number(config_file), k));
244 end 251 end
245 set_options[option_path] = true; 252 set_options[option_path] = true;
253 if errors.is_error(v) then
254 delayed_warnings[option_path] = v;
255 return;
256 end
246 set(config_table, env.__currenthost or "*", k, v); 257 set(config_table, env.__currenthost or "*", k, v);
247 end 258 end
248 }); 259 });
249 260
250 rawset(env, "__currenthost", "*") -- Default is global 261 rawset(env, "__currenthost", "*") -- Default is global
364 env.Credential = filereader(_G.prosody.paths.credentials, "*a"); 375 env.Credential = filereader(_G.prosody.paths.credentials, "*a");
365 elseif _G.prosody.process_type == "prosody" then 376 elseif _G.prosody.process_type == "prosody" then
366 env.Credential = function() error("Credential() requires the $CREDENTIALS_DIRECTORY environment variable to be set", 2) end 377 env.Credential = function() error("Credential() requires the $CREDENTIALS_DIRECTORY environment variable to be set", 2) end
367 else 378 else
368 env.Credential = function() 379 env.Credential = function()
369 t_insert(warnings, ("%s:%d: Credential() requires the $CREDENTIALS_DIRECTORY environment variable to be set") 380 return errors.new({
370 :format(config_file, get_line_number(config_file))); 381 type = "continue",
371 return nil; 382 text = ("%s:%d: Credential() requires the $CREDENTIALS_DIRECTORY environment variable to be set")
383 :format(config_file, get_line_number(config_file));
384 });
372 end 385 end
373 386
374 end 387 end
375 388
376 local chunk, err = envload(data, "@"..config_file, env); 389 local chunk, err = envload(data, "@"..config_file, env);