]> git.ipfire.org Git - pbs.git/commitdiff
api: Create an endpoint to create new mirrors
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 3 Jul 2025 08:36:11 +0000 (08:36 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 3 Jul 2025 08:36:11 +0000 (08:36 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/api/mirrors.py

index 978db93d34f3059188a746ec19285e6011c71133..3864fce316c1335a9dc45a70c8f9b13c19ac8669 100644 (file)
@@ -40,6 +40,40 @@ async def get_mirror_from_path(hostname: str = fastapi.Path(...)) -> Mirror | No
        """
        return await backend.mirrors.get_by_hostname(hostname)
 
+class CreateMirrorRequest(pydantic.BaseModel):
+       # Hostname
+       hostname: str
+
+       # Path
+       path: str
+
+       # Owner
+       owner: str
+
+       # Contact
+       contact: str
+
+       # Notes
+       notes: str
+
+@router.post("")
+async def create_mirror(
+       request: CreateMirrorRequest,
+       current_user: User = fastapi.Depends(auth.get_current_admin),
+) -> Mirror:
+       async with backend.db as session:
+               mirror = await backend.mirrors.create(
+                       hostname = request.hostname,
+                       path     = request.path,
+                       owner    = request.owner,
+                       contact  = request.contact,
+                       notes    = request.notes,
+                       user     = current_user,
+               )
+
+       # Return the new mirror
+       return mirror
+
 @router.get("")
 async def get_mirrors() -> list[Mirror]:
        return [mirror async for mirror in backend.mirrors]