Files
backend/app/config.py
Misaka_Company 2d7c8a6f3f Rename MinIO config to S3, switch to Cloudflare R2
- Rename MinioConfig → S3Config, settings.minio → settings.s3
- Update config.example.yaml with R2 endpoint template
- S3 service is now storage-backend agnostic (MinIO, R2, any S3-compatible)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-28 13:43:10 +08:00

50 lines
1008 B
Python

from pathlib import Path
import yaml
from pydantic import BaseModel
class S3Config(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):
s3: S3Config
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()