/
HookDev-Arch
/
ServerMonitor
Обзор
Документация
Войти
/
HookDev-Arch
/
ServerMonitor
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
2
CI/CD
Аналитика
Безопасность
master
core/config.py
81 строка
3 KB
HookDev-Arch
upload files
09 окт 2025, 02:25
09 окт 2025, 02:25
8bd6873
Код
Авторство
О чём код?
"""Centralised configuration helpers for HookDev-Arch Dashboard.""" import os from pathlib import Path class Settings: """Runtime configuration container with sensible defaults.""" def __init__(self) -> None: # Application identity and runtime mode self.app_name = os.getenv("APP_NAME", "HookDev-Arch Dashboard") self.version = os.getenv("VERSION", "3.5.5") self.debug = os.getenv("DEBUG", "false").lower() == "true" # HTTP server configuration self.host = os.getenv("HOST", "0.0.0.0") self.port = int(os.getenv("PORT", "8888")) self.auto_find_port = os.getenv("AUTO_FIND_PORT", "true").lower() == "true" self.max_port_attempts = int(os.getenv("MAX_PORT_ATTEMPTS", "100")) # Security-related settings self.secret_key = os.getenv("SECRET_KEY", "hookdev-arch-secret-key-2024") self.token_expiry_hours = int(os.getenv("TOKEN_EXPIRY_HOURS", "24")) self.password_min_length = int(os.getenv("PASSWORD_MIN_LENGTH", "8")) # Performance tuning self.cache_ttl = int(os.getenv("CACHE_TTL", "5")) self.max_concurrent_requests = int(os.getenv("MAX_CONCURRENT_REQUESTS", "10")) self.request_timeout = int(os.getenv("REQUEST_TIMEOUT", "10")) # Metrics & logging self.enable_metrics = os.getenv("ENABLE_METRICS", "true").lower() == "true" self.metrics_retention_days = int(os.getenv("METRICS_RETENTION_DAYS", "30")) self.log_level = os.getenv("LOG_LEVEL", "INFO") # Optional external services self.database_url = os.getenv("DATABASE_URL") # Public IP discovery services self.ip_services = [ "https://api.ipify.org", "https://ipinfo.io/ip", "https://icanhazip.com", "https://ifconfig.me/ip", "https://checkip.amazonaws.com", ] # Preferred GPU backends self.gpu_backend_priority = ["nvml", "nvidia-smi"] # Logging targets self.log_file = os.getenv("LOG_FILE", "data/logs/app.log") self.log_max_size = int(os.getenv("LOG_MAX_SIZE", str(10 * 1024 * 1024))) self.log_backup_count = int(os.getenv("LOG_BACKUP_COUNT", "5")) # Authentication defaults self.auth_file = os.getenv("AUTH_FILE", "data/auth.json") self.require_auth = os.getenv("REQUIRE_AUTH", "true").lower() == "true" # Shared settings singleton for application imports settings = Settings() def setup_directories() -> None: """Create directories that must exist before the app boots.""" directories = [ "data", "data/logs", "data/cache", "data/backups", ] for directory in directories: Path(directory).mkdir(parents=True, exist_ok=True) # Run directory bootstrap when the module is imported setup_directories()