From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 95B071FF0C0 for ; Wed, 18 Nov 2026 10:47:28 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id E504E2199E; Wed, 18 Nov 2026 10:44:55 +0100 (CET) From: Lukas Wagner To: pve-devel@lists.proxmox.com Subject: [PATCH proxmox v2 21/63] notify: config: pass builtins explicitly when parsing section config Date: Wed, 18 Nov 2026 10:43:05 +0100 Message-ID: <20261118094348.273646-22-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: 1794995037501 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.194 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: ILG6CILBJVAYE23YGMMCCKYEINGSC7MA X-Message-ID-Hash: ILG6CILBJVAYE23YGMMCCKYEINGSC7MA 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: Instead of passing &Context just for calling default_config, we pass the section config data directly as an option. This makes the code a bit less awkward in tests, where we don't care about builtins. Signed-off-by: Lukas Wagner --- proxmox-notify/src/api/matcher.rs | 12 ++---- proxmox-notify/src/api/mod.rs | 5 +-- proxmox-notify/src/config.rs | 64 +++++++++++++++---------------- 3 files changed, 36 insertions(+), 45 deletions(-) diff --git a/proxmox-notify/src/api/matcher.rs b/proxmox-notify/src/api/matcher.rs index 65ceb1dc7..f8bc06a9a 100644 --- a/proxmox-notify/src/api/matcher.rs +++ b/proxmox-notify/src/api/matcher.rs @@ -210,17 +210,14 @@ mod tests { use super::*; - use crate::{api_types::expression::NotificationMatcher, context::test::test_context}; + use crate::api_types::expression::NotificationMatcher; fn empty_config() -> Config { - let context = test_context(); - Config::parse_section_config(&context, "", "").unwrap() + Config::parse_section_config("", "", None).unwrap() } fn config_with_two_matchers() -> Config { - let context = test_context(); Config::parse_section_config( - &context, " sendmail: foo mailto test@example.com @@ -230,6 +227,7 @@ matcher: matcher1 matcher: matcher2 ", "", + None, ) .unwrap() } @@ -502,9 +500,7 @@ matcher: matcher2 // The normalized expression should stay the same after // a read/write cycle of the config let (raw_config, raw_private_config) = config.to_section_config().unwrap(); - let context = test_context(); - let config = - Config::parse_section_config(&context, &raw_config, &raw_private_config).unwrap(); + let config = Config::parse_section_config(&raw_config, &raw_private_config, None).unwrap(); let matcher = get_matcher(&config, "matcher1")?; assert_eq!(matcher.expression, Some(stored)); diff --git a/proxmox-notify/src/api/mod.rs b/proxmox-notify/src/api/mod.rs index b70c32df8..43e448bc9 100644 --- a/proxmox-notify/src/api/mod.rs +++ b/proxmox-notify/src/api/mod.rs @@ -221,12 +221,11 @@ fn remove_private_config_entry(config: &mut Config, name: &str) -> Result<(), Ht #[cfg(test)] mod test_helpers { - use crate::{Config, context::test}; + use crate::Config; #[allow(unused)] pub fn empty_config() -> Config { - let context = test::test_context(); - Config::parse_section_config(&context, "", "").unwrap() + Config::parse_section_config("", "", None).unwrap() } } diff --git a/proxmox-notify/src/config.rs b/proxmox-notify/src/config.rs index 8c7c84cc8..f59da9bdd 100644 --- a/proxmox-notify/src/config.rs +++ b/proxmox-notify/src/config.rs @@ -6,12 +6,12 @@ use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlug use serde_json::Value; use tracing::error; +use crate::Error; use crate::api_types::{ BACKEND_NAME_SCHEMA, GOTIFY_TYPENAME, GotifyConfig, GotifyPrivateConfig, MATCHER_TYPENAME, MatcherConfig, SENDMAIL_TYPENAME, SMTP_TYPENAME, SendmailConfig, SmtpConfig, SmtpPrivateConfig, WEBHOOK_TYPENAME, WebhookConfig, WebhookPrivateConfig, }; -use crate::{Context, Error}; /// Section config schema for the public config file. pub fn config_parser() -> &'static SectionConfig { @@ -139,51 +139,47 @@ pub struct Config { impl Config { /// Parse notification configuration from section config format. pub fn parse_section_config( - context: &Context, raw_config: &str, raw_private_config: &str, + builtin_config: Option<&SectionConfigData>, ) -> Result { let (mut config, digest) = parse_config(raw_config)?; let (private_config, _) = parse_private_config(raw_private_config)?; - let default_config = context.default_config(); + if let Some(builtin_config) = builtin_config { + for (key, (builtin_typename, builtin_value)) in &builtin_config.sections { + if let Some((typename, value)) = config.sections.get_mut(key) { + if builtin_typename == typename && value == builtin_value { + // Entry is built-in and the config entry section in notifications.cfg + // is exactly the same. + if let Some(obj) = value.as_object_mut() { + obj.insert("origin".to_string(), Value::String("builtin".into())); + } else { + error!("section config entry is not an object. This should not happen"); + } + } else { + // Entry is built-in, but it has been modified by the user. + if let Some(obj) = value.as_object_mut() { + obj.insert( + "origin".to_string(), + Value::String("modified-builtin".into()), + ); + } else { + error!("section config entry is not an object. This should not happen"); + } + } + } else { + let mut val = builtin_value.clone(); - let builtin_config = config_parser() - .parse("", default_config) - .map_err(|err| Error::ConfigDeserialization(err.into()))?; - - for (key, (builtin_typename, builtin_value)) in &builtin_config.sections { - if let Some((typename, value)) = config.sections.get_mut(key) { - if builtin_typename == typename && value == builtin_value { - // Entry is built-in and the config entry section in notifications.cfg - // is exactly the same. - if let Some(obj) = value.as_object_mut() { + if let Some(obj) = val.as_object_mut() { obj.insert("origin".to_string(), Value::String("builtin".into())); } else { error!("section config entry is not an object. This should not happen"); } - } else { - // Entry is built-in, but it has been modified by the user. - if let Some(obj) = value.as_object_mut() { - obj.insert( - "origin".to_string(), - Value::String("modified-builtin".into()), - ); - } else { - error!("section config entry is not an object. This should not happen"); - } + config + .set_data(key, builtin_typename, val) + .map_err(|err| Error::ConfigDeserialization(err.into()))?; } - } else { - let mut val = builtin_value.clone(); - - if let Some(obj) = val.as_object_mut() { - obj.insert("origin".to_string(), Value::String("builtin".into())); - } else { - error!("section config entry is not an object. This should not happen"); - } - config - .set_data(key, builtin_typename, val) - .map_err(|err| Error::ConfigDeserialization(err.into()))?; } } -- 2.47.3