]> git.ipfire.org Git - pbs.git/commitdiff
api: Add endpoints to fetch a single mirror
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 2 Jul 2025 17:03:05 +0000 (17:03 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 2 Jul 2025 17:03:05 +0000 (17:03 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/api/__init__.py
src/api/mirrors.py [new file with mode: 0644]

index 523f9fbaed39339927af5644e9f72b74573489f6..05c3a9654eb9c4cc2389312eda4a84cc28ecf221 100644 (file)
@@ -126,6 +126,7 @@ api_PYTHON = \
        src/api/builds.py \
        src/api/distros.py \
        src/api/events.py \
+       src/api/mirrors.py \
        src/api/uploads.py \
        src/api/users.py
 
index 594b75aa6cb3e6567346e8f432b088fc2479792c..a4fffd38ba82836e87125fdfc448fa806e4dd8c1 100644 (file)
@@ -56,6 +56,7 @@ from . import builders
 from . import builds
 from . import distros
 from . import events
+from . import mirrors
 from . import uploads
 from . import users
 
diff --git a/src/api/mirrors.py b/src/api/mirrors.py
new file mode 100644 (file)
index 0000000..e5bf0f3
--- /dev/null
@@ -0,0 +1,48 @@
+###############################################################################
+#                                                                             #
+# Pakfire - The IPFire package management system                              #
+# Copyright (C) 2025 Pakfire 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
+
+from . import apiv1
+from . import backend
+
+from ..mirrors import Mirror
+
+# Create a new router for all endpoints
+router = fastapi.APIRouter(
+       prefix="/mirrors",
+       tags=["Mirrors"],
+)
+
+async def get_mirror_from_path(hostname: str = fastapi.Path(...)) -> Mirror | None:
+       """
+               Fetches the mirror from the hostname in the path
+       """
+       return await backend.mirrors.get_by_hostname(hostname)
+
+@router.get("/{hostname}")
+async def get_mirror(mirror: Mirror = fastapi.Depends(get_mirror_from_path)) -> Mirror:
+       if not mirror:
+               raise fastapi.HTTPException(404, "Could not find mirror")
+
+       return mirror
+
+# Add everything to the APIv1
+apiv1.include_router(router)