Skip to content

Commit

Permalink
Init Google API authentication when google is configured in dotenv (#570
Browse files Browse the repository at this point in the history
)

### Description

### Checklist

- [x] Created tests which fail without the change (if possible)
- [x] All tests passing
- [x] Extended the documentation, if necessary
  • Loading branch information
armanddidierjean authored Sep 9, 2024
1 parent 3c846f4 commit e6d90bc
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit e6d90bc

Please sign in to comment.