mirror of
https://github.com/wasrusgen/zov-tech.git
synced 2026-06-03 23:04:47 +00:00
- New env: PROXY_LIST_FILE — path to file with one proxy per line - _normalize_proxy_entry accepts: http://user:pass@host:port, host:port:user:pass (Proxys.io format), host:port - _load_from_file reads file, dedup with static list - /api/proxy_status returns file_path, file_loaded count, sample (first 3 masked)
50 lines
1.8 KiB
Python
50 lines
1.8 KiB
Python
"""Конфиг бэкенда — читается из переменных окружения."""
|
||
from __future__ import annotations
|
||
import os
|
||
from dataclasses import dataclass
|
||
from functools import lru_cache
|
||
|
||
|
||
@dataclass(frozen=True)
|
||
class Config:
|
||
bot_token: str
|
||
admin_tg_id: int
|
||
sheet_id: str
|
||
google_credentials_path: str
|
||
|
||
gigachat_auth_key: str
|
||
gigachat_model: str
|
||
gigachat_scope: str
|
||
|
||
active_period_days: int
|
||
grace_period_days: int
|
||
|
||
proxy6_token: str # пусто = без прокси (прямой HTTP)
|
||
proxy_static_list: str # статический список прокси через запятую: "http://user:pass@host:port,..."
|
||
proxy_list_file: str # путь к файлу со списком прокси в формате "host:port:user:pass" или "http://..."
|
||
|
||
|
||
def _required(name: str) -> str:
|
||
val = os.getenv(name)
|
||
if not val:
|
||
raise RuntimeError(f"Missing required env var: {name}")
|
||
return val
|
||
|
||
|
||
@lru_cache(maxsize=1)
|
||
def get_config() -> Config:
|
||
return Config(
|
||
bot_token=_required("BOT_TOKEN"),
|
||
admin_tg_id=int(os.getenv("ADMIN_TG_ID", "0")),
|
||
sheet_id=_required("SHEET_ID"),
|
||
google_credentials_path=os.getenv("GOOGLE_CREDENTIALS_PATH", "/app/credentials.json"),
|
||
gigachat_auth_key=_required("GIGACHAT_AUTH_KEY"),
|
||
gigachat_model=os.getenv("GIGACHAT_MODEL", "GigaChat-Pro"),
|
||
gigachat_scope=os.getenv("GIGACHAT_SCOPE", "GIGACHAT_API_PERS"),
|
||
active_period_days=int(os.getenv("ACTIVE_PERIOD_DAYS", "90")),
|
||
grace_period_days=int(os.getenv("GRACE_PERIOD_DAYS", "14")),
|
||
proxy6_token=os.getenv("PROXY6_TOKEN", ""),
|
||
proxy_static_list=os.getenv("PROXY_STATIC_LIST", ""),
|
||
proxy_list_file=os.getenv("PROXY_LIST_FILE", ""),
|
||
)
|