mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-11-25 23:07:07 +03:00
fix
This commit is contained in:
+19
-2
@@ -74,7 +74,7 @@ from frigate.util.config import (
|
|||||||
find_config_file,
|
find_config_file,
|
||||||
redact_credential,
|
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 (
|
from frigate.util.live_streams import (
|
||||||
generated_transcode_streams,
|
generated_transcode_streams,
|
||||||
sync_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):
|
if not isinstance(saved_cameras, dict):
|
||||||
saved_cameras = {}
|
saved_cameras = {}
|
||||||
|
|
||||||
|
saved_env_vars = saved.get("environment_vars")
|
||||||
|
|
||||||
for camera_name, camera_data in cameras.items():
|
for camera_name, camera_data in cameras.items():
|
||||||
if not isinstance(camera_data, dict):
|
if not isinstance(camera_data, dict):
|
||||||
continue
|
continue
|
||||||
@@ -839,7 +841,7 @@ def _restore_masked_camera_paths(config_data: dict, saved: dict) -> str | None:
|
|||||||
candidates = [
|
candidates = [
|
||||||
inp
|
inp
|
||||||
for inp in saved_inputs
|
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:
|
if len({inp["path"] for inp in candidates}) > 1:
|
||||||
candidates = [
|
candidates = [
|
||||||
@@ -866,6 +868,21 @@ def _resolve_frigate_vars(value: str) -> str:
|
|||||||
return value
|
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]:
|
def _saved_config_from_memory(config: FrigateConfig) -> dict[str, Any]:
|
||||||
"""Shape the in-memory camera inputs like the saved YAML."""
|
"""Shape the in-memory camera inputs like the saved YAML."""
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -624,6 +624,51 @@ class TestConfigSetWildcardPropagation(BaseTestHttp):
|
|||||||
finally:
|
finally:
|
||||||
os.unlink(config_path)
|
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")
|
@patch("frigate.api.app.find_config_file")
|
||||||
def test_over_masked_path_round_trips(self, mock_find_config):
|
def test_over_masked_path_round_trips(self, mock_find_config):
|
||||||
path = "rtsp://10.0.0.1:554/live?x=a@b"
|
path = "rtsp://10.0.0.1:554/live?x=a@b"
|
||||||
|
|||||||
Reference in New Issue
Block a user