From f8beb5f859469e41abb43925b8929c41ff4837b4 Mon Sep 17 00:00:00 2001 From: Yax <1949284+kianby@users.noreply.github.com> Date: Sat, 12 Nov 2022 22:32:13 +0100 Subject: [PATCH] check configuration --- run.py | 7 ++++--- stacosys/conf/config.py | 4 ++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/run.py b/run.py index 33a833e..632883d 100644 --- a/run.py +++ b/run.py @@ -39,9 +39,10 @@ def stacosys_server(config_pathname): logger.error(f"Configuration file '{config_pathname}' not found.") sys.exit(1) - # initialize config + # load config conf = Config.load(config_pathname) - logger.info(conf.__repr__()) + conf.check() + logger.info(conf) # check database file exists (prevents from creating a fresh db) db_pathname = conf.get(ConfigParameter.DB_SQLITE_FILE) @@ -70,7 +71,7 @@ def stacosys_server(config_pathname): conf.get_int(ConfigParameter.SMTP_PORT), conf.get(ConfigParameter.SMTP_LOGIN), conf.get(ConfigParameter.SMTP_PASSWORD), - conf.get(ConfigParameter.SITE_ADMIN_EMAIL) + conf.get(ConfigParameter.SITE_ADMIN_EMAIL), ) # inject config parameters into flask diff --git a/stacosys/conf/config.py b/stacosys/conf/config.py index 1de3ce0..8399e2e 100644 --- a/stacosys/conf/config.py +++ b/stacosys/conf/config.py @@ -74,6 +74,10 @@ class Config: assert value in ("yes", "true", "no", "false") return value in ("yes", "true") + def check(self): + for key in ConfigParameter: + assert self.get(key), f"Paramètre introuvable : {key.value}" + def __repr__(self): d = dict() for section in self._cfg.sections():