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 EE4FC1FF0B7 for ; Fri, 13 Nov 2026 16:15:21 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id DD77621B89; Fri, 13 Nov 2026 16:10:11 +0100 (CET) From: Lukas Wagner To: pve-devel@lists.proxmox.com Subject: [PATCH proxmox 40/55] notify: context: add read_config Date: Fri, 13 Nov 2026 16:08:13 +0100 Message-ID: <20261113150828.756836-41-l.wagner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261113150828.756836-1-l.wagner@proxmox.com> References: <20261113150828.756836-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: 1794582528092 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.203 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: HG2DIOHU63CXLQZO4FP6TIUOG246LZYP X-Message-ID-Hash: HG2DIOHU63CXLQZO4FP6TIUOG246LZYP 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 worker needs the ability to read the notification configuration, which is implemented by adding a 'read_config' method to the ContextImpl trait. Signed-off-by: Lukas Wagner --- proxmox-notify/src/context/mod.rs | 4 ++++ proxmox-notify/src/context/pbs.rs | 19 +++++++++++++++++++ proxmox-notify/src/context/pve.rs | 17 +++++++++++++++++ proxmox-notify/src/context/test.rs | 21 ++++++++++++++++++--- 4 files changed, 58 insertions(+), 3 deletions(-) diff --git a/proxmox-notify/src/context/mod.rs b/proxmox-notify/src/context/mod.rs index c31e108fd..eb8011cf3 100644 --- a/proxmox-notify/src/context/mod.rs +++ b/proxmox-notify/src/context/mod.rs @@ -5,6 +5,7 @@ use std::sync::Arc; use proxmox_http::ProxyConfig; use proxmox_section_config::typed::SectionConfigData; +use crate::Config; use crate::config::ConfigEntity; use crate::error::BoxedError; @@ -63,6 +64,9 @@ pub trait ContextImpl: Send + Sync + Debug { namespace: Option<&str>, source: TemplateSource, ) -> Result, BoxedError>; + + /// Read notification config. + fn read_config(&self) -> Result; } /// Choose between the provided `vendor` template or its by the user optionally created `override` diff --git a/proxmox-notify/src/context/pbs.rs b/proxmox-notify/src/context/pbs.rs index 7d3c51677..046d37055 100644 --- a/proxmox-notify/src/context/pbs.rs +++ b/proxmox-notify/src/context/pbs.rs @@ -9,6 +9,7 @@ use proxmox_schema::{ObjectSchema, Schema, StringSchema}; use proxmox_section_config::typed::{ApiSectionDataEntry, SectionConfigData}; use proxmox_section_config::{SectionConfig, SectionConfigPlugin}; +use crate::Config; use crate::config::ConfigEntity; use crate::context::{ContextImpl, TemplateSource, common}; use crate::error::BoxedError; @@ -136,6 +137,24 @@ impl ContextImpl for PBSContext { Ok(template_string) } + + fn read_config(&self) -> Result { + let raw_config = + proxmox_sys::fs::file_read_optional_string("/etc/proxmox-backup/notifications.cfg")? + .unwrap_or_default(); + let raw_private_config = proxmox_sys::fs::file_read_optional_string( + "/etc/proxmox-backup/notifications-priv.cfg", + )? + .unwrap_or_default(); + + let config = Config::parse_section_config( + &raw_config, + &raw_private_config, + Some(self.default_config()), + )?; + + Ok(config) + } } #[cfg(test)] diff --git a/proxmox-notify/src/context/pve.rs b/proxmox-notify/src/context/pve.rs index a020b5cb4..f7d2ac13c 100644 --- a/proxmox-notify/src/context/pve.rs +++ b/proxmox-notify/src/context/pve.rs @@ -4,6 +4,7 @@ use std::sync::OnceLock; use proxmox_http::ProxyConfig; use proxmox_section_config::typed::{ApiSectionDataEntry, SectionConfigData}; +use crate::Config; use crate::config::ConfigEntity; use crate::context::{ContextImpl, TemplateSource, common}; use crate::error::BoxedError; @@ -87,6 +88,22 @@ impl ContextImpl for PVEContext { Ok(template_string) } + + fn read_config(&self) -> Result { + let raw_config = proxmox_sys::fs::file_read_optional_string("/etc/pve/notifications.cfg")? + .unwrap_or_default(); + let raw_private_config = + proxmox_sys::fs::file_read_optional_string("/etc/pve/priv/notifications.cfg")? + .unwrap_or_default(); + + let config = Config::parse_section_config( + &raw_config, + &raw_private_config, + Some(self.default_config()), + )?; + + Ok(config) + } } pub static PVE_CONTEXT: PVEContext = PVEContext; diff --git a/proxmox-notify/src/context/test.rs b/proxmox-notify/src/context/test.rs index 6061e8c4d..bc68b6e41 100644 --- a/proxmox-notify/src/context/test.rs +++ b/proxmox-notify/src/context/test.rs @@ -3,6 +3,7 @@ use std::sync::OnceLock; use proxmox_http::ProxyConfig; use proxmox_section_config::typed::SectionConfigData; +use crate::Config; use crate::Context; use crate::config::ConfigEntity; use crate::context::ContextImpl; @@ -10,8 +11,11 @@ use crate::error::BoxedError; use super::TemplateSource; -#[derive(Debug)] -pub(crate) struct TestContext; +#[derive(Debug, Default)] +pub(crate) struct TestContext { + /// Make [`ContextImpl::read_config`] fail, to test how callers handle an unreadable config. + pub(crate) fail_read_config: bool, +} impl ContextImpl for TestContext { fn lookup_email_for_user(&self, user: &str) -> Option { @@ -49,8 +53,19 @@ impl ContextImpl for TestContext { ) -> Result, BoxedError> { Ok(Some(String::new())) } + + fn read_config(&self) -> Result { + if self.fail_read_config { + return Err(Box::new(crate::Error::other( + "injected config read failure", + ))); + } + + // An empty config has no targets and no matchers. + Ok(Config::parse_section_config("", "", None)?) + } } pub(crate) fn test_context() -> Context { - Context::new(TestContext) + Context::new(TestContext::default()) } -- 2.47.3