From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id EBDE91FF13F for ; Thu, 29 Jan 2026 14:44:06 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id A5DE453D5; Thu, 29 Jan 2026 14:44:31 +0100 (CET) From: Lukas Wagner To: pdm-devel@lists.proxmox.com Subject: [RFC proxmox 1/1] router: rpc environment: allow to provide a application-specific context handle via rpcenv Date: Thu, 29 Jan 2026 14:44:12 +0100 Message-ID: <20260129134418.307552-2-l.wagner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260129134418.307552-1-l.wagner@proxmox.com> References: <20260129134418.307552-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: 1769694199560 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.036 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. 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: RCHYE2WLJGEXRZCNGCPTP4DCFHXGTLWE X-Message-ID-Hash: RCHYE2WLJGEXRZCNGCPTP4DCFHXGTLWE 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 Datacenter Manager development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Signed-off-by: Lukas Wagner --- proxmox-rest-server/src/api_config.rs | 10 ++++++++++ proxmox-rest-server/src/environment.rs | 6 +++++- proxmox-router/src/cli/environment.rs | 6 ++++++ proxmox-router/src/rpc_environment.rs | 5 ++++- 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/proxmox-rest-server/src/api_config.rs b/proxmox-rest-server/src/api_config.rs index 87d6566c..faaec2d3 100644 --- a/proxmox-rest-server/src/api_config.rs +++ b/proxmox-rest-server/src/api_config.rs @@ -1,3 +1,4 @@ +use std::any::Any; use std::collections::HashMap; use std::future::Future; use std::io; @@ -39,6 +40,8 @@ pub struct ApiConfig { #[cfg(feature = "templates")] templates: templates::Templates, + + pub(crate) context: Option>, } impl ApiConfig { @@ -66,6 +69,7 @@ impl ApiConfig { index_handler: None, privileged_addr: None, auth_cookie_name: None, + context: None, #[cfg(feature = "templates")] templates: templates::Templates::with_escape_fn(), @@ -111,6 +115,12 @@ impl ApiConfig { self.index_handler(IndexHandler::from_fn(func)) } + /// Inject application context that later be retrieved via `[RpcEnvironment::application_context()]`. + pub fn with_application_context(mut self, context: Arc) -> Self { + self.context = Some(context); + self + } + pub(crate) async fn get_index( &self, rest_env: RestEnvironment, diff --git a/proxmox-rest-server/src/environment.rs b/proxmox-rest-server/src/environment.rs index c349c324..636bdca2 100644 --- a/proxmox-rest-server/src/environment.rs +++ b/proxmox-rest-server/src/environment.rs @@ -1,5 +1,5 @@ -use std::net::SocketAddr; use std::sync::Arc; +use std::{any::Any, net::SocketAddr}; use serde_json::{json, Value}; @@ -89,4 +89,8 @@ impl RpcEnvironment for RestEnvironment { fn get_client_ip(&self) -> Option { self.client_ip } + + fn application_context(&self) -> Option> { + self.api_config().context.as_ref().map(Arc::clone) + } } diff --git a/proxmox-router/src/cli/environment.rs b/proxmox-router/src/cli/environment.rs index 3d3dec19..498eedc2 100644 --- a/proxmox-router/src/cli/environment.rs +++ b/proxmox-router/src/cli/environment.rs @@ -1,5 +1,6 @@ use std::any::{Any, TypeId}; use std::collections::HashMap; +use std::sync::Arc; use serde_json::Value; @@ -81,4 +82,9 @@ impl RpcEnvironment for CliEnvironment { fn get_auth_id(&self) -> Option { self.auth_id.clone() } + + fn application_context(&self) -> Option> { + // FIXME: set up context for cli env as well. + None + } } diff --git a/proxmox-router/src/rpc_environment.rs b/proxmox-router/src/rpc_environment.rs index 8ce2d99d..37140b91 100644 --- a/proxmox-router/src/rpc_environment.rs +++ b/proxmox-router/src/rpc_environment.rs @@ -1,4 +1,4 @@ -use std::any::Any; +use std::{any::Any, sync::Arc}; use serde_json::Value; @@ -45,6 +45,9 @@ pub trait RpcEnvironment: Any + AsAny + Send { fn get_client_ip(&self) -> Option { None // dummy no-op implementation, as most environments don't need this } + + /// Return application context that was previously injected. + fn application_context(&self) -> Option>; } /// Environment Type -- 2.47.3