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 E770E1FF0C0 for ; Wed, 18 Nov 2026 10:48:11 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 5124121A5B; Wed, 18 Nov 2026 10:44:58 +0100 (CET) From: Lukas Wagner To: pve-devel@lists.proxmox.com Subject: [PATCH proxmox v2 26/63] notify: context: parse proxy config in trait impl, not at the callsite Date: Wed, 18 Nov 2026 10:43:10 +0100 Message-ID: <20261118094348.273646-27-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: 1794995038162 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: FIVID356K7OFGCGJTTT2IOO5OSEAEB7Y X-Message-ID-Hash: FIVID356K7OFGCGJTTT2IOO5OSEAEB7Y 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: This makes it easier to at some point introduce different proxy schemes for http vs. https URLs, and it also decouples proxmox-notify from the concrete string format used to configure proxies. The trait method was renamed to `proxy_config` to preemptively avoid any confusion if we ever introduce a differentiation between http and https proxies. Signed-off-by: Lukas Wagner --- proxmox-notify/Cargo.toml | 5 ++++- proxmox-notify/src/context/mod.rs | 3 ++- proxmox-notify/src/context/pbs.rs | 11 ++++++++--- proxmox-notify/src/context/pve.rs | 9 +++++++-- proxmox-notify/src/context/test.rs | 5 +++-- proxmox-notify/src/endpoints/gotify.rs | 6 ++---- proxmox-notify/src/endpoints/webhook.rs | 6 ++---- 7 files changed, 28 insertions(+), 17 deletions(-) diff --git a/proxmox-notify/Cargo.toml b/proxmox-notify/Cargo.toml index 5f7ea3176..611aebba6 100644 --- a/proxmox-notify/Cargo.toml +++ b/proxmox-notify/Cargo.toml @@ -28,7 +28,7 @@ thiserror.workspace = true proxmox-api-macro = { workspace = true, optional = true } proxmox-base64 = { workspace = true, optional = true } proxmox-config-digest = { workspace = true, features = ["openssl"], optional = true } -proxmox-http = { workspace = true, features = ["client-sync"], optional = true } +proxmox-http = { workspace = true, optional = true } proxmox-http-error = { workspace = true, optional = true } proxmox-human-byte = { workspace = true, optional = true } proxmox-match-expression = { workspace = true, optional = true } @@ -48,6 +48,8 @@ default = ["send-impl", "api-types"] api-impl = [ "api-types", "dep:proxmox-config-digest", + "dep:proxmox-http", + "proxmox-http/http-helpers", "dep:proxmox-http-error", "dep:proxmox-section-config", ] @@ -67,6 +69,7 @@ send-impl = [ "dep:percent-encoding", "dep:proxmox-base64", "dep:proxmox-http", + "proxmox-http/client-sync", "dep:proxmox-human-byte", "dep:proxmox-section-config", "dep:proxmox-sendmail", diff --git a/proxmox-notify/src/context/mod.rs b/proxmox-notify/src/context/mod.rs index edc147f4a..c31e108fd 100644 --- a/proxmox-notify/src/context/mod.rs +++ b/proxmox-notify/src/context/mod.rs @@ -2,6 +2,7 @@ use std::fmt::{Debug, Display}; use std::ops::Deref; use std::sync::Arc; +use proxmox_http::ProxyConfig; use proxmox_section_config::typed::SectionConfigData; use crate::config::ConfigEntity; @@ -52,7 +53,7 @@ pub trait ContextImpl: Send + Sync + Debug { /// Default from address for sendmail-based targets fn default_sendmail_from(&self) -> String; /// Proxy configuration for the current node - fn http_proxy_config(&self) -> Option; + fn proxy_config(&self) -> Result, BoxedError>; /// Return default config for built-in targets/matchers. fn default_config(&self) -> &'static SectionConfigData; /// Return the path of `filename` from `source` and a certain (optional) `namespace` diff --git a/proxmox-notify/src/context/pbs.rs b/proxmox-notify/src/context/pbs.rs index b76412ad1..7d3c51677 100644 --- a/proxmox-notify/src/context/pbs.rs +++ b/proxmox-notify/src/context/pbs.rs @@ -1,11 +1,12 @@ use std::path::Path; use std::sync::OnceLock; -use proxmox_section_config::typed::{ApiSectionDataEntry, SectionConfigData}; use serde::Deserialize; use tracing::error; +use proxmox_http::ProxyConfig; use proxmox_schema::{ObjectSchema, Schema, StringSchema}; +use proxmox_section_config::typed::{ApiSectionDataEntry, SectionConfigData}; use proxmox_section_config::{SectionConfig, SectionConfigPlugin}; use crate::config::ConfigEntity; @@ -99,9 +100,13 @@ impl ContextImpl for PBSContext { .unwrap_or_else(|| String::from("root")) } - fn http_proxy_config(&self) -> Option { + fn proxy_config(&self) -> Result, BoxedError> { let content = common::attempt_file_read(PBS_NODE_CFG_FILENAME); - content.and_then(|content| common::lookup_datacenter_config_key(&content, "http-proxy")) + content + .and_then(|content| common::lookup_datacenter_config_key(&content, "http-proxy")) + .map(|url| ProxyConfig::parse_proxy_url(&url)) + .transpose() + .map_err(Into::into) } fn default_config(&self) -> &'static SectionConfigData { diff --git a/proxmox-notify/src/context/pve.rs b/proxmox-notify/src/context/pve.rs index 1a5d33ca1..a020b5cb4 100644 --- a/proxmox-notify/src/context/pve.rs +++ b/proxmox-notify/src/context/pve.rs @@ -1,6 +1,7 @@ use std::path::Path; use std::sync::OnceLock; +use proxmox_http::ProxyConfig; use proxmox_section_config::typed::{ApiSectionDataEntry, SectionConfigData}; use crate::config::ConfigEntity; @@ -50,9 +51,13 @@ impl ContextImpl for PVEContext { .unwrap_or_else(|| String::from("root")) } - fn http_proxy_config(&self) -> Option { + fn proxy_config(&self) -> Result, BoxedError> { let content = common::attempt_file_read("/etc/pve/datacenter.cfg"); - content.and_then(|content| common::lookup_datacenter_config_key(&content, "http_proxy")) + content + .and_then(|content| common::lookup_datacenter_config_key(&content, "http_proxy")) + .map(|url| ProxyConfig::parse_proxy_url(&url)) + .transpose() + .map_err(Into::into) } fn default_config(&self) -> &'static SectionConfigData { diff --git a/proxmox-notify/src/context/test.rs b/proxmox-notify/src/context/test.rs index 2e230464b..6061e8c4d 100644 --- a/proxmox-notify/src/context/test.rs +++ b/proxmox-notify/src/context/test.rs @@ -1,5 +1,6 @@ use std::sync::OnceLock; +use proxmox_http::ProxyConfig; use proxmox_section_config::typed::SectionConfigData; use crate::Context; @@ -31,8 +32,8 @@ impl ContextImpl for TestContext { "root".into() } - fn http_proxy_config(&self) -> Option { - None + fn proxy_config(&self) -> Result, BoxedError> { + Ok(None) } fn default_config(&self) -> &'static SectionConfigData { diff --git a/proxmox-notify/src/endpoints/gotify.rs b/proxmox-notify/src/endpoints/gotify.rs index 5341f822f..cf7d4cc68 100644 --- a/proxmox-notify/src/endpoints/gotify.rs +++ b/proxmox-notify/src/endpoints/gotify.rs @@ -4,7 +4,7 @@ use std::time::Duration; use serde_json::json; use proxmox_http::client::sync::Client; -use proxmox_http::{HttpClient, HttpOptions, ProxyConfig}; +use proxmox_http::{HttpClient, HttpOptions}; use crate::api_types::{GotifyConfig, GotifyPrivateConfig}; use crate::renderer::TemplateType; @@ -83,9 +83,7 @@ impl Endpoint for GotifyEndpoint { ]); let proxy_config = context - .http_proxy_config() - .map(|url| ProxyConfig::parse_proxy_url(&url)) - .transpose() + .proxy_config() .map_err(|err| Error::invalid_config_with_source("invalid proxy configuration", err))?; let options = HttpOptions { diff --git a/proxmox-notify/src/endpoints/webhook.rs b/proxmox-notify/src/endpoints/webhook.rs index 49ea29c1e..da2e189b4 100644 --- a/proxmox-notify/src/endpoints/webhook.rs +++ b/proxmox-notify/src/endpoints/webhook.rs @@ -18,7 +18,7 @@ use percent_encoding::AsciiSet; use serde_json::{Map, Value, json}; use proxmox_http::client::sync::Client; -use proxmox_http::{HttpClient, HttpOptions, ProxyConfig}; +use proxmox_http::{HttpClient, HttpOptions}; use crate::api_types::{HttpMethod, WebhookConfig, WebhookPrivateConfig}; use crate::renderer::TemplateType; @@ -61,9 +61,7 @@ impl Endpoint for WebhookEndpoint { impl WebhookEndpoint { fn create_client(&self, context: &Context) -> Result { let proxy_config = context - .http_proxy_config() - .map(|url| ProxyConfig::parse_proxy_url(&url)) - .transpose() + .proxy_config() .map_err(|err| Error::invalid_config_with_source("invalid proxy configuration", err))?; let options = HttpOptions { -- 2.47.3