Skip to content

Commit

Permalink
chore: Improve Config.py by handling invalid multisite settings and a…
Browse files Browse the repository at this point in the history
…dding debug logs
  • Loading branch information
TheophileDiot committed Jun 17, 2024
1 parent c100e1c commit 52c37d7
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/autoconf/Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,12 @@ def __get_full_env(self) -> dict:
if not server_name:
continue
for variable, value in service.items():
if self._db.is_setting(variable, multisite=True):
config[f"{server_name}_{variable}"] = value
if variable.startswith("CUSTOM_CONF") or not variable.isupper():
continue
if not self._db.is_setting(variable, multisite=True):
self.__logger.warning(f"Variable {variable}: {value} is not a valid multisite setting, ignoring it")
continue
config[f"{server_name}_{variable}"] = value
config["SERVER_NAME"] += f" {server_name}"
config["SERVER_NAME"] = config["SERVER_NAME"].strip()
return config
Expand Down Expand Up @@ -134,13 +138,15 @@ def apply(

# update instances in database
if "instances" in changes:
self.__logger.debug(f"Updating instances in database: {self.__instances}")
err = self._db.update_instances(self.__instances, changed=False)
if err:
self.__logger.error(f"Failed to update instances: {err}")

# save config to database
changed_plugins = []
if "config" in changes:
self.__logger.debug(f"Saving config in database: {self.__config}")
err = self._db.save_config(self.__config, "autoconf", changed=False)
if isinstance(err, str):
success = False
Expand All @@ -149,6 +155,7 @@ def apply(

# save custom configs to database
if "custom_configs" in changes:
self.__logger.debug(f"Saving custom configs in database: {custom_configs}")
err = self._db.save_custom_configs(custom_configs, "autoconf", changed=False)
if err:
success = False
Expand Down

0 comments on commit 52c37d7

Please sign in to comment.