added is_production and overrides
This commit is contained in:
1 parent
1ae0636201
commit
79d3fb72f9
4 files changed
+52
-40
No files matched your search
+20
-28
@@ -1,40 +1,32 @@
|
||||
import json
|
||||
from enum import Enum
|
||||
from functools import cache
|
||||
import pathlib
|
||||
from functools import cache
|
||||
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
|
||||
from monitor_utils.constants import PROXIES_PATH, PROJECT_ROOT
|
||||
from monitor_utils.constants import (
|
||||
PROXIES_PATH,
|
||||
PROJECT_ROOT,
|
||||
DEVELOPMENT_MODE,
|
||||
PRODUCTION_BOT_TOKEN,
|
||||
DEVELOPMENT_BOT_TOKEN,
|
||||
DevelopmentMode,
|
||||
)
|
||||
|
||||
|
||||
class DevelopmentMode(str, Enum):
|
||||
PRODUCTION = "PRODUCTION"
|
||||
DEVELOPMENT = "DEVELOPMENT"
|
||||
def is_production(override_production=False) -> bool:
|
||||
if override_production:
|
||||
return override_production
|
||||
|
||||
return DEVELOPMENT_MODE == DevelopmentMode.PRODUCTION
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
mongo_url: str
|
||||
mongo_database_name: str
|
||||
production_bot_token: str
|
||||
profit_api_key: str
|
||||
development_bot_token: str | None = None
|
||||
logging_level: str = "INFO"
|
||||
development_mode: DevelopmentMode = DevelopmentMode.PRODUCTION
|
||||
|
||||
model_config = SettingsConfigDict(env_file=(".env", ".env.local"), extra="ignore")
|
||||
|
||||
@property
|
||||
def bot_token(self) -> str:
|
||||
if self.development_mode == DevelopmentMode.PRODUCTION:
|
||||
return self.production_bot_token
|
||||
|
||||
return self.development_bot_token
|
||||
IS_PRODUCTION = is_production()
|
||||
|
||||
|
||||
@cache
|
||||
def get_settings() -> Settings:
|
||||
return Settings()
|
||||
def get_bot_token() -> str:
|
||||
if IS_PRODUCTION:
|
||||
return PRODUCTION_BOT_TOKEN
|
||||
|
||||
return DEVELOPMENT_BOT_TOKEN
|
||||
|
||||
|
||||
@cache
|
||||
|
||||
Reference in new issue
Block a user