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:
Goffi 2025-11-30 12:27:35 +01:00
commit 6a7b7bc36a

View file

@ -17,12 +17,16 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from pydantic import Field
from libervia.backend import G
from libervia.backend.core.i18n import _, D_
from libervia.backend.core.log import getLogger
from libervia.backend.models.types import JIDType
from libervia.backend.tools.config import PluginSettings
log = getLogger(__name__)
from twisted.words.protocols.jabber.xmlstream import IQ
from twisted.words.protocols.jabber.xmlstream import IQ, XMPPHandler
from twisted.words.protocols.jabber import jid
from twisted.internet import defer
from wokkel import data_form
@ -32,10 +36,6 @@ from libervia.backend.tools import xml_tools
from wokkel import disco, iwokkel
try:
from twisted.words.protocols.xmlstream import XMPPHandler
except ImportError:
from wokkel.subprotocols import XMPPHandler
from zope.interface import implementer
@ -44,6 +44,7 @@ NS_SEARCH = "jabber:iq:search"
PLUGIN_INFO = {
C.PI_NAME: "Jabber Search",
C.PI_IMPORT_NAME: "XEP-0055",
C.PI_CONFIG_KEY: "search",
C.PI_TYPE: "XEP",
C.PI_PROTOCOLS: ["XEP-0055"],
C.PI_DEPENDENCIES: [],
@ -65,18 +66,20 @@ FIELD_CURRENT_SERVICE = (
)
class XEP_0055(object):
class PluginSearchSettings(PluginSettings, plugin_info=PLUGIN_INFO):
services: list[JIDType] = Field(
default_factory=list,
description="Default list of services for search operations.",
)
class XEP_0055:
def __init__(self, host):
log.info(_("Jabber search plugin initialization"))
self.host = host
# default search services (config file + hard-coded lists)
self.services = [
jid.JID(entry)
for entry in host.memory.config_get(
CONFIG_SECTION, CONFIG_SERVICE_LIST, DEFAULT_SERVICE_LIST
)
]
search_settings = G.config.get_settings(PluginSearchSettings)
self.services = search_settings.services
host.bridge.add_method(
"search_fields_ui_get",