config.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. from functools import lru_cache
  2. from pydantic_settings import BaseSettings, SettingsConfigDict
  3. from pydantic import Field
  4. class Settings(BaseSettings):
  5. # -----------------------
  6. # App
  7. # -----------------------
  8. app_name: str = "MyApp"
  9. env: str = "PROD"
  10. debug: bool = False
  11. # -----------------------
  12. # Database / Cache
  13. # -----------------------
  14. database_url: str = Field(..., description="Async database DSN")
  15. redis_url: str
  16. # -----------------------
  17. # Security / API Keys
  18. # -----------------------
  19. openai_api_key: str
  20. stripe_api_key: str
  21. # -----------------------
  22. # Remote Servers
  23. # -----------------------
  24. remote_servers: dict = {
  25. "MCP1": {
  26. "host": "45.137.220.138",
  27. "port": 22,
  28. "username": "root",
  29. "password": "s3UqbkWxW72",
  30. "project_path": "/root/troov-asyncio"
  31. },
  32. "MCP2": {
  33. "host": "185.148.147.103",
  34. "port": 22,
  35. "username": "root",
  36. "password": "nBEqFzWe7z7pbprypmUt",
  37. "project_path": "/root/troov-asyncio"
  38. },
  39. "MCP3": {
  40. "host": "185.148.147.119",
  41. "port": 22,
  42. "username": "root",
  43. "password": "5hcm07IAnBAv87Ey",
  44. "project_path": "/root/troov-asyncio"
  45. }
  46. }
  47. model_config = SettingsConfigDict(
  48. env_file=".env",
  49. env_file_encoding="utf-8",
  50. case_sensitive=False,
  51. )
  52. @lru_cache
  53. def get_settings() -> Settings:
  54. """
  55. 避免多次实例化 Settings(FastAPI 官方推荐)
  56. """
  57. return Settings()
  58. settings = get_settings()
  59. # -----------------------
  60. # Global constants
  61. # -----------------------
  62. BASE_CURRENCY = "EUR"