Rename variables so they make more sens

This commit is contained in:
TheophileDiot 2022-11-19 20:46:13 +01:00
parent b22cc44d82
commit db35e575e3
8 changed files with 59 additions and 39 deletions

View File

@ -78,24 +78,24 @@ class Config(ConfigCaller):
sleep(5)
# update instances in database
ret = self._db.update_instances(self.__instances)
if ret:
self.__logger.error(f"Failed to update instances: {ret}")
err = self._db.update_instances(self.__instances)
if err:
self.__logger.error(f"Failed to update instances: {err}")
# save config to database
ret = self._db.save_config(self.__config, "autoconf")
if ret:
err = self._db.save_config(self.__config, "autoconf")
if err:
success = False
self.__logger.error(
f"Can't save autoconf config in database: {ret}",
f"Can't save autoconf config in database: {err}",
)
# save custom configs to database
ret = self._db.save_custom_configs(custom_configs, "autoconf")
if ret:
err = self._db.save_custom_configs(custom_configs, "autoconf")
if err:
success = False
self.__logger.error(
f"Can't save autoconf custom configs in database: {ret}",
f"Can't save autoconf custom configs in database: {err}",
)
return success

View File

@ -108,10 +108,10 @@ try:
external_plugins.append(plugin_file)
if external_plugins:
ret = db.update_external_plugins(external_plugins)
if ret:
err = db.update_external_plugins(external_plugins)
if err:
logger.error(
f"Couldn't update external plugins to database: {ret}",
f"Couldn't update external plugins to database: {err}",
)
except:

View File

@ -174,8 +174,7 @@ if __name__ == "__main__":
retries += 1
sleep(5)
cmd = "/usr/sbin/nginx -s reload"
proc = run(cmd.split(" "), stdin=DEVNULL, stderr=STDOUT)
proc = run(["nginx", "-s", "reload"], stdin=DEVNULL, stderr=STDOUT)
if proc.returncode != 0:
status = 1
logger.error("Error while reloading nginx")

View File

@ -373,21 +373,21 @@ if __name__ == "__main__":
if apis:
for api in apis:
endpoint_data = api.get_endpoint().replace("http://", "").split(":")
ret = db.add_instance(
err = db.add_instance(
endpoint_data[0], endpoint_data[1], api.get_host()
)
if ret:
logger.warning(ret)
if err:
logger.warning(err)
else:
ret = db.add_instance(
err = db.add_instance(
"localhost",
config_files.get("API_HTTP_PORT", 5000),
config_files.get("API_SERVER_NAME", "bwapi"),
)
if ret:
logger.warning(ret)
if err:
logger.warning(err)
except SystemExit as e:
sys_exit(e)
except:

View File

@ -37,10 +37,10 @@ class BWLogger(Logger):
):
if store_db is True and db is not None:
with self.db_lock:
ret = db.save_log(msg, level, self.name)
err = db.save_log(msg, level, self.name)
if ret:
self.warning("Failed to save log to database")
if err:
self.error(f"Failed to save log to database: {err}")
return super(BWLogger, self)._log(
level, msg, args, exc_info, extra, stack_info, stacklevel

View File

@ -191,11 +191,11 @@ if __name__ == "__main__":
"Kubernetes",
"Autoconf",
):
ret = db.set_autoconf_load(False)
if ret:
err = db.set_autoconf_load(False)
if err:
success = False
logger.error(
f"Can't set autoconf loaded metadata to false in database: {ret}",
f"Can't set autoconf loaded metadata to false in database: {err}",
)
while not db.is_autoconf_loaded():
@ -208,8 +208,16 @@ if __name__ == "__main__":
or db.get_config() != dotenv_values("/var/tmp/bunkerweb/variables.env")
):
# run the config saver
cmd = f"python /usr/share/bunkerweb/gen/save_config.py --settings /usr/share/bunkerweb/settings.json"
proc = subprocess_run(cmd.split(" "), stdin=DEVNULL, stderr=STDOUT)
proc = subprocess_run(
[
"python",
"/usr/share/bunkerweb/gen/save_config.py",
"--settings",
"/usr/share/bunkerweb/settings.json",
],
stdin=DEVNULL,
stderr=STDOUT,
)
if proc.returncode != 0:
logger.error(
"Config saver failed, configuration will not work as expected...",
@ -260,10 +268,10 @@ if __name__ == "__main__":
if custom_confs:
old_configs = db.get_custom_configs()
ret = db.save_custom_configs(custom_confs, "manual")
if ret:
err = db.save_custom_configs(custom_confs, "manual")
if err:
logger.error(
f"Couldn't save some manually created custom configs to database: {ret}",
f"Couldn't save some manually created custom configs to database: {err}",
)
custom_configs = db.get_custom_configs()
@ -299,8 +307,21 @@ if __name__ == "__main__":
if generate is True:
# run the generator
cmd = f"python /usr/share/bunkerweb/gen/main.py --settings /usr/share/bunkerweb/settings.json --templates /usr/share/bunkerweb/confs --output /etc/nginx{f' --variables {args.variables}' if args.variables else ''}"
proc = subprocess_run(cmd.split(" "), stdin=DEVNULL, stderr=STDOUT)
proc = subprocess_run(
[
"python3",
"/usr/share/bunkerweb/gen/main.py",
"--settings",
"/usr/share/bunkerweb/settings.json",
"--templates",
"/usr/share/bunkerweb/confs",
"--output",
"/etc/nginx",
]
+ (["--variables", args.variables] if args.variables else []),
stdin=DEVNULL,
stderr=STDOUT,
)
if proc.returncode != 0:
logger.error(

View File

@ -166,10 +166,10 @@ class Config:
if proc.returncode != 0:
raise Exception(f"Error from generator (return code = {proc.returncode})")
ret = self.__db.save_config(conf, "ui")
if ret:
err = self.__db.save_config(conf, "ui")
if err:
self.__logger.error(
f"Can't save config in database: {ret}",
f"Can't save config in database: {err}",
)
def get_plugins_settings(self) -> dict:

View File

@ -43,9 +43,9 @@ class ConfigFiles:
}
)
ret = self.__db.save_custom_configs(custom_configs, "ui")
if ret:
self.__logger.error(f"Could not save custom configs: {ret}")
err = self.__db.save_custom_configs(custom_configs, "ui")
if err:
self.__logger.error(f"Could not save custom configs: {err}")
return "Couldn't save custom configs to database"
return ""