|
1 | 1 | import os |
2 | 2 | from functools import lru_cache |
3 | 3 |
|
4 | | -from pydantic import BaseSettings |
5 | | - |
6 | | -from app.utils import get_logger |
7 | | - |
8 | | -logger = get_logger(__name__) |
| 4 | +from pydantic import BaseSettings, PostgresDsn |
9 | 5 |
|
10 | 6 |
|
11 | 7 | class Settings(BaseSettings): |
12 | | - """ |
13 | | -
|
14 | | - BaseSettings, from Pydantic, validates the data so that when we create an instance of Settings, |
15 | | - environment and testing will have types of str and bool, respectively. |
16 | | -
|
17 | | - Parameters: |
18 | | - pg_user (str): |
19 | | - pg_pass (str): |
20 | | - pg_database: (str): |
21 | | - pg_test_database: (str): |
22 | | - asyncpg_url: AnyUrl: |
23 | | - asyncpg_test_url: AnyUrl: |
24 | | -
|
25 | | - Returns: |
26 | | - instance of Settings |
27 | | -
|
28 | | - """ |
29 | | - |
30 | | - pg_user: str = os.getenv("SQL_USER", "") |
31 | | - pg_pass: str = os.getenv("POSTGRES_PASSWORD", "") |
32 | | - pg_host: str = os.getenv("SQL_HOST", "") |
33 | | - pg_database: str = os.getenv("SQL_DB", "") |
34 | | - asyncpg_url: str = ( |
35 | | - f"postgresql+asyncpg://{pg_user}:{pg_pass}@{pg_host}:5432/{pg_database}" |
| 8 | + asyncpg_url: PostgresDsn = PostgresDsn.build( |
| 9 | + scheme="postgresql+asyncpg", |
| 10 | + user=os.getenv("SQL_USER"), |
| 11 | + password=os.getenv("POSTGRES_PASSWORD"), |
| 12 | + host=os.getenv("SQL_HOST"), |
| 13 | + port="5432", |
| 14 | + path=f"/{os.getenv('SQL_DB') or ''}", |
36 | 15 | ) |
37 | 16 |
|
38 | | - jwt_secret_key: str = os.getenv("SECRET_KEY", "") |
39 | | - jwt_algorithm: str = os.getenv("ALGORITHM", "") |
40 | | - jwt_access_toke_expire_minutes: int = os.getenv("ACCESS_TOKEN_EXPIRE_MINUTES", 1) |
41 | | - |
42 | 17 |
|
43 | 18 | @lru_cache |
44 | 19 | def get_settings(): |
45 | | - logger.info("Loading config settings from the environment...") |
46 | 20 | return Settings() |
0 commit comments