Coverage for serverctl_deployd/main.py : 100%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""
2Entrypoint for the API.
3"""
5import json
6import logging
7import sys
8from logging.handlers import TimedRotatingFileHandler
10import uvicorn
11from fastapi import Depends, FastAPI
13from serverctl_deployd.config import Settings
14from serverctl_deployd.dependencies import check_authentication, get_settings
15from serverctl_deployd.routers import config, deployments, docker
17rotating_file_handler = TimedRotatingFileHandler("logs/serverctl_deployd.log",
18 when="W0",
19 backupCount=48,
20 utc=True)
22settings: Settings = get_settings()
23logging.basicConfig(
24 level=settings.log_level,
25 format="%(asctime)s %(pathname)s %(lineno)d %(levelname)s: %(message)s",
26 handlers=[logging.StreamHandler(sys.stdout), rotating_file_handler]
27)
29app: FastAPI = FastAPI(dependencies=[Depends(check_authentication)])
32app.include_router(config.router)
33app.include_router(deployments.router)
34app.include_router(docker.router)
37@app.get("/")
38async def root() -> dict[str, str]:
39 """Basic route for testing"""
40 return {"message": "Working!"}
43if __name__ == "__main__":
44 if len(sys.argv) == 2 and sys.argv[1] == "docs":
45 print(json.dumps(app.openapi(), indent=4))
46 else:
47 uvicorn.run(app, host="0.0.0.0", port=8000)