From: Michael Tremer Date: Mon, 16 Feb 2026 19:28:15 +0000 (+0000) Subject: exports: Add a canary domain to all exports X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=25c103a691a2c0b8f3b46b36b1bc49fba005d226;p=dbl.git exports: Add a canary domain to all exports This is so that we can identify when we are reading back our own data. Signed-off-by: Michael Tremer --- diff --git a/src/dbl/lists.py b/src/dbl/lists.py index 9c3bf42..f910496 100644 --- a/src/dbl/lists.py +++ b/src/dbl/lists.py @@ -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): """