From 586aafd476d957ffaebf601087ddcb393a403a78 Mon Sep 17 00:00:00 2001 From: Pulse Monitor Date: Tue, 19 Aug 2025 08:44:18 +0000 Subject: [PATCH] fix: restore environment variable support for key settings - Re-enable DISCOVERY_SUBNET env var for Docker network configuration - Re-enable LOG_LEVEL env var for runtime logging control - Re-enable CONNECTION_TIMEOUT env var for timeout configuration - Re-enable ALLOWED_ORIGINS env var for CORS configuration - Update documentation to reflect working env vars These env vars were accidentally disabled but are useful for Docker deployments. Env vars override system.json settings when present. Addresses #214 - user requested DISCOVERY_SUBNET env var support --- README.md | 9 +-------- docs/DOCKER.md | 4 ++-- internal/config/config.go | 24 ++++++++++++++++++++++-- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index d8b156b6a..c3cd30f48 100644 --- a/README.md +++ b/README.md @@ -128,16 +128,9 @@ services: # RIGHT: PULSE_AUTH_PASS='$$2a$$12$$hash...' # Or use a .env file where no escaping is needed - # Polling & timeouts - # - POLLING_INTERVAL=10 # Fixed at 10 seconds (matches Proxmox update cycle) + # Performance # - CONNECTION_TIMEOUT=10 # Connection timeout in seconds (default: 10) - # Updates - # - UPDATE_CHANNEL=stable # Update channel: stable or rc (default: stable) - # - AUTO_UPDATE_ENABLED=false # Enable auto-updates (default: false) - # - AUTO_UPDATE_CHECK_INTERVAL=24 # Hours between update checks (default: 24) - # - AUTO_UPDATE_TIME=03:00 # Time to install updates HH:MM (default: 03:00) - # CORS & logging # - ALLOWED_ORIGINS=https://app.example.com # CORS origins (default: none, same-origin only) # - LOG_LEVEL=info # Log level: debug/info/warn/error (default: info) diff --git a/docs/DOCKER.md b/docs/DOCKER.md index 742b5b709..597935358 100644 --- a/docs/DOCKER.md +++ b/docs/DOCKER.md @@ -219,12 +219,12 @@ Common problems: | `PORT` | Web UI port | `7655` | | `ALLOWED_ORIGINS` | CORS origins | Same-origin only | | `DISCOVERY_SUBNET` | Network to scan | Auto-detect | +| `CONNECTION_TIMEOUT` | Connection timeout (seconds) | `10` | +| `LOG_LEVEL` | Logging verbosity | `info` | ### System | Variable | Description | Default | |----------|-------------|---------| -| `POLLING_INTERVAL` | Check interval (seconds) | `10` | -| `LOG_LEVEL` | Logging verbosity | `INFO` | | `TZ` | Timezone | `UTC` | ## Advanced Configuration diff --git a/internal/config/config.go b/internal/config/config.go index 61696f304..6beda0c48 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -385,8 +385,28 @@ func Load() (*Config, error) { log.Info().Msg("Development mode: allowing localhost origins") } } - // REMOVED: LOG_LEVEL and DISCOVERY_SUBNET env vars - // These settings now ONLY come from system.json to prevent confusion + // Support env vars for important settings (override system.json) + if discoverySubnet := os.Getenv("DISCOVERY_SUBNET"); discoverySubnet != "" { + cfg.DiscoverySubnet = discoverySubnet + log.Info().Str("subnet", discoverySubnet).Msg("Discovery subnet set from DISCOVERY_SUBNET env var") + } + if logLevel := os.Getenv("LOG_LEVEL"); logLevel != "" { + cfg.LogLevel = logLevel + log.Info().Str("level", logLevel).Msg("Log level set from LOG_LEVEL env var") + } + if connectionTimeout := os.Getenv("CONNECTION_TIMEOUT"); connectionTimeout != "" { + if d, err := time.ParseDuration(connectionTimeout + "s"); err == nil { + cfg.ConnectionTimeout = d + log.Info().Dur("timeout", d).Msg("Connection timeout set from CONNECTION_TIMEOUT env var") + } else if d, err := time.ParseDuration(connectionTimeout); err == nil { + cfg.ConnectionTimeout = d + log.Info().Dur("timeout", d).Msg("Connection timeout set from CONNECTION_TIMEOUT env var") + } + } + if allowedOrigins := os.Getenv("ALLOWED_ORIGINS"); allowedOrigins != "" { + cfg.AllowedOrigins = allowedOrigins + log.Info().Str("origins", allowedOrigins).Msg("Allowed origins set from ALLOWED_ORIGINS env var") + } // Set log level switch cfg.LogLevel {