Skip to content

Commit 037c222

Browse files
Pigbibiclaude
andauthored
fix: 迁移 monitor_dispatcher、Docker 加固、state_persistence 重构 (#156)
Co-authored-by: Claude <noreply@anthropic.com>
1 parent 8554b30 commit 037c222

8 files changed

Lines changed: 84 additions & 355 deletions

File tree

Dockerfile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM python:3.12-slim
1+
FROM python:3.12-slim-bookworm
22

33
ENV PYTHONUNBUFFERED=1 \
44
PIP_NO_CACHE_DIR=1 \
@@ -12,8 +12,15 @@ RUN apt-get update \
1212

1313
COPY requirements.txt ./
1414
RUN python -m pip install --upgrade pip \
15-
&& python -m pip install -r requirements.txt
15+
&& python -m pip install -r requirements.txt \
16+
&& apt-get purge -y git \
17+
&& apt-get autoremove -y --purge \
18+
&& rm -rf /var/lib/apt/lists/*
1619

1720
COPY . .
1821

22+
RUN useradd --create-home --uid 1000 appuser \
23+
&& chown -R appuser:appuser /app
24+
USER appuser
25+
1926
CMD ["gunicorn", "--bind", ":8080", "main:app"]

application/firstrade_client.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,23 @@ class FirstradeCredentials:
5252

5353
@classmethod
5454
def from_env(cls, env: Callable[[str, str | None], str | None] = os.getenv) -> "FirstradeCredentials":
55-
username = env("FIRSTRADE_USERNAME", "") or ""
56-
password = env("FIRSTRADE_PASSWORD", "") or ""
55+
def _get_credential(secret_name: str, env_var: str) -> str:
56+
try:
57+
from quant_platform_kit.cloud import get_secret_store
58+
59+
return get_secret_store().get_secret(secret_name, project_id="firstradequant")
60+
except Exception:
61+
return env(env_var, "") or ""
62+
63+
username = _get_credential("firstrade-username", "FIRSTRADE_USERNAME")
64+
password = _get_credential("firstrade-password", "FIRSTRADE_PASSWORD")
5765
return cls(
5866
username=username.strip(),
5967
password=password,
6068
pin=env("FIRSTRADE_PIN", "") or "",
6169
email=env("FIRSTRADE_MFA_EMAIL", "") or "",
6270
phone=env("FIRSTRADE_MFA_PHONE", "") or "",
63-
mfa_secret=env("FIRSTRADE_MFA_SECRET", "") or "",
71+
mfa_secret=_get_credential("firstrade-mfa-secret", "FIRSTRADE_MFA_SECRET"),
6472
mfa_code=env("FIRSTRADE_MFA_CODE", "") or "",
6573
cookie_dir=env("FIRSTRADE_COOKIE_DIR", ".runtime/firstrade-cookies")
6674
or ".runtime/firstrade-cookies",

application/monitor_dispatcher.py

Lines changed: 0 additions & 271 deletions
This file was deleted.

0 commit comments

Comments
 (0)