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 426E11FF0C0 for ; Wed, 18 Nov 2026 10:47:56 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 611BA21A14; Wed, 18 Nov 2026 10:44:57 +0100 (CET) From: Lukas Wagner To: pve-devel@lists.proxmox.com Subject: [PATCH proxmox v2 22/63] notify: implement PartialEq for all Config types Date: Wed, 18 Nov 2026 10:43:06 +0100 Message-ID: <20261118094348.273646-23-l.wagner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261118094348.273646-1-l.wagner@proxmox.com> References: <20261118094348.273646-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: 1794995037632 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.193 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) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust 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: G46BKM5IWOC5AOH352XCBHBMIGX2Q2MM X-Message-ID-Hash: G46BKM5IWOC5AOH352XCBHBMIGX2Q2MM 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 VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Signed-off-by: Lukas Wagner --- proxmox-notify/src/api_types/gotify.rs | 2 +- .../src/api_types/matcher/calendar.rs | 11 ++++++-- proxmox-notify/src/api_types/matcher/field.rs | 25 ++++++++++++++++++- proxmox-notify/src/api_types/matcher/mod.rs | 4 +-- .../src/api_types/matcher/severity.rs | 4 +-- proxmox-notify/src/api_types/sendmail.rs | 2 +- proxmox-notify/src/api_types/smtp.rs | 4 +-- proxmox-notify/src/api_types/webhook.rs | 4 +-- 8 files changed, 43 insertions(+), 13 deletions(-) diff --git a/proxmox-notify/src/api_types/gotify.rs b/proxmox-notify/src/api_types/gotify.rs index 334920145..f74777472 100644 --- a/proxmox-notify/src/api_types/gotify.rs +++ b/proxmox-notify/src/api_types/gotify.rs @@ -19,7 +19,7 @@ pub const GOTIFY_TYPENAME: &str = "gotify"; }, } )] -#[derive(Serialize, Deserialize, Updater, Default)] +#[derive(Clone, Debug, Serialize, Deserialize, Updater, Default, PartialEq)] #[serde(rename_all = "kebab-case")] /// Config for Gotify notification endpoints pub struct GotifyConfig { diff --git a/proxmox-notify/src/api_types/matcher/calendar.rs b/proxmox-notify/src/api_types/matcher/calendar.rs index a0640b49a..65fd9bb4b 100644 --- a/proxmox-notify/src/api_types/matcher/calendar.rs +++ b/proxmox-notify/src/api_types/matcher/calendar.rs @@ -45,11 +45,18 @@ impl DailyDurationWrapper { } } +impl PartialEq for DailyDurationWrapper { + fn eq(&self, other: &Self) -> bool { + // `daily_duration` is derived from `schedule`, so comparing the latter suffices. + self.schedule == other.schedule + } +} + proxmox_serde::forward_deserialize_to_from_str!(DailyDurationWrapper); proxmox_serde::forward_serialize_to_display!(DailyDurationWrapper); /// Match timestamp of the notification. -#[derive(Clone, Debug, Serialize, Deserialize)] +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] #[serde(rename_all = "kebab-case")] pub struct CalendarMatcher { schedule: DailyDurationWrapper, @@ -90,7 +97,7 @@ pub mod inline { /// /// This is a wrapper that serializes into an inline format that can be used /// in a section config key-value pair. - #[derive(Clone, Debug)] + #[derive(Clone, Debug, PartialEq)] pub struct InlineCalendarMatcher(CalendarMatcher); impl MatchDirective for InlineCalendarMatcher { diff --git a/proxmox-notify/src/api_types/matcher/field.rs b/proxmox-notify/src/api_types/matcher/field.rs index b1ea25302..a00d46c3e 100644 --- a/proxmox-notify/src/api_types/matcher/field.rs +++ b/proxmox-notify/src/api_types/matcher/field.rs @@ -29,6 +29,29 @@ impl From for Expression { } } +// `Regex` does not implement `PartialEq`, so compare the regex patterns instead. +impl PartialEq for FieldMatcher { + fn eq(&self, other: &Self) -> bool { + match (self, other) { + ( + Self::Exact { field, values }, + Self::Exact { + field: other_field, + values: other_values, + }, + ) => field == other_field && values == other_values, + ( + Self::Regex { field, regex }, + Self::Regex { + field: other_field, + regex: other_regex, + }, + ) => field == other_field && regex.as_str() == other_regex.as_str(), + _ => false, + } + } +} + impl MatchDirective for FieldMatcher { fn matches(&self, notification: &Notification) -> Result { Ok(match self { @@ -99,7 +122,7 @@ pub mod inline { /// Check if the notification metadata fields match /// This is a wrapper that serializes into an inline format that can be used /// in a section config key-value pair. - #[derive(Clone, Debug)] + #[derive(Clone, Debug, PartialEq)] pub struct InlineFieldMatcher(FieldMatcher); impl MatchDirective for InlineFieldMatcher { diff --git a/proxmox-notify/src/api_types/matcher/mod.rs b/proxmox-notify/src/api_types/matcher/mod.rs index dd9a987f4..e10ae6986 100644 --- a/proxmox-notify/src/api_types/matcher/mod.rs +++ b/proxmox-notify/src/api_types/matcher/mod.rs @@ -23,7 +23,7 @@ pub const MATCHER_TYPENAME: &str = "matcher"; #[api] #[cfg(feature = "legacy-matchers")] -#[derive(Debug, Serialize, Deserialize, Default, Clone, Copy)] +#[derive(Debug, Serialize, Deserialize, Default, Clone, Copy, PartialEq)] #[serde(rename_all = "kebab-case")] /// The mode in which the results of matches are combined. pub enum MatchModeOperator { @@ -75,7 +75,7 @@ pub enum MatchModeOperator { optional: true, }, })] -#[derive(Clone, Debug, Serialize, Deserialize, Updater, Default)] +#[derive(Clone, Debug, Serialize, Deserialize, Updater, Default, PartialEq)] #[serde(rename_all = "kebab-case")] /// Config for notification matchers. pub struct MatcherConfig { diff --git a/proxmox-notify/src/api_types/matcher/severity.rs b/proxmox-notify/src/api_types/matcher/severity.rs index 2d68a46bb..ed0278888 100644 --- a/proxmox-notify/src/api_types/matcher/severity.rs +++ b/proxmox-notify/src/api_types/matcher/severity.rs @@ -6,7 +6,7 @@ use crate::{Error, Notification, Severity, api_types::expression::NotificationMa use super::MatchDirective; /// Match severity of the notification. -#[derive(Clone, Debug, Serialize, Deserialize)] +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] pub struct SeverityMatcher { pub(crate) severities: Vec, } @@ -44,7 +44,7 @@ pub mod inline { /// /// This is a wrapper that serializes into an inline format that can be used /// in a section config key-value pair. - #[derive(Clone, Debug)] + #[derive(Clone, Debug, PartialEq)] pub struct InlineSeverityMatcher(SeverityMatcher); /// Common trait implemented by all matching directives diff --git a/proxmox-notify/src/api_types/sendmail.rs b/proxmox-notify/src/api_types/sendmail.rs index bb843fbfa..fd7e457c2 100644 --- a/proxmox-notify/src/api_types/sendmail.rs +++ b/proxmox-notify/src/api_types/sendmail.rs @@ -33,7 +33,7 @@ pub const SENDMAIL_TYPENAME: &str = "sendmail"; }, }, )] -#[derive(Debug, Serialize, Deserialize, Updater, Default)] +#[derive(Clone, Debug, Serialize, Deserialize, Updater, Default, PartialEq)] #[serde(rename_all = "kebab-case")] /// Config for Sendmail notification endpoints pub struct SendmailConfig { diff --git a/proxmox-notify/src/api_types/smtp.rs b/proxmox-notify/src/api_types/smtp.rs index 5cebbf8ad..e7dd37ef3 100644 --- a/proxmox-notify/src/api_types/smtp.rs +++ b/proxmox-notify/src/api_types/smtp.rs @@ -9,7 +9,7 @@ use super::schema::{EMAIL_SCHEMA, ENTITY_NAME_SCHEMA, USER_SCHEMA}; pub const SMTP_TYPENAME: &str = "smtp"; #[api] -#[derive(Debug, Serialize, Deserialize, Default, Clone, Copy)] +#[derive(Debug, Serialize, Deserialize, Default, Clone, Copy, PartialEq)] #[serde(rename_all = "kebab-case")] /// Connection security pub enum SmtpMode { @@ -48,7 +48,7 @@ pub enum SmtpMode { }, }, )] -#[derive(Debug, Serialize, Deserialize, Updater, Default)] +#[derive(Clone, Debug, Serialize, Deserialize, Updater, Default, PartialEq)] #[serde(rename_all = "kebab-case")] /// Config for SMTP notification endpoints pub struct SmtpConfig { diff --git a/proxmox-notify/src/api_types/webhook.rs b/proxmox-notify/src/api_types/webhook.rs index 4a2430cec..68c2f381a 100644 --- a/proxmox-notify/src/api_types/webhook.rs +++ b/proxmox-notify/src/api_types/webhook.rs @@ -73,7 +73,7 @@ impl From for &str { }, } )] -#[derive(Serialize, Deserialize, Updater, Default, Clone)] +#[derive(Serialize, Deserialize, Updater, Default, Clone, PartialEq)] #[serde(rename_all = "kebab-case")] /// Config for Webhook notification endpoints pub struct WebhookConfig { @@ -165,7 +165,7 @@ pub enum DeleteableWebhookProperty { } #[api] -#[derive(Serialize, Deserialize, Debug, Default, Clone)] +#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq)] /// Datatype used to represent key-value pairs, the value /// being encoded in base64. pub struct KeyAndBase64Val { -- 2.47.3