]> git.ipfire.org Git - dbl.git/commitdiff
api: Export any reports over the API
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 30 Dec 2025 11:45:49 +0000 (11:45 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 30 Dec 2025 11:45:49 +0000 (11:45 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/dnsbl/api/__init__.py
src/dnsbl/api/reports.py [new file with mode: 0644]
src/dnsbl/reports.py

index 995d37c6ec4c57fd6d3330b77a8f52d07da076f9..7ab311de96c78dfa85e41e543069923999f27cb1 100644 (file)
@@ -64,7 +64,8 @@ dist_pkgpython_PYTHON = \
 
 dist_pkgpython_api_PYTHON = \
        src/dnsbl/api/__init__.py \
-       src/dnsbl/api/lists.py
+       src/dnsbl/api/lists.py \
+       src/dnsbl/api/reports.py
 
 pkgpython_apidir = $(pkgpythondir)/api
 
index 7d69f6d43696d805d5585e23320f93bf84e82bf5..c2bc47438c12c70aafa6a0a4e6f9726b7743b7f2 100644 (file)
@@ -49,3 +49,4 @@ def require_api_key(api_key: str = fastapi.Depends(api_key_header)):
 
 # Import any endpoints
 from . import lists
+from . import reports
diff --git a/src/dnsbl/api/reports.py b/src/dnsbl/api/reports.py
new file mode 100644 (file)
index 0000000..84f3f04
--- /dev/null
@@ -0,0 +1,54 @@
+###############################################################################
+#                                                                             #
+# 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 reports
+
+# Import the main app
+from . import app
+from . import backend
+
+# Create a router
+router = fastapi.APIRouter(
+       prefix="/reports",
+       tags=["Reports"],
+)
+
+def get_report_from_path(id: str = fastapi.Path(...)) -> reports.Report:
+       """
+               Fetches a report by its ID
+       """
+       return backend.reports.get_by_id(id)
+
+@router.get("")
+def get_reports() -> typing.List[reports.Report]:
+       return [l for l in backend.reports]
+
+@router.get("/{id}")
+def get_report(report = fastapi.Depends(get_report_from_path)) -> reports.Report:
+       if not report:
+               raise fastapi.HTTPException(404, "Could not find report")
+
+       return report
+
+# Include our endpoints
+app.include_router(router)
index 68bce05d12496ff828ff52ba10c267120237b41b..15f091093a14d019936d8e52ddf2051c4896facb 100644 (file)
@@ -43,6 +43,19 @@ class Reports(object):
 
                return self.backend.db.fetch(stmt)
 
+       def get_by_id(self, id):
+               stmt = (
+                       sqlmodel
+                       .select(
+                               Report,
+                       )
+                       .where(
+                               Report.id == id,
+                       )
+               )
+
+               return self.backend.db.fetch_one(stmt)
+
        def create(self, **kwargs):
                """
                        Creates a new report