Set maximum amount

master
Mark Veidemanis 1 year ago
parent 3d6c8d618f
commit bea84ee2b6
Signed by: m
GPG Key ID: 5ACFCEED46C0904F

@ -20,6 +20,8 @@ log = logs.get_logger("rules")
SECONDS_PER_UNIT = {"s": 1, "m": 60, "h": 3600, "d": 86400, "w": 604800}
MAX_WINDOW = 2592000
MAX_AMOUNT_NTFY = 10
MAX_AMOUNT_WEBHOOK = 1000
class RuleParseError(Exception):
@ -426,6 +428,7 @@ class NotificationRuleData(object):
interval = self.cleaned_data.get("interval")
window = self.cleaned_data.get("window")
amount = self.cleaned_data.get("amount")
service = self.cleaned_data.get("service")
on_demand = interval == 0
if on_demand and window is not None:
@ -477,6 +480,23 @@ class NotificationRuleData(object):
"window",
)
if amount is not None:
if service == "ntfy":
if amount > MAX_AMOUNT_NTFY:
raise RuleParseError(
f"Amount cannot be larger than {MAX_AMOUNT_NTFY} for ntfy",
"amount",
)
else:
if amount > MAX_AMOUNT_WEBHOOK:
raise RuleParseError(
(
f"Amount cannot be larger than {MAX_AMOUNT_WEBHOOK} for "
f"{service}"
),
"amount",
)
def validate_permissions(self):
"""
Validate permissions for the source and index variables.

Loading…
Cancel
Save