mirror of
https://github.com/vacp2p/pod-api-requester.git
synced 2026-08-27 17:51:09 +00:00
* Added cache to app and get_pod_infos * Add API endpoint: /cache/clear * Make namespace not optional
28 lines
608 B
Python
28 lines
608 B
Python
from collections import defaultdict
|
|
|
|
from fastapi import FastAPI
|
|
|
|
from routers.registry import build_routers
|
|
from utils import setup_logger
|
|
|
|
logger = setup_logger(__file__)
|
|
|
|
|
|
def create_app(config) -> FastAPI:
|
|
app = FastAPI()
|
|
|
|
app.state.namespace = (
|
|
open("/var/run/secrets/kubernetes.io/serviceaccount/namespace").read().strip() or "default"
|
|
)
|
|
|
|
async def get_config() -> dict:
|
|
logger.debug(f"get_config: {config}")
|
|
return config
|
|
|
|
app.state.cache = defaultdict(dict)
|
|
|
|
for router in build_routers(get_config):
|
|
app.include_router(router)
|
|
|
|
return app
|