diff --git a/.env.example b/.env.example index 8bf8646..d8f854e 100644 --- a/.env.example +++ b/.env.example @@ -44,6 +44,14 @@ TRUSTED_NAME_HEADER=X-Forwarded-User-Name # dbx-main 에서 인증된 사용자를 OMS DB 에 자동 등록할지 AUTO_PROVISION_USERS=1 + +# ===== 서비스 간 호출 (OMS → CORM 반품 신청) ===== +# CORM 컨테이너 이름 기반 URL. NPM 거치지 않고 docker network 로 직접 호출. +CS_RETURN_REQUEST_URL=http://dbx-corm:8002/api/return/request + +# 서비스 간 인증 토큰. OMS 와 CORM 양쪽 .env 에 동일한 값으로 박을 것. +# openssl rand -hex 32 로 생성. +INTERNAL_SERVICE_TOKEN=__paste-same-value-as-dbx-corm__ # 자동 등록 시 is_admin=True 로 만들 이메일(쉼표 구분) ADMIN_EMAILS=king@dbxcorp.co.kr diff --git a/app/routers/orders.py b/app/routers/orders.py index 3ab659a..184ed37 100644 --- a/app/routers/orders.py +++ b/app/routers/orders.py @@ -31,8 +31,11 @@ from app.search_utils import ( router = APIRouter() CS_RETURN_REQUEST_URL = os.getenv( "CS_RETURN_REQUEST_URL", - "http://127.0.0.1:8001/api/return/request", + "http://dbx-corm:8002/api/return/request", ) +# 서비스 간 호출 인증용 토큰 (양쪽 .env 에 같은 값으로 박는다). +# CORM 의 AuthGuard 가 이 헤더를 보고 세션 검사 우회. +INTERNAL_SERVICE_TOKEN = os.getenv("INTERNAL_SERVICE_TOKEN", "") # Global dict to hold upload progress. In a real world scenario this should be in Redis or DB. upload_progress_state = {} @@ -942,8 +945,11 @@ async def send_return_request( try: timeout = httpx.Timeout(connect=2.0, read=5.0, write=3.0, pool=2.0) + headers = {} + if INTERNAL_SERVICE_TOKEN: + headers["X-Service-Token"] = INTERNAL_SERVICE_TOKEN async with httpx.AsyncClient(timeout=timeout, trust_env=False) as client: - response = await client.post(CS_RETURN_REQUEST_URL, json=payload) + response = await client.post(CS_RETURN_REQUEST_URL, json=payload, headers=headers) response.raise_for_status() except httpx.HTTPStatusError as exc: response_text = exc.response.text[:1000] if exc.response is not None else ""