]> git.ipfire.org Git - dnsbl.git/commitdiff
dnsbl: Connect to the PostgreSQL database
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 5 Dec 2025 14:42:49 +0000 (14:42 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 5 Dec 2025 14:42:49 +0000 (14:42 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
configure.ac
src/dnsbl/__init__.py

index 4593a60d6ba279f06452e7a27a05b818dd6d6c7d..faaaf23290963ec5caceb6d5b4aa0b309ade1891 100644 (file)
@@ -52,6 +52,8 @@ AC_PROG_MKDIR_P
 # Python
 AM_PATH_PYTHON([3.13])
 
+AX_PYTHON_MODULE([sqlmodel], [fatal])
+
 # ------------------------------------------------------------------------------
 
 AC_CONFIG_FILES([
index 5330288aeb6ea575e454ad0c96aee65b43afd49f..783e19fadd5e7737821cd26c5a4f0b839c23c2a4 100644 (file)
@@ -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