From 97e82582880361e65a343b22935274b69194506f Mon Sep 17 00:00:00 2001 From: Blake Blackshear Date: Fri, 15 Jan 2021 21:33:53 -0600 Subject: [PATCH] add env vars to config fixes #509 --- frigate/app.py | 5 +++++ frigate/config.py | 11 +++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/frigate/app.py b/frigate/app.py index 9bcd4d5b9..cd212d305 100644 --- a/frigate/app.py +++ b/frigate/app.py @@ -39,6 +39,10 @@ class FrigateApp(): self.log_queue = mp.Queue() self.camera_metrics = {} + def set_environment_vars(self): + for key, value in self.config.environment_vars.items(): + os.environ[key] = value + def ensure_dirs(self): for d in [RECORD_DIR, CLIPS_DIR, CACHE_DIR]: if not os.path.exists(d) and not os.path.islink(d): @@ -201,6 +205,7 @@ class FrigateApp(): logger.error(f"Error parsing config: {e}") self.log_process.terminate() sys.exit(1) + self.set_environment_vars() self.ensure_dirs() self.check_config() self.set_log_levels() diff --git a/frigate/config.py b/frigate/config.py index be2d0a7bb..883215d83 100644 --- a/frigate/config.py +++ b/frigate/config.py @@ -248,7 +248,8 @@ FRIGATE_CONFIG_SCHEMA = vol.Schema( vol.Optional('objects', default={}): OBJECTS_SCHEMA, vol.Optional('motion', default={}): MOTION_SCHEMA, vol.Optional('detect', default={}): DETECT_SCHEMA, - vol.Required('cameras', default={}): CAMERAS_SCHEMA + vol.Required('cameras', default={}): CAMERAS_SCHEMA, + vol.Optional('environment_vars', default={}): { str: str } } ) @@ -982,6 +983,7 @@ class FrigateConfig(): self._snapshots = SnapshotsConfig(config['clips']) self._cameras = { name: CameraConfig(name, c, config) for name, c in config['cameras'].items() } self._logger = LoggerConfig(config['logger']) + self._environment_vars = config['environment_vars'] def _sub_env_vars(self, config): frigate_env_vars = {k: v for k, v in os.environ.items() if k.startswith('FRIGATE_')} @@ -1015,7 +1017,8 @@ class FrigateConfig(): 'clips': self.clips.to_dict(), 'snapshots': self.snapshots.to_dict(), 'cameras': {k: c.to_dict() for k, c in self.cameras.items()}, - 'logger': self.logger.to_dict() + 'logger': self.logger.to_dict(), + 'environment_vars': self._environment_vars } @property @@ -1049,3 +1052,7 @@ class FrigateConfig(): @property def cameras(self) -> Dict[str, CameraConfig]: return self._cameras + + @property + def environment_vars(self): + return self._environment_vars