Files
pulp-console/app/deps.py
Hyemin Lee 07094d9352 feat(demo): expose demo_mode to templates + 연결 배지 데모 표시
- deps.py: PULP_DEMO 설정을 Jinja 전역(demo_mode)으로 노출 → 모든
  템플릿에서 참조 가능. 실연동 오인 방지(데모는 화면 확인 전용).
- health.html: 데모 모드일 때 연결 배지를 "데모 모드 · 가짜 데이터"
  칩으로 표시.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-10 10:03:45 +09:00

37 lines
1.2 KiB
Python

"""공용 의존성: 템플릿 엔진, 요청 단위 Pulp 클라이언트.
라우터 모듈들이 main 을 import 하지 않도록 여기로 분리(순환참조 방지).
"""
from __future__ import annotations
from collections.abc import Iterator
from pathlib import Path
from fastapi.templating import Jinja2Templates
from .config import get_settings
from .pulp_client import PulpClient
TEMPLATES_DIR = Path(__file__).resolve().parent / "templates"
templates = Jinja2Templates(directory=str(TEMPLATES_DIR))
# 데모(가짜 데이터) 모드를 모든 템플릿에서 참조 가능하게 전역 노출 → 배너/배지로 명시.
# 설정은 lru_cache 라 프로세스 내 상수. 실연동 오인 방지용(스펙: 데모는 화면 확인 전용).
templates.env.globals["demo_mode"] = get_settings().pulp_demo
def get_pulp_client() -> Iterator[PulpClient]:
"""요청 단위 Pulp 클라이언트. 테스트에서 dependency_overrides 로 교체한다."""
if get_settings().pulp_demo:
# 임시 데모 모드: 가짜 데이터 (단계5 전 제거 가능)
from .demo import DemoPulpClient
yield DemoPulpClient() # type: ignore[misc]
return
pulp = PulpClient()
try:
yield pulp
finally:
pulp.close()