]> git.ipfire.org Git - pbs.git/commitdiff
api: Create API endpoints to export users
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 2 Jul 2025 16:50:45 +0000 (16:50 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 2 Jul 2025 16:50:45 +0000 (16:50 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/api/__init__.py
src/api/users.py [new file with mode: 0644]

index 4c802c3a22f557fe6589fc0c189e610e9173482c..523f9fbaed39339927af5644e9f72b74573489f6 100644 (file)
@@ -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
 
index a431b08cd08d8562be3fe4b67472b785aeea8378..594b75aa6cb3e6567346e8f432b088fc2479792c 100644 (file)
@@ -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 (file)
index 0000000..80f6e3e
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+###############################################################################
+
+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)