core: Replace legacy INI config system with Pydantic-based TOML configuration.
This is a huge configuration refactoring. The configuration system now uses Pydantic settings, with better validation, better support for environment variables and other goodies. The main config files now use TOML instead of INI, this allow for better handling of complex types, notably dict. Plugins, components and frontends can declare their config settings in a class which will be imported dynamically.
This commit is contained in:
parent
f3f40848b3
commit
6a7b7bc36a
1 changed files with 1392 additions and 1011 deletions
|
|
@ -261,12 +261,21 @@ class Memory:
|
|||
self.subscriptions = {}
|
||||
self.auth_sessions = PasswordSessions() # remember the authenticated profiles
|
||||
self.disco = Discovery(host)
|
||||
self.config = tools_config.parse_main_conf(log_filenames=True)
|
||||
self._cache_path = Path(self.config_get("", "local_dir"), C.CACHE_DIR)
|
||||
self.admins = self.config_get("", "admins_list", [])
|
||||
self.config: tools_config.Settings = tools_config.parse_main_conf(
|
||||
log_filenames=True
|
||||
)
|
||||
self._cache_path = self.config.common.local_dir / C.CACHE_DIR
|
||||
self.admins = self.config.common.admins_list
|
||||
self.admin_jids = set()
|
||||
self._file_path_lock = defer.DeferredLock()
|
||||
|
||||
def reparse_configuration(self) -> None:
|
||||
"""Reparse configuration.
|
||||
|
||||
This is needed when dynamic settings has been added (after importing plugins).
|
||||
"""
|
||||
self.config = tools_config.parse_main_conf(ignore_cache=True)
|
||||
|
||||
async def initialise(self):
|
||||
self.storage = Storage()
|
||||
await self.storage.initialise()
|
||||
|
|
@ -296,18 +305,6 @@ class Memory:
|
|||
|
||||
## Configuration ##
|
||||
|
||||
def config_get(
|
||||
self, section: str | None, name: str, default: Any = None
|
||||
) -> str | list | dict:
|
||||
"""Get the main configuration option
|
||||
|
||||
@param section: section of the config file (None or '' for DEFAULT)
|
||||
@param name: name of the option
|
||||
@param default: value to use if not found
|
||||
@return: str, list or dict
|
||||
"""
|
||||
return tools_config.config_get(self.config, section, name, default)
|
||||
|
||||
def load_xml(self, filename):
|
||||
"""Load parameters template from xml file
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue