from __future__ import annotations import os from dotenv import load_dotenv from dataclasses import dataclass from functools import lru_cache @dataclass(frozen=True) class Settings: feishu_app_id: str feishu_app_secret: str feishu_verify_token: str feishu_encrypt_key: str feishu_ws_url: str huobanyun_app_id: str huobanyun_app_secret: str huobanyun_token: str huobanyun_api_key: str huobanyun_base_url: str log_level: str log_rotation: str log_max_bytes: int log_backup_count: int log_query_token: str request_timeout: int retry_count: int def _env(name: str, default: str = "") -> str: return os.getenv(name, default).strip() @lru_cache(maxsize=1) def get_settings() -> Settings: load_dotenv() return Settings( feishu_app_id=_env("FEISHU_APP_ID"), feishu_app_secret=_env("FEISHU_APP_SECRET"), feishu_verify_token=_env("FEISHU_VERIFY_TOKEN"), feishu_encrypt_key=_env("FEISHU_ENCRYPT_KEY"), feishu_ws_url=_env("FEISHU_WS_URL"), huobanyun_app_id=_env("HUOBANYUN_APP_ID"), huobanyun_app_secret=_env("HUOBANYUN_APP_SECRET"), huobanyun_token=_env("HUOBANYUN_TOKEN"), huobanyun_api_key=_env("HUOBANYUN_API_KEY"), huobanyun_base_url=_env("HUOBANYUN_BASE_URL"), log_level=_env("LOG_LEVEL", "INFO"), log_rotation=_env("LOG_ROTATION", "size"), log_max_bytes=int(_env("LOG_MAX_BYTES", "10485760")), log_backup_count=int(_env("LOG_BACKUP_COUNT", "10")), log_query_token=_env("LOG_QUERY_TOKEN"), request_timeout=int(_env("REQUEST_TIMEOUT", "10")), retry_count=int(_env("RETRY_COUNT", "2")), )