From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id DF7431FF0E0 for ; Thu, 09 Jul 2026 13:57:46 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id E9EE1214C4; Thu, 09 Jul 2026 13:57:33 +0200 (CEST) From: Lukas Wagner To: pbs-devel@lists.proxmox.com, pve-devel@lists.proxmox.com Subject: [PATCH proxmox 06/29] notify: matcher: break out calendar matcher into submodule Date: Thu, 9 Jul 2026 13:56:53 +0200 Message-ID: <20260709115716.299836-7-l.wagner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260709115716.299836-1-l.wagner@proxmox.com> References: <20260709115716.299836-1-l.wagner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1783598238216 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.000 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: SMNAR7TYDPTG7Q3ZIIIRDPP66M2ZFOZ5 X-Message-ID-Hash: SMNAR7TYDPTG7Q3ZIIIRDPP66M2ZFOZ5 X-MailFrom: l.wagner@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox Backup Server development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: No functional changes. Signed-off-by: Lukas Wagner --- proxmox-notify/src/matcher/calendar.rs | 46 ++++++++++++++++++++++++ proxmox-notify/src/matcher/mod.rs | 48 +++----------------------- 2 files changed, 50 insertions(+), 44 deletions(-) create mode 100644 proxmox-notify/src/matcher/calendar.rs diff --git a/proxmox-notify/src/matcher/calendar.rs b/proxmox-notify/src/matcher/calendar.rs new file mode 100644 index 00000000..5deab13e --- /dev/null +++ b/proxmox-notify/src/matcher/calendar.rs @@ -0,0 +1,46 @@ +use std::fmt; +use std::str::FromStr; + +use proxmox_time::DailyDuration; + +use crate::{Error, Notification}; + +use super::MatchDirective; + +/// Match timestamp of the notification. +#[derive(Clone, Debug)] +pub struct CalendarMatcher { + schedule: DailyDuration, + original: String, +} + +impl MatchDirective for CalendarMatcher { + fn matches(&self, notification: &Notification) -> Result { + self.schedule + .time_match(notification.metadata.timestamp, false) + .map_err(|err| Error::Generic(format!("could not match timestamp: {err}"))) + } +} + +impl fmt::Display for CalendarMatcher { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.write_str(&self.original) + } +} + +impl FromStr for CalendarMatcher { + type Err = Error; + + fn from_str(s: &str) -> Result { + let schedule = proxmox_time::parse_daily_duration(s) + .map_err(|e| Error::Generic(format!("could not parse schedule: {e}")))?; + + Ok(Self { + schedule, + original: s.to_string(), + }) + } +} + +proxmox_serde::forward_deserialize_to_from_str!(CalendarMatcher); +proxmox_serde::forward_serialize_to_display!(CalendarMatcher); diff --git a/proxmox-notify/src/matcher/mod.rs b/proxmox-notify/src/matcher/mod.rs index dce9ec5c..8c9e5505 100644 --- a/proxmox-notify/src/matcher/mod.rs +++ b/proxmox-notify/src/matcher/mod.rs @@ -1,23 +1,20 @@ use std::collections::HashSet; -use std::fmt; use std::fmt::Debug; -use std::str::FromStr; -use const_format::concatcp; -use regex::Regex; use serde::{Deserialize, Serialize}; use tracing::{error, info}; -use proxmox_schema::api_types::{COMMENT_SCHEMA, SAFE_ID_REGEX_STR}; -use proxmox_schema::{ApiStringFormat, Schema, StringSchema, Updater, api, const_regex}; -use proxmox_time::{DailyDuration, parse_daily_duration}; +use proxmox_schema::api_types::COMMENT_SCHEMA; +use proxmox_schema::{Updater, api}; use crate::schema::ENTITY_NAME_SCHEMA; use crate::{Error, Notification, Origin}; +pub mod calendar; pub mod field; pub mod severity; +use calendar::CalendarMatcher; use field::FieldMatcher; use severity::SeverityMatcher; @@ -203,43 +200,6 @@ impl MatcherConfig { } } -/// Match timestamp of the notification. -#[derive(Clone, Debug)] -pub struct CalendarMatcher { - schedule: DailyDuration, - original: String, -} - -proxmox_serde::forward_deserialize_to_from_str!(CalendarMatcher); -proxmox_serde::forward_serialize_to_display!(CalendarMatcher); - -impl MatchDirective for CalendarMatcher { - fn matches(&self, notification: &Notification) -> Result { - self.schedule - .time_match(notification.metadata.timestamp, false) - .map_err(|err| Error::Generic(format!("could not match timestamp: {err}"))) - } -} - -impl fmt::Display for CalendarMatcher { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.write_str(&self.original) - } -} - -impl FromStr for CalendarMatcher { - type Err = Error; - fn from_str(s: &str) -> Result { - let schedule = parse_daily_duration(s) - .map_err(|e| Error::Generic(format!("could not parse schedule: {e}")))?; - - Ok(Self { - schedule, - original: s.to_string(), - }) - } -} - #[api] #[derive(Serialize, Deserialize)] #[serde(rename_all = "kebab-case")] -- 2.47.3