]> git.ipfire.org Git - dbl.git/commitdiff
api: Add a simple endpoint to fetch all lists
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 29 Dec 2025 13:47:10 +0000 (13:47 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 29 Dec 2025 13:47:10 +0000 (13:47 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/dnsbl/api/__init__.py
src/dnsbl/api/lists.py [new file with mode: 0644]

index f14ddba31b30e6f8bb18e7a745d6fb15961b8bf4..9d2c33ba08a661ed469e88fed851be62c44f027f 100644 (file)
@@ -61,7 +61,8 @@ dist_pkgpython_PYTHON = \
        src/dnsbl/util.py
 
 dist_pkgpython_api_PYTHON = \
-       src/dnsbl/api/__init__.py
+       src/dnsbl/api/__init__.py \
+       src/dnsbl/api/lists.py
 
 pkgpython_apidir = $(pkgpythondir)/api
 
index d0ad10e009b37f075515f5a3832c584c62633376..901a4d3ed51ac6bb58fe2a63de955e3fbee5c166 100644 (file)
@@ -32,7 +32,10 @@ app = fastapi.FastAPI(
 )
 
 # Initialize the backend
-app.state.backend = Backend(
+backend = app.state.backend = Backend(
        config = "/etc/dnsbl.conf",
        debug  = True,
 )
+
+# Import any endpoints
+from . import lists
diff --git a/src/dnsbl/api/lists.py b/src/dnsbl/api/lists.py
new file mode 100644 (file)
index 0000000..cb39904
--- /dev/null
@@ -0,0 +1,41 @@
+###############################################################################
+#                                                                             #
+# dnsbl - A DNS Blocklist Compositor For IPFire                               #
+# Copyright (C) 2025 IPFire Development Team                                  #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+###############################################################################
+
+import fastapi
+import typing
+
+from .. import lists
+
+# Import the main app
+from . import app
+from . import backend
+
+# Create a router
+router = fastapi.APIRouter(
+       prefix="/lists",
+       tags=["Lists"],
+)
+
+@router.get("")
+def get_lists() -> typing.List[lists.List]:
+       return [l for l in backend.lists]
+
+# Include our endpoints
+app.include_router(router)