Preserve local user table for superDream-specific features while syncing user lifecycle, API key CRUD and usage queries through sub2api. Admin token handles reads and user lifecycle; per-user tokens (Fernet-encrypted in DB) handle key writes that admin endpoints do not expose. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
58 lines
1.4 KiB
Python
58 lines
1.4 KiB
Python
from pydantic_settings import BaseSettings
|
|
from functools import lru_cache
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
app_name: str = "SuperDream"
|
|
debug: bool = False
|
|
host: str = "0.0.0.0"
|
|
port: int = 18000
|
|
|
|
# Database
|
|
db_type: str = "mysql"
|
|
db_host: str = "10.11.0.43"
|
|
db_port: int = 3306
|
|
db_user: str = "root"
|
|
db_password: str = "for_develop_only"
|
|
db_name: str = "superdream"
|
|
|
|
# Storage
|
|
data_dir: str = "./data"
|
|
|
|
# JWT
|
|
jwt_secret: str = "superdream-secret-change-me"
|
|
jwt_algorithm: str = "HS256"
|
|
jwt_access_expire_minutes: int = 30
|
|
jwt_refresh_expire_days: int = 7
|
|
|
|
# sub2api upstream
|
|
sub2api_base_url: str = "http://127.0.0.1:8080"
|
|
sub2api_admin_token: str = ""
|
|
sub2api_request_timeout: float = 10.0
|
|
|
|
# Fernet key (urlsafe base64, 44 chars). Generate with:
|
|
# python -c "from cryptography.fernet import Fernet; print(Fernet.generate_key().decode())"
|
|
token_encryption_key: str = ""
|
|
|
|
@property
|
|
def database_url(self) -> str:
|
|
return (
|
|
f"mysql+aiomysql://{self.db_user}:{self.db_password}"
|
|
f"@{self.db_host}:{self.db_port}/{self.db_name}"
|
|
)
|
|
|
|
@property
|
|
def sub2api_api_prefix(self) -> str:
|
|
return self.sub2api_base_url.rstrip("/") + "/api/v1"
|
|
|
|
class Config:
|
|
env_file = ".env"
|
|
env_prefix = "SD_"
|
|
|
|
|
|
@lru_cache
|
|
def get_settings() -> Settings:
|
|
return Settings()
|
|
|
|
|
|
settings = get_settings() |