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