Skip to content

Commit

Permalink
Safely load config file for go2rtc (#11491)
Browse files Browse the repository at this point in the history
* Safely load config file for go2rtc

* Add log for default config

* Cleanup
  • Loading branch information
NickM-27 committed May 22, 2024
1 parent 527d2ab commit 4d05bc2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
17 changes: 10 additions & 7 deletions docker/main/rootfs/usr/local/go2rtc/create_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,16 @@
if os.path.isfile(config_file_yaml):
config_file = config_file_yaml

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)
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)
except FileNotFoundError:
config: dict[str, any] = {}

go2rtc_config: dict[str, any] = config.get("go2rtc", {})

Expand Down
7 changes: 6 additions & 1 deletion frigate/util/builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def find_by_key(dictionary, target_key):
return None


def save_default_config(location: str):
def save_default_config(location: str) -> None:
try:
with open(location, "w") as f:
f.write(
Expand All @@ -303,6 +303,11 @@ def save_default_config(location: str):
)
except PermissionError:
logger.error("Unable to write default config to /config")
return

logger.info(
"Created default config file, see the getting started docs for configuration https://docs.frigate.video/guides/getting_started"
)


def get_tomorrow_at_time(hour: int) -> datetime.datetime:
Expand Down

0 comments on commit 4d05bc2

Please sign in to comment.