fix(HEL-494): enforce datahub as sole website market boundary
Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
@@ -96,15 +96,6 @@ class DatahubClient:
|
||||
{"api_name": api_name, "params": params or {}, "fields": fields},
|
||||
)
|
||||
|
||||
def put_ifind_credentials(self, refresh_token: str, access_token: str = "") -> DatahubResponse:
|
||||
return self.post(
|
||||
"/v1/credentials/ifind",
|
||||
{
|
||||
"ifind_refresh_token": refresh_token,
|
||||
"ifind_access_token": access_token,
|
||||
},
|
||||
)
|
||||
|
||||
def sector_quote(self, code: str, date: str = "") -> DatahubResponse:
|
||||
payload: dict[str, Any] = {"code": code}
|
||||
if date:
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import time
|
||||
from typing import Any
|
||||
|
||||
@@ -8,9 +7,6 @@ from backend.data.datahub.bridge import DatahubBridge
|
||||
from backend.data.datahub.errors import DatahubError
|
||||
from backend.data.providers.ifind_client import IfindError
|
||||
|
||||
LOGGER = logging.getLogger("xiaobai.datahub")
|
||||
|
||||
|
||||
class HubIfindProxy:
|
||||
"""Website-facing iFinD facade. Talks only to xiaobai-datahub."""
|
||||
|
||||
@@ -18,20 +14,12 @@ class HubIfindProxy:
|
||||
self._datahub = datahub
|
||||
self._status: dict[str, Any] | None = None
|
||||
self._status_at = 0.0
|
||||
self._pending: tuple[str, str] | None = None
|
||||
|
||||
@property
|
||||
def configured(self) -> bool:
|
||||
return bool(self.status().get("configured"))
|
||||
|
||||
def set_credentials(self, refresh_token: str, access_token: str = "") -> None:
|
||||
self._pending = (str(refresh_token or ""), str(access_token or ""))
|
||||
self._status = None
|
||||
self._status_at = 0.0
|
||||
self._flush_credentials()
|
||||
|
||||
def status(self) -> dict[str, Any]:
|
||||
self._flush_credentials()
|
||||
now = time.monotonic()
|
||||
if self._status is not None and now - self._status_at < 30:
|
||||
return dict(self._status)
|
||||
@@ -139,18 +127,7 @@ class HubIfindProxy:
|
||||
"sample_time": str(payload[0].get("time") or "") if payload else "",
|
||||
}
|
||||
|
||||
def _flush_credentials(self) -> None:
|
||||
pending = self._pending
|
||||
if pending is None or not self._datahub.settings.token:
|
||||
return
|
||||
try:
|
||||
self._datahub.client.put_ifind_credentials(pending[0], pending[1])
|
||||
self._pending = None
|
||||
except DatahubError:
|
||||
LOGGER.warning("datahub ifind credential push failed; will retry")
|
||||
|
||||
def _rows(self, api_name: str, params: dict[str, Any]) -> list[dict[str, Any]]:
|
||||
self._flush_credentials()
|
||||
try:
|
||||
response = self._datahub.client.query_api(api_name, params)
|
||||
except DatahubError as exc:
|
||||
|
||||
Reference in New Issue
Block a user