From bea84ee2b67ee2ed78fee0ef41bc9195878ac5f3 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Mon, 16 Jan 2023 07:20:37 +0000 Subject: [PATCH] Set maximum amount --- core/lib/rules.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/core/lib/rules.py b/core/lib/rules.py index cb1b013..fa1b26e 100644 --- a/core/lib/rules.py +++ b/core/lib/rules.py @@ -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.