refactor(lps): 환경설정 TOML 단일화 — .env 제거, 시크릿도 config.local.toml 로 통합
설정이 .env(시크릿)+toml(설정)로 갈려 있던 것을 config.local.toml 하나로 통합. DB 비번이 이미 toml 에 있어 분리 기준이 임의적이었고, backend(하우스 패턴)도 toml 단일이라 일관성 확보. 환경별로 바뀌는 값(DB_HOST 등)만 env override 유지. - config_models: NaverConfig(keys 로테이션)·OpenAIConfig·DecodoConfig 추가 - server_configs: 3개 로드, load_dotenv 제거(python-dotenv 의존성도 제거) - proxy/naver/similarity/keyword/worker_main: os.environ → config 객체 참조 - config.local.toml.example: [NaverConfig]/[OpenAIConfig]/[DecodoConfig] 섹션 - .env/.env.example 삭제, README/주석 갱신 (배포는 toml 마운트 or env override) - tests: DecodoConfig 기반으로 갱신 → 전체 44/44 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
2481c79e3f
commit
7911ba1745
12 files changed
+103
-86
No files matched your search
@@ -2,14 +2,13 @@
|
||||
|
||||
공식 오픈 API(https://openapi.naver.com/v1/search/shop.json)라 크롤링/브라우저 불필요.
|
||||
레퍼런스의 핵심 자산인 **키 로테이션**을 이식: 429/403(쿼터/차단) 시 다음 키로 순환 재시도.
|
||||
키는 .env(NAVER_CLIENT_ID/SECRET, +_2.._10)에서 로드 → server_configs 가 load_dotenv 로 주입.
|
||||
키는 config.local.toml [NaverConfig].keys 에서 로드(여러 개면 로테이션).
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
import httpx
|
||||
|
||||
from common.logger import LOG
|
||||
from config.server_configs import naver_config
|
||||
from services.search.contract import SearchAdapter, NormalizedProduct, AdapterError, AdapterHealth
|
||||
from services.search.rate_limiter import RateLimiter
|
||||
from services.search.naver.transform import transform_items
|
||||
@@ -20,16 +19,8 @@ _MAX_DISPLAY = 100
|
||||
|
||||
|
||||
def load_naver_keys() -> list[tuple[str, str]]:
|
||||
"""(client_id, client_secret) 쌍 목록. 기본(무접미) + _2.._10 로테이션 키."""
|
||||
keys: list[tuple[str, str]] = []
|
||||
cid, csec = os.environ.get("NAVER_CLIENT_ID"), os.environ.get("NAVER_CLIENT_SECRET")
|
||||
if cid and csec:
|
||||
keys.append((cid, csec))
|
||||
for i in range(2, 11):
|
||||
cid, csec = os.environ.get(f"NAVER_CLIENT_ID_{i}"), os.environ.get(f"NAVER_CLIENT_SECRET_{i}")
|
||||
if cid and csec:
|
||||
keys.append((cid, csec))
|
||||
return keys
|
||||
"""(client_id, client_secret) 쌍 목록. TOML [NaverConfig].keys 에서 로드(여러 개면 로테이션)."""
|
||||
return [(k.id, k.secret) for k in naver_config.keys if k.id and k.secret]
|
||||
|
||||
|
||||
class NaverAdapter(SearchAdapter):
|
||||
@@ -52,7 +43,7 @@ class NaverAdapter(SearchAdapter):
|
||||
|
||||
async def search(self, query: str, limit: int = 40) -> list[NormalizedProduct]:
|
||||
if not self._keys:
|
||||
raise AdapterError("네이버 API 키 없음(.env NAVER_CLIENT_ID/SECRET)", source=self.source)
|
||||
raise AdapterError("네이버 API 키 없음(config.local.toml [NaverConfig].keys)", source=self.source)
|
||||
|
||||
collected: list[dict] = []
|
||||
async with httpx.AsyncClient(timeout=self._timeout) as client:
|
||||
|
||||
Reference in new issue
Block a user