|
1 | 1 | """Free functions to inject dependencies in routes handlers""" |
2 | 2 |
|
3 | | -from asyncio import Lock |
4 | 3 | from typing import Annotated, cast |
5 | 4 |
|
6 | 5 | from fastapi import Depends, FastAPI, Request |
|
9 | 8 | from servicelib.rabbitmq._client_rpc import RabbitMQRPCClient |
10 | 9 |
|
11 | 10 | from ...core import rabbitmq |
12 | | -from ...core.settings import ApplicationSettings |
13 | 11 | from ...models.schemas.application_health import ApplicationHealth |
14 | | -from ...models.shared_store import SharedStore |
15 | | -from ...modules.inputs import InputsState |
16 | | -from ...modules.mounted_fs import MountedVolumes |
17 | | -from ...modules.outputs import OutputsManager |
18 | 12 | from ...modules.prometheus_metrics import UserServicesMetrics |
19 | 13 |
|
20 | 14 |
|
21 | 15 | def get_application(request: Request) -> FastAPI: |
22 | 16 | return cast(FastAPI, request.app) |
23 | 17 |
|
24 | 18 |
|
25 | | -def get_app_state(request: Request) -> State: |
| 19 | +def _get_app_state(request: Request) -> State: |
26 | 20 | return cast(State, request.app.state) |
27 | 21 |
|
28 | 22 |
|
29 | 23 | def get_application_health( |
30 | | - app_state: Annotated[State, Depends(get_app_state)], |
| 24 | + app_state: Annotated[State, Depends(_get_app_state)], |
31 | 25 | ) -> ApplicationHealth: |
32 | 26 | return cast(ApplicationHealth, app_state.application_health) |
33 | 27 |
|
34 | 28 |
|
35 | | -def get_settings( |
36 | | - app_state: Annotated[State, Depends(get_app_state)], |
37 | | -) -> ApplicationSettings: |
38 | | - return cast(ApplicationSettings, app_state.settings) |
39 | | - |
40 | | - |
41 | | -def get_shared_store( |
42 | | - app_state: Annotated[State, Depends(get_app_state)], |
43 | | -) -> SharedStore: |
44 | | - return cast(SharedStore, app_state.shared_store) |
45 | | - |
46 | | - |
47 | | -def get_mounted_volumes( |
48 | | - app_state: Annotated[State, Depends(get_app_state)], |
49 | | -) -> MountedVolumes: |
50 | | - return cast(MountedVolumes, app_state.mounted_volumes) |
51 | | - |
52 | | - |
53 | | -def get_container_restart_lock( |
54 | | - app_state: Annotated[State, Depends(get_app_state)], |
55 | | -) -> Lock: |
56 | | - return cast(Lock, app_state.container_restart_lock) |
57 | | - |
58 | | - |
59 | | -def get_outputs_manager( |
60 | | - app_state: Annotated[State, Depends(get_app_state)], |
61 | | -) -> OutputsManager: |
62 | | - return cast(OutputsManager, app_state.outputs_manager) |
63 | | - |
64 | | - |
65 | | -def get_inputs_state( |
66 | | - app_state: Annotated[State, Depends(get_app_state)], |
67 | | -) -> InputsState: |
68 | | - return cast(InputsState, app_state.inputs_state) |
69 | | - |
70 | | - |
71 | 29 | def get_user_services_metrics( |
72 | | - app_state: Annotated[State, Depends(get_app_state)], |
| 30 | + app_state: Annotated[State, Depends(_get_app_state)], |
73 | 31 | ) -> UserServicesMetrics: |
74 | 32 | return cast(UserServicesMetrics, app_state.user_service_metrics) |
75 | 33 |
|
|
0 commit comments