2024-03-11 07:48:04 +03:00
|
|
|
import os
|
|
|
|
|
|
|
|
import yaml # type: ignore
|
|
|
|
from pydantic_settings import BaseSettings
|
|
|
|
|
2024-03-11 21:07:01 +03:00
|
|
|
with open(os.getenv("CONFIG_PATH", "./config/api_config.yml")) as f:
|
2024-03-11 07:48:04 +03:00
|
|
|
config_data: dict = yaml.safe_load(f)
|
|
|
|
|
|
|
|
if os.getenv("INDOCKER"):
|
|
|
|
config_data["db"]["host"] = "db"
|
|
|
|
config_data["db"]["port"] = 5432
|
|
|
|
|
|
|
|
|
|
|
|
class DBSettings(BaseSettings):
|
|
|
|
pg_user: str = config_data["db"]["user"]
|
|
|
|
pg_pass: str = config_data["db"]["password"]
|
|
|
|
pg_host: str = config_data["db"]["host"]
|
|
|
|
pg_port: int = config_data["db"]["port"]
|
|
|
|
pg_db: str = config_data["db"]["database"]
|
|
|
|
|
|
|
|
@property
|
|
|
|
def get_db_url(self) -> str:
|
|
|
|
return "postgresql+asyncpg://{}:{}@{}:{}/{}".format(
|
|
|
|
self.pg_user,
|
|
|
|
self.pg_pass,
|
|
|
|
self.pg_host,
|
|
|
|
self.pg_port,
|
|
|
|
self.pg_db,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
settings = DBSettings()
|
|
|
|
|
|
|
|
|
|
|
|
def get_settings():
|
|
|
|
print(id(settings))
|
|
|
|
return settings
|