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 41B141FF0C0 for ; Wed, 18 Nov 2026 10:47:20 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 7CF31215E9; Wed, 18 Nov 2026 10:44:55 +0100 (CET) From: Lukas Wagner To: pve-devel@lists.proxmox.com Subject: [PATCH proxmox v2 25/63] notify: context: parse builtin config only once Date: Wed, 18 Nov 2026 10:43:09 +0100 Message-ID: <20261118094348.273646-26-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: 1794995038028 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: ZDTPONAVY4VD3PQXGLXEEEMK5DJ6EECO X-Message-ID-Hash: ZDTPONAVY4VD3PQXGLXEEEMK5DJ6EECO 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: The builtin config does not change during runtime, thus it makes sense to change the signature of the context trait to let the `default_config` method return a &'static SectionConfigData instead of &'static str. Signed-off-by: Lukas Wagner --- proxmox-notify/src/context/mod.rs | 5 ++++- proxmox-notify/src/context/pbs.rs | 11 +++++++++-- proxmox-notify/src/context/pve.rs | 12 ++++++++++-- proxmox-notify/src/context/test.rs | 10 ++++++++-- 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/proxmox-notify/src/context/mod.rs b/proxmox-notify/src/context/mod.rs index fd55dca14..edc147f4a 100644 --- a/proxmox-notify/src/context/mod.rs +++ b/proxmox-notify/src/context/mod.rs @@ -2,6 +2,9 @@ use std::fmt::{Debug, Display}; use std::ops::Deref; use std::sync::Arc; +use proxmox_section_config::typed::SectionConfigData; + +use crate::config::ConfigEntity; use crate::error::BoxedError; #[cfg(any(feature = "pve-context", feature = "pbs-context"))] @@ -51,7 +54,7 @@ pub trait ContextImpl: Send + Sync + Debug { /// Proxy configuration for the current node fn http_proxy_config(&self) -> Option; /// Return default config for built-in targets/matchers. - fn default_config(&self) -> &'static str; + fn default_config(&self) -> &'static SectionConfigData; /// Return the path of `filename` from `source` and a certain (optional) `namespace` fn lookup_template( &self, diff --git a/proxmox-notify/src/context/pbs.rs b/proxmox-notify/src/context/pbs.rs index f16e9ebdd..b76412ad1 100644 --- a/proxmox-notify/src/context/pbs.rs +++ b/proxmox-notify/src/context/pbs.rs @@ -1,11 +1,14 @@ use std::path::Path; +use std::sync::OnceLock; +use proxmox_section_config::typed::{ApiSectionDataEntry, SectionConfigData}; use serde::Deserialize; use tracing::error; use proxmox_schema::{ObjectSchema, Schema, StringSchema}; use proxmox_section_config::{SectionConfig, SectionConfigPlugin}; +use crate::config::ConfigEntity; use crate::context::{ContextImpl, TemplateSource, common}; use crate::error::BoxedError; @@ -101,8 +104,12 @@ impl ContextImpl for PBSContext { content.and_then(|content| common::lookup_datacenter_config_key(&content, "http-proxy")) } - fn default_config(&self) -> &'static str { - DEFAULT_CONFIG + fn default_config(&self) -> &'static SectionConfigData { + static CONFIG: OnceLock> = OnceLock::new(); + CONFIG.get_or_init(|| { + ConfigEntity::parse_section_config("builtin-config", DEFAULT_CONFIG) + .expect("built-in notification config must be valid") + }) } fn lookup_template( diff --git a/proxmox-notify/src/context/pve.rs b/proxmox-notify/src/context/pve.rs index bcfa0edff..1a5d33ca1 100644 --- a/proxmox-notify/src/context/pve.rs +++ b/proxmox-notify/src/context/pve.rs @@ -1,5 +1,9 @@ use std::path::Path; +use std::sync::OnceLock; +use proxmox_section_config::typed::{ApiSectionDataEntry, SectionConfigData}; + +use crate::config::ConfigEntity; use crate::context::{ContextImpl, TemplateSource, common}; use crate::error::BoxedError; @@ -51,8 +55,12 @@ impl ContextImpl for PVEContext { content.and_then(|content| common::lookup_datacenter_config_key(&content, "http_proxy")) } - fn default_config(&self) -> &'static str { - DEFAULT_CONFIG + fn default_config(&self) -> &'static SectionConfigData { + static CONFIG: OnceLock> = OnceLock::new(); + CONFIG.get_or_init(|| { + ConfigEntity::parse_section_config("builtin-config", DEFAULT_CONFIG) + .expect("built-in notification config must be valid") + }) } fn lookup_template( diff --git a/proxmox-notify/src/context/test.rs b/proxmox-notify/src/context/test.rs index 8296dbf62..2e230464b 100644 --- a/proxmox-notify/src/context/test.rs +++ b/proxmox-notify/src/context/test.rs @@ -1,4 +1,9 @@ +use std::sync::OnceLock; + +use proxmox_section_config::typed::SectionConfigData; + use crate::Context; +use crate::config::ConfigEntity; use crate::context::ContextImpl; use crate::error::BoxedError; @@ -30,8 +35,9 @@ impl ContextImpl for TestContext { None } - fn default_config(&self) -> &'static str { - "" + fn default_config(&self) -> &'static SectionConfigData { + static CONFIG: OnceLock> = OnceLock::new(); + CONFIG.get_or_init(SectionConfigData::default) } fn lookup_template( -- 2.47.3