from pathlib import Path import yaml from pydantic import BaseModel class MinioConfig(BaseModel): endpoint: str public_endpoint: str = "" bucket: str = "snapledger" access_key: str secret_key: str class PostgresConfig(BaseModel): host: str port: int = 5432 database: str = "snapledger" user: str password: str @property def dsn(self) -> str: return ( f"postgresql://{self.user}:{self.password}" f"@{self.host}:{self.port}/{self.database}" ) class ApiConfig(BaseModel): token: str class AppConfig(BaseModel): minio: MinioConfig postgresql: PostgresConfig api: ApiConfig def load_config(path: str = "config.yaml") -> AppConfig: config_path = Path(path) if not config_path.exists(): raise FileNotFoundError(f"Configuration file not found: {path}") with open(config_path, encoding="utf-8") as f: data = yaml.safe_load(f) return AppConfig(**data) settings = load_config()