From e6d90bce98b2af71c7082e2e08c7346266d74bbd Mon Sep 17 00:00:00 2001 From: Armand Didierjean <95971503+armanddidierjean@users.noreply.github.com> Date: Mon, 9 Sep 2024 11:51:39 +0200 Subject: [PATCH] Init Google API authentication when google is configured in dotenv (#570) ### Description ### Checklist - [x] Created tests which fail without the change (if possible) - [x] All tests passing - [x] Extended the documentation, if necessary --- app/app.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/app/app.py b/app/app.py index 7c8a883b8..c81242225 100644 --- a/app/app.py +++ b/app/app.py @@ -301,16 +301,17 @@ def get_application(settings: Settings, drop_db: bool = False) -> FastAPI: @asynccontextmanager async def lifespan(app: FastAPI) -> AsyncGenerator: # Init Google API credentials - async for db in app.dependency_overrides.get( - get_db, - get_db, - )(): - google_api = GoogleAPI() - try: - await google_api.get_credentials(db, settings) - except GoogleAPIInvalidCredentialsError: - # We expect this error to be raised if the credentials were never set before - pass + google_api = GoogleAPI() + if google_api.is_google_api_configured(settings): + async for db in app.dependency_overrides.get( + get_db, + get_db, + )(): + try: + await google_api.get_credentials(db, settings) + except GoogleAPIInvalidCredentialsError: + # We expect this error to be raised if the credentials were never set before + pass ws_manager = app.dependency_overrides.get( get_websocket_connection_manager,