From: Michael Tremer Date: Wed, 2 Jul 2025 17:03:05 +0000 (+0000) Subject: api: Add endpoints to fetch a single mirror X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=da5ec8cb3b9eb466369e3cb25e6d1d10f2d68353;p=pbs.git api: Add endpoints to fetch a single mirror Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 523f9fba..05c3a965 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 diff --git a/src/api/__init__.py b/src/api/__init__.py index 594b75aa..a4fffd38 100644 --- a/src/api/__init__.py +++ b/src/api/__init__.py @@ -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 index 00000000..e5bf0f37 --- /dev/null +++ b/src/api/mirrors.py @@ -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 . # +# # +############################################################################### + +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)