From ab93cae4c017393043d0c902cf7c93b5234bdb2c Mon Sep 17 00:00:00 2001 From: Jason Hunter Date: Thu, 24 Jun 2021 16:53:01 -0400 Subject: [PATCH] remove side effects from password substitution --- frigate/config.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/frigate/config.py b/frigate/config.py index c9295ada8..707d38aad 100644 --- a/frigate/config.py +++ b/frigate/config.py @@ -58,7 +58,7 @@ class MqttConfig(BaseModel): def validate_password(cls, v, values): if (v is None) != (values["user"] is None): raise ValueError("Password must be provided with username.") - return v if v is None else v.format(**FRIGATE_ENV_VARS) + return v class RetainConfig(BaseModel): @@ -328,10 +328,6 @@ class CameraInput(BaseModel): default_factory=list, title="FFmpeg input arguments." ) - @validator("path") - def sub_env_vars(cls, v): - return v.format(**FRIGATE_ENV_VARS) - class CameraFfmpegConfig(FfmpegConfig): inputs: List[CameraInput] = Field(title="Camera inputs.") @@ -665,6 +661,12 @@ class FrigateConfig(BaseModel): def runtime_config(self) -> FrigateConfig: """Merge camera config with globals.""" config = self.copy(deep=True) + + # MQTT password substitution + if config.mqtt.password: + config.mqtt.password = config.mqtt.password.format(**FRIGATE_ENV_VARS) + + # Global config to propegate down to camera level global_config = config.dict( include={ "clips": {"retain"}, @@ -682,6 +684,10 @@ class FrigateConfig(BaseModel): merged_config = deep_merge(camera.dict(exclude_unset=True), global_config) camera_config = CameraConfig.parse_obj({"name": name, **merged_config}) + # FFMPEG input substitution + for input in camera_config.ffmpeg.inputs: + input.path = input.path.format(**FRIGATE_ENV_VARS) + # Add default filters object_keys = camera_config.objects.track if camera_config.objects.filters is None: