|
4 | 4 |
|
5 | 5 | from fastapi.routing import APIRoute, APIWebSocketRoute |
6 | 6 | from fastapi.templating import Jinja2Templates |
7 | | -from pydantic import BaseModel, Field, ValidationInfo, field_validator |
| 7 | +from pydantic import BaseModel, Field |
8 | 8 |
|
9 | 9 | from uiauth.enums import APIMethods |
10 | 10 |
|
@@ -32,30 +32,17 @@ def get_env(keys: List[str], default: Optional[str] = None) -> Optional[str]: |
32 | 32 |
|
33 | 33 |
|
34 | 34 | class EnvConfig(BaseModel): |
35 | | - """Configuration for environment variables.""" |
| 35 | + """Configuration for environment variables. |
36 | 36 |
|
37 | | - username: str |
38 | | - password: str |
| 37 | + >>> EnvConfig |
39 | 38 |
|
40 | | - # noinspection PyMethodParameters |
41 | | - @field_validator("username", "password", mode="before") |
42 | | - def load_user(cls, key: str, field: ValidationInfo) -> str | None: |
43 | | - """Load environment variables into the configuration. |
44 | | -
|
45 | | - Args: |
46 | | - key: Environment variable key to check. |
47 | | - field: Field information for validation. |
48 | | -
|
49 | | - See Also: |
50 | | - - This method checks if the environment variable is set and returns its value. |
51 | | - - If the key is not set, it attempts to get the value from the environment using a helper function. |
| 39 | + See Also: |
| 40 | + - Tries to resolve username and password through kwargs. |
| 41 | + - Uses environment variables as fallback. |
| 42 | + """ |
52 | 43 |
|
53 | | - Returns: |
54 | | - str | None: |
55 | | - Value of the environment variable or None if not set. |
56 | | - """ |
57 | | - if not key: |
58 | | - return get_env([field.field_name, field.field_name[:4]]) |
| 44 | + username: str = Field(default_factory=lambda: get_env(("username", "user"))) |
| 45 | + password: str = Field(default_factory=lambda: get_env(("password", "pass"))) |
59 | 46 |
|
60 | 47 |
|
61 | 48 | env = EnvConfig |
|
0 commit comments