neutralize upstream service branding

This commit is contained in:
2026-06-12 16:31:08 +08:00
parent 126ae4eafa
commit 42de7f9da0
18 changed files with 340 additions and 256 deletions

View File

@ -13,7 +13,7 @@ from starlette.responses import Response
from .config import GatewayConfig
from .db import init_db
from .everos_client import EverOSClient
from .backend_client import BackendClient
from .repository import MemoryRepository
from .service import MemoryGatewayService, UnsupportedContentType, UploadTooLarge
@ -181,21 +181,21 @@ def _body_for_log(body: bytes, content_type: str | None) -> Any:
def create_app(
*,
config: GatewayConfig | None = None,
everos_client: Any | None = None,
backend_client: Any | None = None,
) -> FastAPI:
cfg = config or GatewayConfig.from_env()
init_db(cfg.database_path)
repository = MemoryRepository(cfg.database_path)
client = everos_client or EverOSClient(
cfg.everos_base_url,
timeout=cfg.everos_timeout_seconds,
client = backend_client or BackendClient(
cfg.backend_base_url,
timeout=cfg.backend_timeout_seconds,
)
service = MemoryGatewayService(cfg, repository, client)
app = FastAPI(title="memory-gateway", version="0.1.0")
app.state.config = cfg
app.state.repository = repository
app.state.everos_client = client
app.state.backend_client = client
app.state.gateway_service = service
router = APIRouter()
@ -278,24 +278,24 @@ def create_app(
@router.get("/health")
async def health() -> dict[str, Any]:
try:
everos_health = await client.health_check()
backend_health = await client.health_check()
except Exception as exc:
return {
"status": "degraded",
"api": {"status": "ok"},
"everos": {
"backend": {
"status": "unavailable",
"base_url": cfg.everos_base_url,
"base_url": cfg.backend_base_url,
"error": str(exc),
},
}
return {
"status": "ok",
"api": {"status": "ok"},
"everos": {
"backend": {
"status": "ok",
"base_url": cfg.everos_base_url,
"data": everos_health,
"base_url": cfg.backend_base_url,
"data": backend_health,
},
}