config.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. """
  2. Application configuration and settings.
  3. """
  4. import os
  5. from pathlib import Path
  6. from functools import lru_cache
  7. class Settings:
  8. """Application settings."""
  9. def __init__(self):
  10. # Application
  11. self.app_name: str = "CustomBuild API"
  12. self.app_version: str = "1.0.0"
  13. self.debug: bool = False
  14. # Paths
  15. self.base_dir: str = os.getenv(
  16. "CBS_BASEDIR",
  17. default=str(Path(__file__).parent.parent.parent.parent / "base")
  18. )
  19. # Redis
  20. self.redis_host: str = os.getenv(
  21. 'CBS_REDIS_HOST',
  22. default='localhost'
  23. )
  24. self.redis_port: str = os.getenv(
  25. 'CBS_REDIS_PORT',
  26. default='6379'
  27. )
  28. # Logging
  29. self.log_level: str = os.getenv('CBS_LOG_LEVEL', default='INFO')
  30. # ArduPilot Git Repository
  31. self.ap_git_url: str = "https://github.com/ardupilot/ardupilot.git"
  32. @property
  33. def source_dir(self) -> str:
  34. """ArduPilot source directory."""
  35. return os.path.join(self.base_dir, 'ardupilot')
  36. @property
  37. def artifacts_dir(self) -> str:
  38. """Build artifacts directory."""
  39. return os.path.join(self.base_dir, 'artifacts')
  40. @property
  41. def outdir_parent(self) -> str:
  42. """Build output directory (same as artifacts_dir)."""
  43. return self.artifacts_dir
  44. @property
  45. def workdir_parent(self) -> str:
  46. """Work directory parent."""
  47. return os.path.join(self.base_dir, 'workdir')
  48. @property
  49. def remotes_json_path(self) -> str:
  50. """Path to remotes.json configuration."""
  51. return os.path.join(self.base_dir, 'configs', 'remotes.json')
  52. @property
  53. def admin_token_file_path(self) -> str:
  54. """Path to admin token secret file."""
  55. return os.path.join(self.base_dir, 'secrets', 'reload_token')
  56. @property
  57. def enable_inbuilt_builder(self) -> bool:
  58. """Whether to enable the inbuilt builder."""
  59. return os.getenv('CBS_ENABLE_INBUILT_BUILDER', '1') == '1'
  60. @property
  61. def admin_token_env(self) -> str:
  62. """Token required to reload remotes.json via API."""
  63. env = os.getenv('CBS_REMOTES_RELOAD_TOKEN', '')
  64. return env if env != '' else None
  65. @lru_cache()
  66. def get_settings() -> Settings:
  67. """Get cached settings instance."""
  68. return Settings()