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 5AB201FF0E6 for ; Fri, 24 Jul 2026 12:02:20 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 9BC40214CD; Fri, 24 Jul 2026 12:02:19 +0200 (CEST) Date: Fri, 24 Jul 2026 12:01:45 +0200 From: Wolfgang Bumiller To: Arthur Bied-Charreton Subject: Re: [PATCH proxmox 12/29] notify: api: support new expression parameter Message-ID: <2wrk6fkyqsabakds2upba63dflutmijik32rsnm7qjnuil3oep@fhrprifkbj5x> References: <20260709115716.299836-1-l.wagner@proxmox.com> <20260709115716.299836-13-l.wagner@proxmox.com> <4m5kl2paeakjnxb2jvh4hbnbvulf54mjwcixweezbmiup7vd6f@rju5nwedy25a> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4m5kl2paeakjnxb2jvh4hbnbvulf54mjwcixweezbmiup7vd6f@rju5nwedy25a> X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1784887274899 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.223 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_LOW -0.7 Sender listed at https://www.dnswl.org/, low 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: 5VWV7TGWEWNEYDQEN7AYVK2JITWNYIUI X-Message-ID-Hash: 5VWV7TGWEWNEYDQEN7AYVK2JITWNYIUI X-MailFrom: w.bumiller@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 CC: Lukas Wagner , pbs-devel@lists.proxmox.com, pve-devel@lists.proxmox.com X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On Fri, Jul 24, 2026 at 08:46:19AM +0200, Arthur Bied-Charreton wrote: > On Thu, Jul 09, 2026 at 01:56:59PM +0200, Lukas Wagner wrote: > > Add support for the new 'expression' parameter to the add_matcher and > > updater_matcher API functions. Also add some validation that won't allow > > to create a configuration with both old properties and new the > > 'expression'. > > > > Signed-off-by: Lukas Wagner > one comment inline > > --- > > proxmox-notify/src/api/matcher.rs | 119 ++++++++++++++++++++++++++++++ > > proxmox-notify/src/matcher/mod.rs | 43 ++++++++++- > > 2 files changed, 161 insertions(+), 1 deletion(-) > > > [...] > > diff --git a/proxmox-notify/src/matcher/mod.rs b/proxmox-notify/src/matcher/mod.rs > > index 429692a4..60725e00 100644 > > --- a/proxmox-notify/src/matcher/mod.rs > > +++ b/proxmox-notify/src/matcher/mod.rs > > @@ -76,7 +76,7 @@ pub enum MatchModeOperator { > > optional: true, > > }, > > })] > > -#[derive(Debug, Serialize, Deserialize, Updater, Default)] > > +#[derive(Clone, Debug, Serialize, Deserialize, Updater, Default)] > > #[serde(rename_all = "kebab-case")] > > /// Config for notification matchers. > > pub struct MatcherConfig { > > @@ -216,6 +216,45 @@ impl MatcherConfig { > > ); > > } > > } > > + > > + /// Ensure the validity of this matcher. > > + pub(crate) fn ensure_valid(&self) -> Result<(), Error> { > > + if let Some(expression) = &self.expression { > > + if self.invert_match.is_some() { > > + return Err(Error::Generic( > > + "'expression' and 'invert-match' are mutually exclusive properties".into(), > > + )); > > + } > > + if self.mode.is_some() { > > + return Err(Error::Generic( > > + "'expression' and 'mode' are mutually exclusive properties".into(), > > + )); > > + } > > + if !self.match_field.is_empty() { > > + return Err(Error::Generic( > > + "'expression' and 'match-field' are mutually exclusive properties".into(), > > + )); > > + } > > + if !self.match_severity.is_empty() { > > + return Err(Error::Generic( > > + "'expression' and 'match-severity' are mutually exclusive properties".into(), > > + )); > > + } > > + if !self.match_calendar.is_empty() { > > + return Err(Error::Generic( > > + "'expression' and 'match-calendar' are mutually exclusive properties".into(), > > + )); > > + } Would be nicer to collect all the above into a string and then have a single error "'expression' is mutually exclusive with: {list}". > > + > > + if let Err(err) = serde_json::from_str::>(expression) { > > + return Err(Error::Generic(format!( > > + "'expression' is not valid: {err:#}" > > + ))); > > + } > > + } > > + > i think this is missing a check for the length of FieldMatcher::Exact > fields and SeverityMatcher severities. afaict them being empty is pretty > much always an error? if a user wants a matcher that never matches there > is the inverted "Always match" option, which is made for that. > > this is preexisting, the old backend also did not check it, but i think > it would be a good time to add that :) Depends on what "valid" means - that they don't crash, or that they do what the user wants them to do, in which case I'd ask what the empty field is supposed to do anyway ;-) Code wise I doubt fixing this is worth it. Do we expect users to run into this? Note that for the inline version, they have to match a regex which uses `SAFE_ID_REGEX_STR` for the field name, which does not match an empty string, so that fails to parse. Given that, we *could* consider this the job of `FieldMatcher`'s deserialize implementation. Could redirect the field deserialization via `#[serde(deserialize_with = "foo")]`. For the severity matchers, neither `FromStr` nor the new version do any checking. > > + Ok(()) > > + } > > } > > > > #[api] > > @@ -237,6 +276,8 @@ pub enum DeleteableMatcherProperty { > > MatchSeverity, > > /// Delete `mode` > > Mode, > > + /// Delete `expression` > > + Expression, > > /// Delete `target` > > Target, > > } > > -- > > 2.47.3