- config: PULP_* env + 사내 CA(verify=) 대응 - pulp_client: Basic Auth get/post/patch, status/list_repos/get_version - BFF 라우트: GET / (대시보드), GET /repos (조각), GET /healthz - views: Pulp JSON → 표시 모델 (GPG 검증 배지 3단계, 요약 집계) - HTMX + Jinja 템플릿, vendored pico.css/htmx.js (CDN 의존 0) - 브라우저는 Pulp 직접 호출 안 함 — 모두 BFF 경유 (스펙 §2) - 테스트: pulp_client(respx), 라우트(dependency_overrides), views 순수함수 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
46 lines
1.4 KiB
Python
46 lines
1.4 KiB
Python
"""FastAPI 진입점: 정적 자산 마운트, 라우터 등록, 헬스체크.
|
|
|
|
화면용 라우트는 JSON 이 아니라 HTML(전체 페이지 또는 조각)을 반환한다(스펙 §7).
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
import httpx
|
|
from fastapi import Depends, FastAPI, Request
|
|
from fastapi.responses import HTMLResponse
|
|
from fastapi.staticfiles import StaticFiles
|
|
|
|
# 테스트 호환을 위해 re-export (tests 가 app.main.get_pulp_client 를 override 함)
|
|
from .deps import get_pulp_client, templates
|
|
from .pulp_client import PulpClient
|
|
from .routes import dashboard
|
|
|
|
BASE_DIR = Path(__file__).resolve().parent
|
|
|
|
app = FastAPI(title="Pulp 패치 관리 콘솔")
|
|
app.mount("/static", StaticFiles(directory=str(BASE_DIR / "static")), name="static")
|
|
app.include_router(dashboard.router)
|
|
|
|
__all__ = ["app", "get_pulp_client"]
|
|
|
|
|
|
@app.get("/healthz", response_class=HTMLResponse)
|
|
def healthz(
|
|
request: Request, pulp: PulpClient = Depends(get_pulp_client)
|
|
) -> HTMLResponse:
|
|
"""Pulp status 프록시 → 연결 상태 배지 조각."""
|
|
try:
|
|
pulp.status()
|
|
online, detail = True, "Pulp 연결됨"
|
|
except httpx.HTTPError as exc:
|
|
online, detail = False, f"Pulp 연결 실패: {exc}"
|
|
|
|
return templates.TemplateResponse(
|
|
request,
|
|
"partials/health.html",
|
|
{"online": online, "detail": detail},
|
|
status_code=200 if online else 503,
|
|
)
|