refactor config structure

This commit is contained in:
2021-09-20 18:08:56 +02:00
parent 46a7103900
commit 42e65848c4
7 changed files with 240 additions and 257 deletions

View File

@@ -84,24 +84,24 @@ def main():
cfg = ModifyMilterConfig(args.config, args.debug)
if not args.debug:
logger.setLevel(cfg["loglevel"])
logger.setLevel(cfg.loglevel)
if args.socket:
socket = args.socket
elif "socket" in cfg:
socket = cfg["socket"]
elif cfg.socket:
socket = cfg.socket
else:
raise RuntimeError(
"listening socket is neither specified on the command line "
"nor in the configuration file")
if not cfg["rules"]:
if not cfg.rules:
raise RuntimeError("no rules configured")
for rule_cfg in cfg["rules"]:
if not rule_cfg["actions"]:
for rule_cfg in cfg.rules:
if not rule_cfg.actions:
raise RuntimeError(
f"{rule_cfg['name']}: no actions configured")
f"{rule_cfg.name}: no actions configured")
except (RuntimeError, AssertionError) as e:
logger.error(e)