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):
12
12
REDIS_URL : Optional [str ] = None
13
13
14
14
15
+ class AuthConfig (BaseModel ):
16
+ JWT_ALGORITHM : str = "HS256"
17
+ JWKS_URL : Optional [str ] = None
18
+
19
+
15
20
class AppConfig (BaseSettings ):
16
21
model_config = SettingsConfigDict (env_nested_delimiter = "__" )
17
22
18
23
APP_NAME : str = "bootstrap"
24
+ AUTH : AuthConfig = AuthConfig ()
19
25
DRAMATIQ : DramatiqConfig = DramatiqConfig ()
20
26
DEBUG : bool = False
21
27
ENVIRONMENT : TYPE_ENVIRONMENT = "local"
Original file line number Diff line number Diff line change 7
7
from structlog import get_logger
8
8
9
9
from common import AppConfig , application_init
10
+ from http_app import context
10
11
from http_app .routes import init_routes
11
12
12
13
13
14
def create_app (
14
15
test_config : Union [AppConfig , None ] = None ,
15
16
) -> FastAPI :
16
17
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
+
17
28
application_init (app_config )
18
29
app = FastAPI (
19
30
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