38 lines
876 B
Python
38 lines
876 B
Python
|
import os
|
||
|
|
||
|
import yaml # type: ignore
|
||
|
from pydantic_settings import BaseSettings
|
||
|
|
||
|
with open(os.getenv("CONFIG_PATH", "")) as f:
|
||
|
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
|