Safely load config file for go2rtc (#11491)

* Safely load config file for go2rtc

* Add log for default config

* Cleanup
This commit is contained in:
Nicolas Mowen
2024-05-22 17:10:55 -06:00
committed by GitHub
parent 527d2ab27b
commit 4d05bc25f4
2 changed files with 15 additions and 7 deletions

View File

@@ -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", {})