]> git.ipfire.org Git - pbs.git/commitdiff
api: Add an endpoint to edit a mirror
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 2 Jul 2025 17:36:57 +0000 (17:36 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 2 Jul 2025 17:36:57 +0000 (17:36 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/api/mirrors.py

index 971e5b65b2f7b183b5218e8811fc7bca35e51a7f..978db93d34f3059188a746ec19285e6011c71133 100644 (file)
@@ -19,6 +19,7 @@
 ###############################################################################
 
 import fastapi
+import pydantic
 
 from . import apiv1
 from . import auth
@@ -50,6 +51,31 @@ async def get_mirror(mirror: Mirror = fastapi.Depends(get_mirror_from_path)) ->
 
        return mirror
 
+class EditMirrorRequest(pydantic.BaseModel):
+       # Owner
+       owner: str = ""
+
+       # Contact
+       contact: str = ""
+
+       # Notes
+       notes: str = ""
+
+@router.put("/{hostname}")
+async def edit_mirror(
+       request: EditMirrorRequest,
+       mirror: Mirror = fastapi.Depends(get_mirror_from_path),
+       current_user: User = fastapi.Depends(auth.get_current_admin),
+) -> Mirror:
+       # Update some fields
+       async with backend.db as session:
+               mirror.owner   = request.owner
+               mirror.contact = request.contact
+               mirror.notes   = request.notes
+
+       # Return the changed mirror
+       return mirror
+
 @router.delete("/{hostname}")
 async def delete_mirror(
        mirror: Mirror = fastapi.Depends(get_mirror_from_path),