make app configurable via CLI and ENV parameters
This commit is contained in:
parent
9b97500516
commit
a1aa89132d
3 changed files with 57 additions and 7 deletions
|
|
@ -11,7 +11,6 @@ from simple_openid_connect.client import OpenidClient
|
|||
from simple_openid_connect.data import TokenSuccessResponse
|
||||
from cachetools import TTLCache
|
||||
from aiohttp import BasicAuth
|
||||
import asyncio
|
||||
|
||||
from dooris_api import deps, models, exceptions
|
||||
from dooris_api.ccujack import CCUJackClient
|
||||
|
|
@ -22,6 +21,9 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
from dooris_api import app_config
|
||||
app_config = app_config.get()
|
||||
|
||||
root_logger = logging.getLogger("")
|
||||
root_logger.setLevel(logging.INFO)
|
||||
root_logger.addHandler(logging.StreamHandler(sys.stderr))
|
||||
|
|
@ -29,10 +31,11 @@ async def lifespan(app: FastAPI):
|
|||
app_logger.setLevel(logging.DEBUG)
|
||||
|
||||
app.extra["oidc_client"] = OpenidClient.from_issuer_url(
|
||||
url="https://id.hamburg.ccc.de/realms/test/",
|
||||
authentication_redirect_uri="http://localhost:8000/auth/login-callback",
|
||||
client_id="dooris",
|
||||
client_secret="dp9HhnvUhAtKm3pRnxfGA7q8Nwrd1td8",
|
||||
url=app_config.openid_issuer,
|
||||
authentication_redirect_uri=f"{app_config.base_url}/auth/login-callback",
|
||||
client_id=app_config.openid_client_id,
|
||||
client_secret=app_config.openid_client_secret,
|
||||
scope=app_config.openid_scope,
|
||||
)
|
||||
|
||||
app.extra["cache"] = TTLCache(maxsize=64, ttl=30 * 60)
|
||||
|
|
@ -43,7 +46,7 @@ async def lifespan(app: FastAPI):
|
|||
|
||||
|
||||
app = FastAPI(
|
||||
title="Dooris", summary="API for interacting with HomeMatic door locks in CCCHH", docs_url="/api/docs",
|
||||
title="Dooris", summary="Server to interact with CCCHH doors via locks over CCUJACK over HomeMatic over WiFi", docs_url="/api/docs",
|
||||
lifespan=lifespan,
|
||||
)
|
||||
app.add_exception_handler(exceptions.HttpProblemException, exceptions.problem_exception_handler)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue