This commit is contained in:
Josh Hawkins
2026-11-24 09:26:07 -06:00
parent 0798d3f247
commit bcd64d96a6
2 changed files with 64 additions and 2 deletions
+19 -2
View File
@@ -74,7 +74,7 @@ from frigate.util.config import (
find_config_file,
redact_credential,
)
from frigate.util.env import substitute_frigate_vars
from frigate.util.env import candidate_env_vars, substitute_frigate_vars
from frigate.util.live_streams import (
generated_transcode_streams,
sync_transcode_streams,
@@ -810,6 +810,8 @@ def _restore_masked_camera_paths(config_data: dict, saved: dict) -> str | None:
if not isinstance(saved_cameras, dict):
saved_cameras = {}
saved_env_vars = saved.get("environment_vars")
for camera_name, camera_data in cameras.items():
if not isinstance(camera_data, dict):
continue
@@ -839,7 +841,7 @@ def _restore_masked_camera_paths(config_data: dict, saved: dict) -> str | None:
candidates = [
inp
for inp in saved_inputs
if clean_camera_user_pass(_resolve_frigate_vars(inp["path"])) == path
if path in _masked_saved_paths(inp["path"], saved_env_vars)
]
if len({inp["path"] for inp in candidates}) > 1:
candidates = [
@@ -866,6 +868,21 @@ def _resolve_frigate_vars(value: str) -> str:
return value
def _masked_saved_paths(path: str, saved_env_vars: Any) -> set[str]:
"""Mask a saved camera path the ways /config can show it.
/config resolves placeholders with the installed environment_vars until a
no-restart update swaps in a config parsed with the saved block.
"""
with candidate_env_vars(saved_env_vars):
saved_resolved = _resolve_frigate_vars(path)
return {
clean_camera_user_pass(_resolve_frigate_vars(path)),
clean_camera_user_pass(saved_resolved),
}
def _saved_config_from_memory(config: FrigateConfig) -> dict[str, Any]:
"""Shape the in-memory camera inputs like the saved YAML."""
return {
@@ -624,6 +624,51 @@ class TestConfigSetWildcardPropagation(BaseTestHttp):
finally:
os.unlink(config_path)
@patch.dict("frigate.util.env._CONFIG_ENV_VARS", {"FRIGATE_CAM_HOST": "10.0.0.1"})
@patch.dict("frigate.util.env.FRIGATE_ENV_VARS", {"FRIGATE_CAM_HOST": "10.0.0.1"})
@patch("frigate.api.app.find_config_file")
def test_masked_path_matches_after_saved_env_var_swap(self, mock_find_config):
"""A no-restart update swaps in a config resolved with the saved
environment_vars, so /config shows the saved value until a restart."""
path = "rtsp://admin:pw@{FRIGATE_CAM_HOST}:554/live"
self._set_inputs([(path, "detect")])
self.minimal_config["environment_vars"] = {"FRIGATE_CAM_HOST": "10.0.0.2"}
config_path = self._write_config_file()
mock_find_config.return_value = config_path
try:
app, _ = self._create_app_with_publisher()
with AuthTestClient(app) as client:
resp = self._save(
client, {"cameras": {"front_door": {"detect": {"fps": 6}}}}
)
self.assertEqual(resp.status_code, 200, resp.text)
camera = client.get("/config").json()["cameras"]["front_door"]
inputs = camera["ffmpeg"]["inputs"]
self.assertIn("10.0.0.2", inputs[0]["path"])
resp = self._save(
client,
{
"cameras": {
"front_door": {
"ffmpeg": {"inputs": inputs},
"detect": {"fps": 7},
}
}
},
)
self.assertEqual(resp.status_code, 200, resp.text)
_, saved = self._read_config_file(config_path)
self.assertEqual(
saved["cameras"]["front_door"]["ffmpeg"]["inputs"][0]["path"], path
)
finally:
os.unlink(config_path)
@patch("frigate.api.app.find_config_file")
def test_over_masked_path_round_trips(self, mock_find_config):
path = "rtsp://10.0.0.1:554/live?x=a@b"