f8d3cbdd59
Add the FastAPI app, PostgreSQL migrations, Docker/Helm packaging, API contracts, docs, client examples, and the unit/integration/compatibility test suite for local client and tooling labs without a real vCenter.
48 lines
1.3 KiB
Python
48 lines
1.3 KiB
Python
"""CIS tasks REST."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
from fastapi import APIRouter, Depends
|
|
|
|
from app.db.pool import Database
|
|
from app.dependencies import get_database
|
|
from app.vsphere.domain import tasks as task_store
|
|
from app.vsphere.errors import not_found
|
|
from app.vsphere.security.authz import require_read
|
|
from app.vsphere.security.session import SessionInfo
|
|
|
|
router = APIRouter(tags=["vSphere Tasks"])
|
|
|
|
|
|
@router.get("/api/cis/tasks")
|
|
async def list_tasks(
|
|
database: Database = Depends(get_database),
|
|
_: SessionInfo = Depends(require_read),
|
|
) -> list[dict[str, Any]]:
|
|
tasks = await task_store.list_tasks(database)
|
|
if tasks:
|
|
return tasks
|
|
# Fresh lab DB — ensure callers always see at least one completed task.
|
|
await task_store.create_task(
|
|
database,
|
|
description="Lab inventory seed",
|
|
service="com.vmware.vcenter",
|
|
operation="seed",
|
|
result={"status": "SUCCEEDED"},
|
|
)
|
|
return await task_store.list_tasks(database)
|
|
|
|
|
|
@router.get("/api/cis/tasks/{task}")
|
|
async def get_task(
|
|
task: str,
|
|
database: Database = Depends(get_database),
|
|
_: SessionInfo = Depends(require_read),
|
|
) -> dict[str, Any]:
|
|
payload = await task_store.get_task(database, task)
|
|
if payload is None:
|
|
raise not_found(f"Task {task} not found")
|
|
return payload
|