fix logging and CLI
This commit is contained in:
@@ -118,8 +118,8 @@ def show(cfg, args):
|
||||
for q in quarantines:
|
||||
qcfg = q["options"]
|
||||
|
||||
if "notify" in qcfg:
|
||||
notify_type = cfg["notifications"][qcfg["notify"]]["type"]
|
||||
if "notification" in qcfg:
|
||||
notify_type = cfg["notifications"][qcfg["notification"]]["type"]
|
||||
else:
|
||||
notify_type = "NONE"
|
||||
|
||||
@@ -133,7 +133,7 @@ def show(cfg, args):
|
||||
else:
|
||||
milter_action = "NONE"
|
||||
|
||||
storage_type = cfg["storages"][qcfg["store"]]["type"]
|
||||
storage_type = cfg["storages"][qcfg["storage"]]["type"]
|
||||
|
||||
qlist.append({
|
||||
"name": q["name"],
|
||||
|
||||
@@ -94,7 +94,7 @@ class BaseConfig:
|
||||
class ListConfig(BaseConfig):
|
||||
JSON_SCHEMA = {
|
||||
"type": "object",
|
||||
"required": ["name", "type"],
|
||||
"required": ["type"],
|
||||
"additionalProperties": True,
|
||||
"properties": {
|
||||
"type": {"enum": ["db"]},
|
||||
@@ -203,7 +203,6 @@ class StorageConfig(BaseConfig):
|
||||
"additionalProperties": False,
|
||||
"properties": {
|
||||
"type": {"type": "string"},
|
||||
"name": {"type": "string"},
|
||||
"directory": {"type": "string"},
|
||||
"mode": {"type": "string"},
|
||||
"metavar": {"type": "string"},
|
||||
@@ -242,7 +241,6 @@ class NotificationConfig(BaseConfig):
|
||||
"additionalProperties": False,
|
||||
"properties": {
|
||||
"type": {"type": "string"},
|
||||
"name": {"type": "string"},
|
||||
"smtp_host": {"type": "string"},
|
||||
"smtp_port": {"type": "number"},
|
||||
"envelope_from": {"type": "string"},
|
||||
@@ -422,11 +420,9 @@ class QuarantineMilterConfig(BaseConfig):
|
||||
|
||||
def __init__(self, config, rec=True):
|
||||
super().__init__(config)
|
||||
for param in ["lists", "storages", "notifications"]:
|
||||
for name, cfg in self[param].items():
|
||||
if "name" not in cfg:
|
||||
cfg["name"] = name
|
||||
for name, cfg in self["lists"].items():
|
||||
if "name" not in cfg:
|
||||
cfg["name"] = name
|
||||
self["lists"][name] = ListConfig(cfg)
|
||||
|
||||
for name, cfg in self["storages"].items():
|
||||
|
||||
@@ -334,9 +334,6 @@ class Notify:
|
||||
self.logger = logging.getLogger(cfg["name"])
|
||||
self.logger.setLevel(cfg.get_loglevel(debug))
|
||||
|
||||
self.name = f"{cfg['name']}: {cfg['options']['notification']['name']}"
|
||||
del cfg["options"]["notification"]["name"]
|
||||
|
||||
nodification_type = cfg["options"]["notification"]["type"]
|
||||
del cfg["options"]["notification"]["type"]
|
||||
|
||||
@@ -355,5 +352,5 @@ class Notify:
|
||||
|
||||
def execute(self, milter):
|
||||
logger = CustomLogger(
|
||||
self.logger, {"name": self.name, "qid": milter.qid})
|
||||
self.logger, {"name": self.cfg["name"], "qid": milter.qid})
|
||||
self._notification.execute(milter, logger)
|
||||
|
||||
@@ -374,9 +374,6 @@ class Store:
|
||||
self.logger = logging.getLogger(cfg["name"])
|
||||
self.logger.setLevel(cfg.get_loglevel(debug))
|
||||
|
||||
self.name = f"{cfg['name']}: {cfg['options']['storage']['name']}"
|
||||
del cfg["options"]["storage"]["name"]
|
||||
|
||||
storage_type = cfg["options"]["storage"]["type"]
|
||||
del cfg["options"]["storage"]["type"]
|
||||
|
||||
@@ -395,7 +392,7 @@ class Store:
|
||||
|
||||
def execute(self, milter):
|
||||
logger = CustomLogger(
|
||||
self.logger, {"name": self.name, "qid": milter.qid})
|
||||
self.logger, {"name": self.cfg["name"], "qid": milter.qid})
|
||||
self._storage.execute(milter, logger)
|
||||
|
||||
|
||||
@@ -415,11 +412,7 @@ class Quarantine:
|
||||
|
||||
self._notification = None
|
||||
if "notification" in cfg["options"]:
|
||||
#name = cfg["options"]["notification"]["name"]
|
||||
#cfg["options"]["notify"]["name"] = f"{cfg['name']}: {name}"
|
||||
#cfg["options"]["notify"]["loglevel"] = cfg["loglevel"]
|
||||
self._notification = Notify(
|
||||
cfg, local_addrs, debug)
|
||||
self._notification = Notify(cfg, local_addrs, debug)
|
||||
|
||||
self._allowlist = None
|
||||
if "allowlist" in cfg["options"]:
|
||||
|
||||
Reference in New Issue
Block a user