-
Notifications
You must be signed in to change notification settings - Fork 14
/
config.py
43 lines (26 loc) · 1.09 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from functools import lru_cache
from typing import Optional
from pydantic_settings import BaseSettings, SettingsConfigDict
class BaseConfig(BaseSettings):
ENV_STATE: Optional[str] = None
model_config = SettingsConfigDict(env_file=".env", extra="ignore")
class GlobalConfig(BaseConfig):
DATABASE_URL: Optional[str] = None
DB_FORCE_ROLL_BACK: bool = False
MAILGUN_DOMAIN: Optional[str] = None
MAILGUN_API_KEY: Optional[str] = None
REDIS_URL: Optional[str] = None
class DevConfig(GlobalConfig):
model_config = SettingsConfigDict(env_prefix="DEV_", extra="ignore")
class ProdConfig(GlobalConfig):
model_config = SettingsConfigDict(env_prefix="PROD_", extra="ignore")
class TestConfig(GlobalConfig):
DATABASE_URL: str = "sqlite:///test.db"
DB_FORCE_ROLL_BACK: bool = True
REDIS_URL: str = ""
model_config = SettingsConfigDict(env_prefix="TEST_", extra="ignore")
@lru_cache()
def get_config(env_state: str):
configs = {"dev": DevConfig, "prod": ProdConfig, "test": TestConfig}
return configs[env_state]()
config = get_config(BaseConfig().ENV_STATE)