api: use proper connection shutdown for downstream services
This commit is contained in:
parent
0331dd6406
commit
44d484cfc1
3 changed files with 94 additions and 22 deletions
|
|
@ -2,7 +2,6 @@ from typing import Optional, List
|
|||
import logging
|
||||
import secrets
|
||||
import sys
|
||||
import os
|
||||
from datetime import datetime, UTC
|
||||
from fastapi import FastAPI, Request, Response, status
|
||||
from fastapi.responses import RedirectResponse
|
||||
|
|
@ -42,11 +41,13 @@ async def lifespan(app: FastAPI):
|
|||
auth=BasicAuth(app_cfg.ccujack_user, app_cfg.ccujack_password),
|
||||
mqtt_conn=app_cfg.ccujack_mqtt,
|
||||
)
|
||||
await app.extra["ccujack"].find_locks()
|
||||
await app.extra["ccujack"].connect_mqtt()
|
||||
await app.extra["ccujack"].find_locks()
|
||||
|
||||
yield
|
||||
|
||||
await app.extra["ccujack"].close_connections()
|
||||
|
||||
|
||||
app = FastAPI(
|
||||
title="Dooris",
|
||||
|
|
@ -71,9 +72,7 @@ async def get_user_info(
|
|||
) -> models.UserStatus:
|
||||
return models.UserStatus(
|
||||
is_authorized=current_user.may_operate_locks,
|
||||
guaranteed_session_until=datetime.fromtimestamp(
|
||||
current_user.id_token.exp, UTC
|
||||
),
|
||||
guaranteed_session_until=datetime.fromtimestamp(current_user.id_token.exp, UTC),
|
||||
username=current_user.id_token.preferred_username,
|
||||
ccchh_roles=current_user.ccchh_roles,
|
||||
)
|
||||
|
|
@ -122,7 +121,9 @@ async def login_init(
|
|||
response_class=RedirectResponse,
|
||||
status_code=302,
|
||||
)
|
||||
async def login_callback(req: Request, resp: Response, oidc_client: deps.OpenidClient) -> str:
|
||||
async def login_callback(
|
||||
req: Request, resp: Response, oidc_client: deps.OpenidClient
|
||||
) -> str:
|
||||
# check that the user is currently in an authenticating state
|
||||
# these cookies are set by the login_init() view
|
||||
if (
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue