974e782057
- Add dict[str, Any] / list[Any] type params throughout (fingerprint, models, schemas, scanner, status_checker) - Add return type annotations to all route functions (nodes, edges, canvas, scan, auth, status, main) - Fix no-any-return in security.py: cast pwd/jwt results to bool/str explicitly - Fix canvas.py: use model_validate() for NodeResponse/EdgeResponse, rename db_node/db_edge upsert vars - Fix scheduler.py: rename 'result' → 'check_result' to avoid type collision - Fix get_db() return type: AsyncGenerator[AsyncSession, None] - Add types-PyYAML for yaml import stubs - Fix scanner.py: remove unnecessary type: ignore comment (nmap has stubs) - Fix scan.py: wrap scalars().all() with list() for Sequence→list compatibility
47 lines
1.3 KiB
Python
47 lines
1.3 KiB
Python
from collections.abc import AsyncGenerator
|
|
from contextlib import asynccontextmanager
|
|
from typing import Any
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from app.api.routes import auth, canvas, edges, nodes, scan, status
|
|
from app.core.config import settings
|
|
from app.core.scheduler import start_scheduler, stop_scheduler
|
|
from app.db.database import init_db
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI) -> AsyncGenerator[None, None]:
|
|
await init_db()
|
|
start_scheduler()
|
|
yield
|
|
stop_scheduler()
|
|
|
|
|
|
app = FastAPI(
|
|
title="Homelable API",
|
|
version="0.1.0",
|
|
lifespan=lifespan,
|
|
)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=settings.cors_origins,
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
app.include_router(auth.router, prefix="/api/v1/auth", tags=["auth"])
|
|
app.include_router(nodes.router, prefix="/api/v1/nodes", tags=["nodes"])
|
|
app.include_router(edges.router, prefix="/api/v1/edges", tags=["edges"])
|
|
app.include_router(canvas.router, prefix="/api/v1/canvas", tags=["canvas"])
|
|
app.include_router(scan.router, prefix="/api/v1/scan", tags=["scan"])
|
|
app.include_router(status.router, prefix="/api/v1/status", tags=["status"])
|
|
|
|
|
|
@app.get("/api/v1/health")
|
|
async def health() -> dict[str, Any]:
|
|
return {"status": "ok"}
|