Self-hosted homelab infrastructure visualizer — interactive network diagram with live status monitoring
TypeScript diagramhomelabhomelab-infrastructure-observabilitynetworkproxmox-veself-hostedzigbeezwavezwave-js
fix(unifi): keep the connection config env-only
Pouzor03c46377f580
diff --git a/backend/app/core/config.py b/backend/app/core/config.pyindex bbd6037..8d43ac1 100644--- a/backend/app/core/config.py+++ b/backend/app/core/config.py@@ -212,7 +212,7 @@ class Settings(BaseSettings):# 'user@realm!tokenname'; use a read-only PVEAuditor role.proxmox_token_id: str = ""proxmox_token_secret: str = ""- # Non-secret connection + auto-sync config (persisted via save_overrides).+ # Connection config is env-only; only the auto-sync activation is persisted.proxmox_host: str = ""proxmox_port: int = 8006proxmox_verify_tls: bool = True@@ -261,8 +261,8 @@ class Settings(BaseSettings):# Accepts UNIFI_USER or UNIFI_USERNAME; UNIFI_PASS or UNIFI_PASSWORD.unifi_username: str = Field("", alias="unifi_user", validation_alias=AliasChoices("unifi_username", "unifi_user"))unifi_password: str = Field("", alias="unifi_pass", validation_alias=AliasChoices("unifi_password", "unifi_pass"))- # Non-secret connection + auto-sync config (persisted via save_overrides).- # Accepts UNIFI_URL (full URL) or UNIFI_HOST (bare host/IP).+ # Connection config is env-only; only the auto-sync activation and import+ # modes are persisted. Accepts UNIFI_URL (full URL) or UNIFI_HOST (bare host/IP).unifi_url: str = ""unifi_host: str = ""unifi_port: int = 8443@@ -341,6 +341,9 @@ class Settings(BaseSettings):self.zwave_sync_enabled = bool(data["zwave_sync_enabled"])if "zwave_sync_interval" in data:self.zwave_sync_interval = int(data["zwave_sync_interval"])+ # UniFi: auto-sync activation and import modes only. Connection+ # config (host, port, site, verify_tls) is env-only, same reason+ # as Proxmox: a persisted empty host clobbered UNIFI_HOST.if "unifi_sync_enabled" in data:self.unifi_sync_enabled = bool(data["unifi_sync_enabled"])if "unifi_sync_interval" in data:@@ -349,14 +352,6 @@ class Settings(BaseSettings):key = f"unifi_import_{mode}"if key in data:setattr(self, key, bool(data[key]))- if "unifi_host" in data:- self.unifi_host = str(data["unifi_host"])- if "unifi_port" in data:- self.unifi_port = int(data["unifi_port"])- if "unifi_site" in data:- self.unifi_site = str(data["unifi_site"])- if "unifi_verify_tls" in data:- self.unifi_verify_tls = bool(data["unifi_verify_tls"])except Exception:pass@@ -383,17 +378,13 @@ class Settings(BaseSettings):"zigbee_sync_include_mesh_links": self.zigbee_sync_include_mesh_links,"zwave_sync_enabled": self.zwave_sync_enabled,"zwave_sync_interval": self.zwave_sync_interval,- # UniFi: non-secret connection config + auto-sync activation persisted.- # Credentials (username/password) are env-only and never written here.+ # UniFi: auto-sync activation and import modes only. Connection+ # config (host/port/site/verify_tls) and credentials are env-only."unifi_sync_enabled": self.unifi_sync_enabled,"unifi_sync_interval": self.unifi_sync_interval,"unifi_import_infrastructure": self.unifi_import_infrastructure,"unifi_import_known_clients": self.unifi_import_known_clients,"unifi_import_active_clients": self.unifi_import_active_clients,- "unifi_host": self.unifi_host,- "unifi_port": self.unifi_port,- "unifi_site": self.unifi_site,- "unifi_verify_tls": self.unifi_verify_tls,}))diff --git a/backend/tests/test_settings.py b/backend/tests/test_settings.pyindex 1e09ff0..66d19eb 100644--- a/backend/tests/test_settings.py+++ b/backend/tests/test_settings.py@@ -196,6 +196,53 @@ def test_save_overrides_omits_mesh_credentials(tmp_path):assert written["zwave_sync_interval"] == 1200+def test_unifi_connection_config_is_env_only_never_from_overrides(tmp_path):+ """Regression #538: a scan_config.json written before UNIFI_* was set holds+ an empty host and the default port. It must not clobber the env values.+ Only the auto-sync activation and import modes are read back."""+ s = Settings(secret_key="x", sqlite_path=str(tmp_path / "homelab.db"))+ s.unifi_host = "unifi.lan" # as if set from env+ s.unifi_port = 443+ s.unifi_site = "home"+ s.unifi_verify_tls = True+ (tmp_path / "scan_config.json").write_text(json.dumps({+ "unifi_host": "",+ "unifi_port": 8443,+ "unifi_site": "default",+ "unifi_verify_tls": False,+ "unifi_sync_enabled": True,+ "unifi_sync_interval": 600,+ "unifi_import_known_clients": True,+ }))+ s.load_overrides()+ assert s.unifi_host == "unifi.lan"+ assert s.unifi_port == 443+ assert s.unifi_site == "home"+ assert s.unifi_verify_tls is True+ assert s.unifi_effective_host == "unifi.lan"+ assert s.unifi_sync_enabled is True+ assert s.unifi_sync_interval == 600+ assert s.unifi_import_known_clients is True+++def test_save_overrides_omits_unifi_connection_config(tmp_path):+ """Saving any settings section must not freeze the UniFi connection config+ (nor the credentials) into scan_config.json."""+ s = Settings(secret_key="x", sqlite_path=str(tmp_path / "homelab.db"))+ s.unifi_host = "unifi.lan"+ s.unifi_password = "secret"+ s.unifi_sync_enabled = True+ s.unifi_sync_interval = 900+ s.save_overrides()+ raw = (tmp_path / "scan_config.json").read_text()+ assert "secret" not in raw+ written = json.loads(raw)+ for key in ("unifi_host", "unifi_port", "unifi_site", "unifi_verify_tls", "unifi_url"):+ assert key not in written+ assert written["unifi_sync_enabled"] is True+ assert written["unifi_sync_interval"] == 900++def test_zigbee_mesh_links_setting_round_trips(tmp_path):"""The auto-sync mesh-links opt-in is a UI setting: it must survive a restart."""