From ab5469db29a373d3243713d94cc250d2eb0407ca Mon Sep 17 00:00:00 2001 From: Thomas Oettli Date: Fri, 12 Jan 2024 17:51:20 +0100 Subject: [PATCH] cleanup --- pyquarantine/cli.py | 3 ++- pyquarantine/config.py | 15 +++++---------- pyquarantine/notify.py | 3 ++- pyquarantine/storage.py | 3 ++- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/pyquarantine/cli.py b/pyquarantine/cli.py index 0634561..4a0bed2 100644 --- a/pyquarantine/cli.py +++ b/pyquarantine/cli.py @@ -119,7 +119,8 @@ def show(cfg, args): qcfg = q["options"] if "notification" in qcfg: - notify_type = cfg["notifications"][qcfg["notification"]]["type"] + notification = cfg["notifications"][qcfg["notification"]] + notify_type = notification["type"] else: notify_type = "NONE" diff --git a/pyquarantine/config.py b/pyquarantine/config.py index 0b4127b..19b7e31 100644 --- a/pyquarantine/config.py +++ b/pyquarantine/config.py @@ -297,11 +297,11 @@ class QuarantineConfig(BaseConfig): if "metadata" not in self["storage"]: self["storage"]["metadata"] = True if "notification" in self: - notification = self["notification"] + name = self["notification"] try: - self["notification"] = milter_config["notifications"][notification] + self["notification"] = milter_config["notifications"][name] except KeyError: - raise RuntimeError(f"notification '{notification}' not found") + raise RuntimeError(f"notification '{name}' not found") if "allowlist" in self: allowlist = self["allowlist"] try: @@ -344,13 +344,8 @@ class ActionConfig(BaseConfig): if "conditions" in self: self["conditions"] = ConditionsConfig(self["conditions"], lists) - if self["type"] == "store": - storage = StoreConfig(self["options"], milter_config)["storage"] - elif self["type"] == "notify": - notify = NotifyConfig(self["options"], milter_config)["notification"] - else: - self["action"] = self.ACTION_TYPES[self["type"]]( - self["options"], milter_config) + self["action"] = self.ACTION_TYPES[self["type"]]( + self["options"], milter_config) class RuleConfig(BaseConfig): diff --git a/pyquarantine/notify.py b/pyquarantine/notify.py index 7b6b76f..b0f38be 100644 --- a/pyquarantine/notify.py +++ b/pyquarantine/notify.py @@ -337,7 +337,8 @@ class Notify: nodification_type = cfg["options"]["notification"]["type"] del cfg["options"]["notification"]["type"] - self._notification = self.NOTIFICATION_TYPES[nodification_type](**cfg["options"]["notification"]) + ncfg = cfg["options"]["notification"] + self._notification = self.NOTIFICATION_TYPES[nodification_type](**ncfg) self._headersonly = self._notification._headersonly def __str__(self): diff --git a/pyquarantine/storage.py b/pyquarantine/storage.py index 854cd28..ed0b26c 100644 --- a/pyquarantine/storage.py +++ b/pyquarantine/storage.py @@ -377,7 +377,8 @@ class Store: storage_type = cfg["options"]["storage"]["type"] del cfg["options"]["storage"]["type"] - self._storage = self.STORAGE_TYPES[storage_type](**cfg["options"]["storage"]) + scfg = cfg["options"]["storage"] + self._storage = self.STORAGE_TYPES[storage_type](**scfg) self._headersonly = self._storage._headersonly def __str__(self):