diff options
author | Kim Alvefur <zash@zash.se> | 2025-02-22 00:00:41 +0100 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2025-02-22 00:00:41 +0100 |
commit | 9eedb15c6fc760e45316a02cf372b00bb6547f09 (patch) | |
tree | efd1b6b0e309c513235eb571854eef79cc658bac /core/configmanager.lua | |
parent | 13dc010593fc7968faa3bd713a43893a2dff4f19 (diff) | |
download | prosody-9eedb15c6fc760e45316a02cf372b00bb6547f09.tar.gz prosody-9eedb15c6fc760e45316a02cf372b00bb6547f09.zip |
core.configmanager: Remove dependency on 'prosody' global for Credential
Minimizing dependencies on global state is nice, as it makes using
configmanager outside of Prosody easier.
Diffstat (limited to 'core/configmanager.lua')
-rw-r--r-- | core/configmanager.lua | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/core/configmanager.lua b/core/configmanager.lua index 023545d7..effe33a1 100644 --- a/core/configmanager.lua +++ b/core/configmanager.lua @@ -36,6 +36,8 @@ 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 } @@ -371,9 +373,9 @@ do 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() @@ -405,4 +407,12 @@ do 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; |