]> git.ipfire.org Git - dbl.git/commitdiff
exports: Add a canary domain to all exports
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 16 Feb 2026 19:28:15 +0000 (19:28 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 16 Feb 2026 19:28:15 +0000 (19:28 +0000)
This is so that we can identify when we are reading back our own data.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/dbl/lists.py

index 9c3bf42b74992b1e25600ae31388db2eb021a407..f9104966809e6f3d5fc3a17f9a6aef332b1701ac 100644 (file)
@@ -255,6 +255,21 @@ class List(sqlmodel.SQLModel, database.BackendMixin, table=True):
                # Join it all together
                return ".".join(e for e in s if e)
 
+       @functools.cached_property
+       def canary(self):
+               """
+                       Creates a canary that will be inserted into all exports
+                       and will be checked if we import a source to avoid that we will
+                       import our own data in a circle.
+               """
+               # Make a unique canary
+               canary = "canary.%s" % self.zone(prefix="dbl")
+
+               # Remove the trailing dot
+               canary = canary.removesuffix(".")
+
+               return canary
+
        @functools.cached_property
        def __domains(self):
                """
@@ -340,14 +355,29 @@ class List(sqlmodel.SQLModel, database.BackendMixin, table=True):
                """
                        Returns all domains that are on this list
                """
-               stmt = (
+               domains = self.backend.db.fetch(
                        sqlmodel
                        .select(
                                self.__domains.c.name,
                        )
                )
 
-               return self.backend.db.fetch(stmt)
+               canary_inserted = False
+
+               # Walk through all domains and insert the canary
+               for domain in domains:
+                       # If we have not inserted the canary, yet, we will do
+                       # it whenever it alphabetically fits
+                       if not canary_inserted and domain > self.canary:
+                               yield self.canary
+                               canary_inserted = True
+
+                       # Add the domain, too
+                       yield domain
+
+               # If we have added all domains but not the canary, we will add the canary anyways
+               if not canary_inserted:
+                       yield self.canary
 
        def add_domain(self, name, added_by, report=None, block=True):
                """