]> git.ipfire.org Git - pbs.git/commitdiff
api: Add some basic distro endpoints
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 30 Jun 2025 10:38:01 +0000 (10:38 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 30 Jun 2025 10:38:01 +0000 (10:38 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/api/__init__.py
src/api/distros.py [new file with mode: 0644]

index 7a216f5fb55934c05284e995e1de44b18239a5ee..4c802c3a22f557fe6589fc0c189e610e9173482c 100644 (file)
@@ -124,6 +124,7 @@ api_PYTHON = \
        src/api/auth.py \
        src/api/builders.py \
        src/api/builds.py \
+       src/api/distros.py \
        src/api/events.py \
        src/api/uploads.py
 
index c0cb3caa6115d5c447b9283add60077b70cb4f7f..a431b08cd08d8562be3fe4b67472b785aeea8378 100644 (file)
@@ -54,6 +54,7 @@ apiv1 = fastapi.APIRouter(
 from . import auth
 from . import builders
 from . import builds
+from . import distros
 from . import events
 from . import uploads
 
diff --git a/src/api/distros.py b/src/api/distros.py
new file mode 100644 (file)
index 0000000..ead5470
--- /dev/null
@@ -0,0 +1,73 @@
+###############################################################################
+#                                                                             #
+# 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
+import typing
+
+from . import apiv1
+from . import backend
+
+from ..distros import Distro
+from ..repos import Repo
+
+# Create a new router for all endpoints
+router = fastapi.APIRouter(
+       prefix="/distros",
+       tags=["Distributions"],
+)
+
+async def get_from_path(distro: str = fastapi.Path(...)) -> Distro:
+       """
+               Fetches the distribution from the name in the path
+       """
+       return await backend.distros.get_by_slug(distro)
+
+@router.get("")
+async def get_distros() -> typing.List[Distro]:
+       """
+               An endpoint to list all available distros
+       """
+       return [distro async for distro in backend.distros]
+
+@router.get("/{distro}")
+async def get_distro(distro = fastapi.Depends(get_from_path)) -> Distro:
+       """
+               An endpoint to fetch information about a specific distribution
+       """
+       # Send 404 if we could not find the distro
+       if not distro:
+               raise fastapi.HTTPException(404, "Could not find distro")
+
+       return distro
+
+@router.get("/{distro}/repos")
+async def get_repos(distro = fastapi.Depends(get_from_path)) -> typing.List[Repo]:
+       """
+               An endpoint to fetch all repositories that belong to a distro
+       """
+       # Send 404 if we could not find the distro
+       if not distro:
+               raise fastapi.HTTPException(404, "Could not find distro")
+
+       # Return a list with all repos
+       return await distro.get_repos()
+
+# Add everything to the APIv1
+apiv1.include_router(router)