62 lines
1.5 KiB
Python
62 lines
1.5 KiB
Python
"""GuardDog Nexus — FastAPI application entry point."""
|
|
|
|
import os
|
|
from contextlib import asynccontextmanager
|
|
|
|
import uvicorn
|
|
from fastapi import FastAPI
|
|
from fastapi.staticfiles import StaticFiles
|
|
|
|
from guarddog_nexus.api import findings, packages, scans
|
|
from guarddog_nexus.config import config
|
|
from guarddog_nexus.database import init_db
|
|
from guarddog_nexus.logging_setup import log
|
|
from guarddog_nexus.web.routes import router as web_router
|
|
from guarddog_nexus.webhooks import router as webhook_router
|
|
|
|
STATIC_DIR = os.path.join(os.path.dirname(__file__), "static")
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
await init_db()
|
|
log.info("GuardDog Nexus started on %s:%s", config.host, config.port)
|
|
yield
|
|
log.info("GuardDog Nexus shutting down")
|
|
|
|
|
|
app = FastAPI(
|
|
title="GuardDog Nexus",
|
|
version="0.1.0",
|
|
description="Scan PyPI packages from Sonatype Nexus webhooks using GuardDog",
|
|
lifespan=lifespan,
|
|
)
|
|
|
|
app.include_router(webhook_router)
|
|
app.include_router(scans.router)
|
|
app.include_router(packages.router)
|
|
app.include_router(findings.router)
|
|
app.include_router(web_router)
|
|
|
|
if os.path.isdir(STATIC_DIR):
|
|
app.mount("/static", StaticFiles(directory=STATIC_DIR), name="static")
|
|
|
|
|
|
@app.get("/health")
|
|
async def health():
|
|
return {"status": "ok", "version": "0.1.0"}
|
|
|
|
|
|
def main():
|
|
uvicorn.run(
|
|
"guarddog_nexus.main:app",
|
|
host=config.host,
|
|
port=config.port,
|
|
log_level=config.log_level.lower(),
|
|
reload=False,
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|