File tree Expand file tree Collapse file tree 3 files changed +22
-0
lines changed
Expand file tree Collapse file tree 3 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -12,10 +12,16 @@ class DramatiqConfig(BaseModel):
1212 REDIS_URL : Optional [str ] = None
1313
1414
15+ class AuthConfig (BaseModel ):
16+ JWT_ALGORITHM : str = "HS256"
17+ JWKS_URL : Optional [str ] = None
18+
19+
1520class AppConfig (BaseSettings ):
1621 model_config = SettingsConfigDict (env_nested_delimiter = "__" )
1722
1823 APP_NAME : str = "bootstrap"
24+ AUTH : AuthConfig = AuthConfig ()
1925 DRAMATIQ : DramatiqConfig = DramatiqConfig ()
2026 DEBUG : bool = False
2127 ENVIRONMENT : TYPE_ENVIRONMENT = "local"
Original file line number Diff line number Diff line change 77from structlog import get_logger
88
99from common import AppConfig , application_init
10+ from http_app import context
1011from http_app .routes import init_routes
1112
1213
1314def create_app (
1415 test_config : Union [AppConfig , None ] = None ,
1516) -> FastAPI :
1617 app_config = test_config or AppConfig ()
18+
19+ """
20+ The config is submitted here at runtime, this means
21+ that we cannot declare a function to be used with
22+ FastAPI dependency injection system because Depends
23+ is evaluated before this function is called.
24+ A context variable will achieve the same purpose.
25+ """
26+ context .app_config .set (app_config )
27+
1728 application_init (app_config )
1829 app = FastAPI (
1930 debug = app_config .DEBUG ,
Original file line number Diff line number Diff line change 1+ from contextvars import ContextVar
2+
3+ from common import AppConfig
4+
5+ app_config : ContextVar [AppConfig ] = ContextVar ("app_config" )
You can’t perform that action at this time.
0 commit comments