Mercurial > prosody-hg
comparison core/configmanager.lua @ 13743:0c7e11c11968 13.0
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.
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sat, 22 Feb 2025 00:00:41 +0100 |
| parents | 0c8c1a8338d1 |
| children | 34ac05f6bd10 |
comparison
equal
deleted
inserted
replaced
| 13741:e9edf9b50f32 | 13743:0c7e11c11968 |
|---|---|
| 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 = {}; | 37 local delayed_warnings = {}; |
| 38 local files = {}; | 38 local files = {}; |
| 39 local credentials_directory = nil; | |
| 40 local credential_fallback_fatal = true; | |
| 39 | 41 |
| 40 -- When host not found, use global | 42 -- When host not found, use global |
| 41 local host_mt = { __index = function(_, k) return config["*"][k] end } | 43 local host_mt = { __index = function(_, k) return config["*"][k] end } |
| 42 | 44 |
| 43 function _M.getconfig() | 45 function _M.getconfig() |
| 369 | 371 |
| 370 env.FileContents = filereader(config_path, "*a"); | 372 env.FileContents = filereader(config_path, "*a"); |
| 371 env.FileLine = filereader(config_path, "*l"); | 373 env.FileLine = filereader(config_path, "*l"); |
| 372 env.FileLines = linereader(config_path); | 374 env.FileLines = linereader(config_path); |
| 373 | 375 |
| 374 if _G.prosody.paths.credentials then | 376 if credentials_directory then |
| 375 env.Credential = filereader(_G.prosody.paths.credentials, "*a"); | 377 env.Credential = filereader(credentials_directory, "*a"); |
| 376 elseif _G.prosody.process_type == "prosody" then | 378 elseif credential_fallback_fatal then |
| 377 env.Credential = function() error("Credential() requires the $CREDENTIALS_DIRECTORY environment variable to be set", 2) end | 379 env.Credential = function() error("Credential() requires the $CREDENTIALS_DIRECTORY environment variable to be set", 2) end |
| 378 else | 380 else |
| 379 env.Credential = function() | 381 env.Credential = function() |
| 380 return errors.new({ | 382 return errors.new({ |
| 381 type = "continue", | 383 type = "continue", |
| 403 return true, warnings; | 405 return true, warnings; |
| 404 end | 406 end |
| 405 | 407 |
| 406 end | 408 end |
| 407 | 409 |
| 410 function _M.set_credentials_directory(directory) | |
| 411 credentials_directory = directory; | |
| 412 end | |
| 413 | |
| 414 function _M.set_credential_fallback_mode(mode) | |
| 415 credential_fallback_fatal = mode == "error"; | |
| 416 end | |
| 417 | |
| 408 return _M; | 418 return _M; |
