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
|
|
@ -22,6 +22,7 @@ import time
|
|||
from typing import Optional, cast
|
||||
import uuid
|
||||
|
||||
from pydantic import Field
|
||||
import shortuuid
|
||||
from twisted.internet import defer
|
||||
from twisted.python import failure
|
||||
|
|
@ -32,6 +33,7 @@ from wokkel import rsm
|
|||
from wokkel import mam
|
||||
from zope.interface import implementer
|
||||
|
||||
from libervia.backend import G
|
||||
from libervia.backend.core import exceptions
|
||||
from libervia.backend.core.core_types import SatXMPPEntity
|
||||
from libervia.backend.core.constants import Const as C
|
||||
|
|
@ -40,6 +42,7 @@ from libervia.backend.core.log import getLogger
|
|||
from libervia.backend.memory import memory
|
||||
from libervia.backend.plugins import plugin_misc_jid_search
|
||||
from libervia.backend.tools import xml_tools, utils
|
||||
from libervia.backend.tools.config import PluginSettings
|
||||
|
||||
|
||||
log = getLogger(__name__)
|
||||
|
|
@ -71,9 +74,8 @@ HISTORY_LEGACY = "legacy"
|
|||
HISTORY_MAM = "mam"
|
||||
|
||||
|
||||
CONFIG_SECTION = "plugin muc"
|
||||
|
||||
default_conf = {"default_muc": "sat@chat.jabberfr.org"}
|
||||
class PluginsMucSettings(PluginSettings, plugin_info=PLUGIN_INFO):
|
||||
default_muc: str = Field(default="sat@chat.jabberfr.org")
|
||||
|
||||
|
||||
class AlreadyJoined(exceptions.ConflictError):
|
||||
|
|
@ -653,13 +655,9 @@ class XEP_0045:
|
|||
return jid.JID(f"{room_name}@{muc_service}")
|
||||
|
||||
def get_default_muc(self):
|
||||
"""Return the default MUC.
|
||||
|
||||
@return: unicode
|
||||
"""
|
||||
return self.host.memory.config_get(
|
||||
CONFIG_SECTION, "default_muc", default_conf["default_muc"]
|
||||
)
|
||||
"""Return the default MUC."""
|
||||
plugin_settings = G.config.get_settings(PluginsMucSettings)
|
||||
return plugin_settings.default_muc
|
||||
|
||||
def _bridge_join_eb(self, failure_, client):
|
||||
failure_.trap(AlreadyJoined)
|
||||
|
|
|
|||
Loading…
Reference in a new issue