From 2802a484a23f35c56f3763fea2430964470c6620 Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Wed, 22 May 2024 16:02:04 -0600 Subject: [PATCH] Safely load config file for go2rtc --- .../main/rootfs/usr/local/go2rtc/create_config.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/docker/main/rootfs/usr/local/go2rtc/create_config.py b/docker/main/rootfs/usr/local/go2rtc/create_config.py index f3e4bdaa5..44d2170ee 100644 --- a/docker/main/rootfs/usr/local/go2rtc/create_config.py +++ b/docker/main/rootfs/usr/local/go2rtc/create_config.py @@ -32,13 +32,16 @@ config_file_yaml = config_file.replace(".yml", ".yaml") if os.path.isfile(config_file_yaml): config_file = config_file_yaml -with open(config_file) as f: - raw_config = f.read() +try: + with open(config_file) as f: + raw_config = f.read() -if config_file.endswith((".yaml", ".yml")): - config: dict[str, any] = yaml.safe_load(raw_config) -elif config_file.endswith(".json"): - config: dict[str, any] = json.loads(raw_config) + if config_file.endswith((".yaml", ".yml")): + config: dict[str, any] = yaml.safe_load(raw_config) + elif config_file.endswith(".json"): + config: dict[str, any] = json.loads(raw_config) +except FileNotFoundError: + config: dict[str, any] = {} go2rtc_config: dict[str, any] = config.get("go2rtc", {})