public inbox for pdm-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Lukas Wagner <l.wagner@proxmox.com>
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	[thread overview]
Message-ID: <20260129134418.307552-2-l.wagner@proxmox.com> (raw)
In-Reply-To: <20260129134418.307552-1-l.wagner@proxmox.com>

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 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<Arc<dyn Any + Send + Sync>>,
 }
 
 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<dyn Any + Send + Sync>) -> 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<SocketAddr> {
         self.client_ip
     }
+
+    fn application_context(&self) -> Option<Arc<dyn Any + Send + Sync>> {
+        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<String> {
         self.auth_id.clone()
     }
+
+    fn application_context(&self) -> Option<Arc<dyn Any + Send + Sync>> {
+        // 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<std::net::SocketAddr> {
         None // dummy no-op implementation, as most environments don't need this
     }
+
+    /// Return application context that was previously injected.
+    fn application_context(&self) -> Option<Arc<dyn Any + Send + Sync>>;
 }
 
 /// Environment Type
-- 
2.47.3





  reply	other threads:[~2026-01-29 13:44 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-29 13:44 [RFC datacenter-manager/proxmox 0/7] inject application context via rpcenv for easier integration testing Lukas Wagner
2026-01-29 13:44 ` Lukas Wagner [this message]
2026-01-29 13:44 ` [RFC datacenter-manager 1/6] connection: store client factory in an Arc and add public getter Lukas Wagner
2026-01-29 13:44 ` [RFC datacenter-manager 2/6] parallel fetcher: allow to use custom client factory Lukas Wagner
2026-01-29 13:44 ` [RFC datacenter-manager 3/6] introduce PdmApplication struct and inject it during API server startup Lukas Wagner
2026-01-29 13:44 ` [RFC datacenter-manager 4/6] remote updates: use PdmApplication object to derive paths, permissions and client factory Lukas Wagner
2026-01-29 13:44 ` [RFC datacenter-manager 5/6] tests: add captured responses for integration tests Lukas Wagner
2026-01-29 13:44 ` [RFC datacenter-manager 6/6] tests: add basic integration tests for the remote updates API Lukas Wagner
2026-02-03 11:02 ` [RFC datacenter-manager/proxmox 0/7] inject application context via rpcenv for easier integration testing Robert Obkircher

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260129134418.307552-2-l.wagner@proxmox.com \
    --to=l.wagner@proxmox.com \
    --cc=pdm-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal