]> git.ipfire.org Git - dbl.git/commitdiff
dnsbl: Gracefully terminate if we could not find a list
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 5 Jan 2026 10:13:21 +0000 (10:13 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 5 Jan 2026 10:13:21 +0000 (10:13 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/scripts/dnsbl.in

index 8edcab20f86a1e20dba869c7afb57a7bda2af307..54e7e7e819e181a564a7c4af0a16cecfdd3c8f4e 100644 (file)
@@ -236,6 +236,20 @@ class CLI(object):
                # Otherwise just exit
                sys.exit(0)
 
+       def __get_list(self, backend, slug):
+               """
+                       Fetches a list or terminates the program if we could not find the list.
+               """
+               # Fetch the list
+               list = backend.lists.get_by_slug(slug)
+
+               # Terminate because we could not find the list
+               if not list:
+                       sys.stderr.write("Could not find list '%s'\n" % slug)
+                       raise SystemExit(2)
+
+               return list
+
        def __list(self, backend, args):
                table = rich.table.Table(title=_("Lists"))
                table.add_column(_("Name"))
@@ -272,7 +286,7 @@ class CLI(object):
                """
                        Deletes a list
                """
-               list = backend.lists.get_by_slug(args.list)
+               list = self.__get_list(backend, args.list)
 
                # Delete!
                list.delete(
@@ -283,7 +297,7 @@ class CLI(object):
                """
                        Shows information about a list
                """
-               list = backend.lists.get_by_slug(args.list)
+               list = self.__get_list(backend, args.list)
 
                table = rich.table.Table(title=list.name)
                table.add_column(_("Property"))
@@ -330,7 +344,7 @@ class CLI(object):
                        Updates a single list
                """
                # Fetch the list
-               list = backend.lists.get_by_slug(args.list)
+               list = self.__get_list(backend, args.list)
 
                # Update!
                list.update(force=args.force)
@@ -347,7 +361,7 @@ class CLI(object):
                        Exports a list
                """
                # Fetch the list
-               list = backend.lists.get_by_slug(args.list)
+               list = self.__get_list(backend, args.list)
 
                # Export!
                list.export(args.output, format=args.format)
@@ -423,7 +437,7 @@ class CLI(object):
                        Adds a new source to a list
                """
                # Fetch the list
-               list = backend.lists.get_by_slug(args.list)
+               list = self.__get_list(backend, args.list)
 
                # Create the source
                backend.sources.create(
@@ -439,7 +453,7 @@ class CLI(object):
                        Removes a source from a list
                """
                # Fetch the list
-               list = backend.lists.get_by_slug(args.list)
+               list = self.__get_list(backend, args.list)
 
                # Remove the source
                list.delete_source(
@@ -490,7 +504,7 @@ class CLI(object):
                        Analyzes a list
                """
                # Fetch the list
-               list = backend.lists.get_by_slug(args.list)
+               list = self.__get_list(backend, args.list)
 
                # Show duplicates
                self.__analyze_duplicates(list)
@@ -542,7 +556,7 @@ class CLI(object):
                        Shows the history of a list
                """
                # Fetch the list
-               list = backend.lists.get_by_slug(args.list)
+               list = self.__get_list(backend, args.list)
 
                # Fetch the history
                history = list.get_history(limit=args.limit)