From: Michael Tremer Date: Fri, 5 Dec 2025 14:42:49 +0000 (+0000) Subject: dnsbl: Connect to the PostgreSQL database X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=faa03c59f583469c5169a166a5ab725d6acef444;p=dbl.git dnsbl: Connect to the PostgreSQL database Signed-off-by: Michael Tremer --- diff --git a/configure.ac b/configure.ac index 4593a60..faaaf23 100644 --- a/configure.ac +++ b/configure.ac @@ -52,6 +52,8 @@ AC_PROG_MKDIR_P # Python AM_PATH_PYTHON([3.13]) +AX_PYTHON_MODULE([sqlmodel], [fatal]) + # ------------------------------------------------------------------------------ AC_CONFIG_FILES([ diff --git a/src/dnsbl/__init__.py b/src/dnsbl/__init__.py index 5330288..783e19f 100644 --- a/src/dnsbl/__init__.py +++ b/src/dnsbl/__init__.py @@ -20,6 +20,7 @@ import configparser import logging +import sqlmodel # Initialize logging as early as possible from . import logger @@ -32,6 +33,9 @@ class Backend(object): # Parse the configuration file self.config = self.parse_config(config) + # Connect to the database + self.db = self.connect() + log.debug("DNS Blocklist Backend Initialized") def parse_config(self, config=None): @@ -47,6 +51,15 @@ class Backend(object): return c + def connect(self): + """ + Connect to the database + """ + uri = self.config.get("database", "uri") + + # Create the database engine + return sqlmodel.create_engine(uri) + def update_sources(self): """ Updates all sources