diff options
| author | 2024-08-18 20:16:38 +0100 | |
|---|---|---|
| committer | 2024-08-18 20:16:38 +0100 | |
| commit | 26954a4862bc33a0eab68d6b8992efdf038687d4 (patch) | |
| tree | 9526e227a27d09f21417d4e8eca61240bae8e1dc /thallium-backend/src/settings.py | |
| parent | Forward correct path to localhost in compose file (diff) | |
Add debug router for debugging endpoints
Diffstat (limited to 'thallium-backend/src/settings.py')
| -rw-r--r-- | thallium-backend/src/settings.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/thallium-backend/src/settings.py b/thallium-backend/src/settings.py index 931fc0d..db292ba 100644 --- a/thallium-backend/src/settings.py +++ b/thallium-backend/src/settings.py @@ -2,6 +2,7 @@ import typing from collections.abc import AsyncGenerator from logging import getLogger +import httpx import pydantic import pydantic_settings from fastapi import Depends @@ -24,7 +25,8 @@ class _Config( git_sha: str = "development" database_url: pydantic.SecretStr - token: pydantic.SecretStr + super_admin_token: pydantic.SecretStr + printful_token: pydantic.SecretStr CONFIG = _Config() @@ -37,6 +39,16 @@ class Connections: DB_SESSION_MAKER = async_sessionmaker(DB_ENGINE) +async def _get_printful_client() -> AsyncGenerator[httpx.AsyncClient, None]: + """Yield an authenticated httpx client for printful, for use with a FastAPI dependency.""" + client = httpx.AsyncClient( + headers={"Authorization": f"Bearer {CONFIG.printful_token.get_secret_value()}"}, + base_url="https://api.printful.com", + ) + async with client as c: + yield c + + async def _get_db_session() -> AsyncGenerator[AsyncSession, None]: """Yield a database session, for use with a FastAPI dependency.""" async with Connections.DB_SESSION_MAKER() as session, session.begin(): @@ -44,3 +56,4 @@ async def _get_db_session() -> AsyncGenerator[AsyncSession, None]: DBSession = typing.Annotated[AsyncSession, Depends(_get_db_session)] +PrintfulClient = typing.Annotated[httpx.AsyncClient, Depends(_get_printful_client)] |