diff --git a/backend/pilotwings.py b/backend/pilotwings.py index e82926f..c969f69 100644 --- a/backend/pilotwings.py +++ b/backend/pilotwings.py @@ -2,6 +2,7 @@ from os import getenv, path from typing import Annotated, Any from docker import errors, from_env +from docker.models.containers import Container from dotenv import load_dotenv from fastapi import Depends, FastAPI, HTTPException, Request from fastapi.security import HTTPBasic, HTTPBasicCredentials @@ -57,15 +58,31 @@ class AuthStaticFiles(StaticFiles): app = FastAPI(dependencies=[Depends(check_auth)]) +def serialize_container(container: Container) -> dict[str, Any]: + return { + "id": container.short_id, + "name": container.name, + "image": container.image.tags[0] if container.image else None, + "labels": container.labels, + "status": container.status, + "health": container.health, + "ports": container.ports, + "owner": container.labels.get("owner"), + "environment": container.attrs["Config"]["Env"], + } + + @app.get("/api/containers") def get_containers( credentials: Annotated[HTTPBasicCredentials, Depends(security)], -) -> list[str]: +) -> list[dict[str, Any]]: if credentials.username == "admin": - return [container.name for container in client.containers.list()] + return [ + serialize_container(container) for container in client.containers.list() + ] return [ - container.name + serialize_container(container) for container in client.containers.list( filters={"label": f"owner={credentials.username}"} ) @@ -88,7 +105,7 @@ def get_container( ): raise HTTPException(status_code=status.HTTP_403_FORBIDDEN) - return container.attrs + return serialize_container(container) app.mount( @@ -100,5 +117,5 @@ app.mount( ) -def launch(): +def launch() -> None: run(app, host="0.0.0.0") diff --git a/frontend/views/Home.vue b/frontend/views/Home.vue index 241feae..5fb4408 100644 --- a/frontend/views/Home.vue +++ b/frontend/views/Home.vue @@ -2,9 +2,9 @@ {{ error }} @@ -31,7 +31,7 @@ export default { }, async mounted() { try { - const response = await axios.get('/api/containers') + const response = await axios.get('/api/containers') this.containers = response.data } catch (error) { console.error(error)