From: Michael Tremer Date: Wed, 2 Jul 2025 16:50:45 +0000 (+0000) Subject: api: Create API endpoints to export users X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=94974435a694f8bf10af2569d61c69954fb3848f;p=pbs.git api: Create API endpoints to export users Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 4c802c3a..523f9fba 100644 --- a/Makefile.am +++ b/Makefile.am @@ -126,7 +126,8 @@ api_PYTHON = \ src/api/builds.py \ src/api/distros.py \ src/api/events.py \ - src/api/uploads.py + src/api/uploads.py \ + src/api/users.py apidir = $(pkgpythondir)/api diff --git a/src/api/__init__.py b/src/api/__init__.py index a431b08c..594b75aa 100644 --- a/src/api/__init__.py +++ b/src/api/__init__.py @@ -57,6 +57,7 @@ from . import builds from . import distros from . import events from . import uploads +from . import users # Add the APIv1 to the app app.include_router(apiv1) diff --git a/src/api/users.py b/src/api/users.py new file mode 100644 index 00000000..80f6e3e7 --- /dev/null +++ b/src/api/users.py @@ -0,0 +1,50 @@ +############################################################################### +# # +# 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 ..users import User + +# Create a new router for all builds endpoints +router = fastapi.APIRouter( + prefix="/users", + tags=["Users"], +) + +async def get_user_from_path(username: str = fastapi.Path(...)) -> User | None: + """ + Fetches the user from the name in the path + """ + return await backend.users.get_by_name(username) + +@router.get("/{username}") +async def get_user(user: User = fastapi.Depends(get_user_from_path)) -> User: + if not user: + raise fastapi.HTTPException(404, "Could not find user") + + print(user) + + return user + +# Add everything to the APIv1 +apiv1.include_router(router)