# HG changeset patch # User Kim Alvefur # Date 1740180395 -3600 # Node ID 3d58ea9c53563d8191b0bf447ad0c4615c52551c # Parent 47e537e340c43d0e8affb474c5438ecb3a813cfd# Parent 994ea8d54b727b60657bd777235094efbb089154 Merge 13.0->trunk diff -r 47e537e340c4 -r 3d58ea9c5356 core/configmanager.lua --- a/core/configmanager.lua Mon Feb 17 23:06:26 2025 +0000 +++ b/core/configmanager.lua Sat Feb 22 00:26:35 2025 +0100 @@ -34,8 +34,9 @@ local config_mt = { __index = function (t, _) return rawget(t, "*"); end}; local config = setmetatable({ ["*"] = { } }, config_mt); -local delayed_warnings = {}; local files = {}; +local credentials_directory = nil; +local credential_fallback_fatal = true; -- When host not found, use global local host_mt = { __index = function(_, k) return config["*"][k] end } @@ -45,11 +46,12 @@ end function _M.get(host, key) - if host and key and delayed_warnings[host.."/"..key] then - local warning = delayed_warnings[host.."/"..key]; - log("warn", "%s", warning.text); + local v = config[host][key]; + if v and errors.is_error(v) then + log("warn", "%s:%d: %s", v.context.filename, v.context.fileline, v.text); + return nil; end - return config[host][key]; + return v; end function _M.rawget(host, key) local hostconfig = rawget(config, host); @@ -250,10 +252,6 @@ t_insert(warnings, ("%s:%d: Duplicate option '%s'"):format(config_file, get_line_number(config_file), k)); end set_options[option_path] = true; - if errors.is_error(v) then - delayed_warnings[option_path] = v; - return; - end set(config_table, env.__currenthost or "*", k, v); end }); @@ -371,19 +369,17 @@ env.FileLine = filereader(config_path, "*l"); env.FileLines = linereader(config_path); - if _G.prosody.paths.credentials then - env.Credential = filereader(_G.prosody.paths.credentials, "*a"); - elseif _G.prosody.process_type == "prosody" then + if credentials_directory then + env.Credential = filereader(credentials_directory, "*a"); + elseif credential_fallback_fatal then env.Credential = function() error("Credential() requires the $CREDENTIALS_DIRECTORY environment variable to be set", 2) end else env.Credential = function() return errors.new({ - type = "continue", - text = ("%s:%d: Credential() requires the $CREDENTIALS_DIRECTORY environment variable to be set") - :format(config_file, get_line_number(config_file)); - }); + type = "continue"; + text = "Credential() requires the $CREDENTIALS_DIRECTORY environment variable to be set"; + }, { filename = config_file; fileline = get_line_number(config_file) }); end - end local chunk, err = envload(data, "@"..config_file, env); @@ -405,4 +401,12 @@ end +function _M.set_credentials_directory(directory) + credentials_directory = directory; +end + +function _M.set_credential_fallback_mode(mode) + credential_fallback_fatal = mode == "error"; +end + return _M; diff -r 47e537e340c4 -r 3d58ea9c5356 util/startup.lua --- a/util/startup.lua Mon Feb 17 23:06:26 2025 +0000 +++ b/util/startup.lua Sat Feb 22 00:26:35 2025 +0100 @@ -89,6 +89,14 @@ end end prosody.config_file = filename + local credentials_directory = os.getenv("CREDENTIALS_DIRECTORY"); + if credentials_directory then + config.set_credentials_directory(credentials_directory); + elseif prosody.process_type == "prosody" then + config.set_credential_fallback_mode("error"); + else + config.set_credential_fallback_mode("warn"); + end local ok, level, err = config.load(filename); if not ok then print("\n"); @@ -271,7 +279,6 @@ config = CFG_CONFIGDIR or "."; plugins = CFG_PLUGINDIR or "plugins"; data = "data"; - credentials = os.getenv("CREDENTIALS_DIRECTORY"); }; prosody.arg = _G.arg;