all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Lukas Wagner <l.wagner@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [PATCH proxmox v3 02/21] rest-server: allow to inject shared state
Date: Thu, 27 Aug 2026 13:42:25 +0200	[thread overview]
Message-ID: <20260827114244.424784-3-l.wagner@proxmox.com> (raw)
In-Reply-To: <20260827114244.424784-1-l.wagner@proxmox.com>

Let users of ApiConfig register a shared state registry while setting
up the server and pass it on to API handlers via RestEnvironment.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 proxmox-rest-server/src/api_config.rs  | 14 +++++++++++++-
 proxmox-rest-server/src/environment.rs |  6 +++++-
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/proxmox-rest-server/src/api_config.rs b/proxmox-rest-server/src/api_config.rs
index 3543f8c4..2a8eec70 100644
--- a/proxmox-rest-server/src/api_config.rs
+++ b/proxmox-rest-server/src/api_config.rs
@@ -17,7 +17,7 @@ use proxmox_daemon::command_socket::CommandSocket;
 use proxmox_http::Body;
 use proxmox_log::{FileLogOptions, FileLogger};
 use proxmox_network_types::Cidr;
-use proxmox_router::{Router, RpcEnvironmentType, UserInformation};
+use proxmox_router::{Router, RpcEnvironmentType, SharedStateRegistry, UserInformation};
 use proxmox_sys::fs::{CreateOptions, create_path};
 
 use crate::RestEnvironment;
@@ -33,6 +33,8 @@ pub struct ApiConfig {
     handlers: Vec<Handler>,
     auth_handler: Option<AuthHandler>,
     index_handler: Option<IndexHandler>,
+    /// State that API handlers can request via a `#[state]` parameter.
+    pub(crate) shared_state: Option<SharedStateRegistry>,
     pub(crate) privileged_addr: Option<PrivilegedAddr>,
     // Name of the auth cookie that should be unset on 401 request. If `None` no cookie will be
     // removed.
@@ -92,6 +94,7 @@ impl ApiConfig {
             index_handler: None,
             privileged_addr: None,
             auth_cookie_name: None,
+            shared_state: None,
 
             real_ip_header,
             real_ip_allow_from: None,
@@ -366,6 +369,15 @@ impl ApiConfig {
             .push(Handler::unformatted_router(prefix, router));
         self
     }
+
+    /// Set the [`SharedStateRegistry`] from which API handlers get their `#[state]` parameters.
+    ///
+    /// All types a handler requests must be registered using
+    /// [`SharedStateRegistry::register`], otherwise a call to the API handler will fail.
+    pub fn with_shared_state(mut self, shared_state: SharedStateRegistry) -> Self {
+        self.shared_state = Some(shared_state);
+        self
+    }
 }
 
 #[cfg(feature = "templates")]
diff --git a/proxmox-rest-server/src/environment.rs b/proxmox-rest-server/src/environment.rs
index 47ff5a4f..9133999f 100644
--- a/proxmox-rest-server/src/environment.rs
+++ b/proxmox-rest-server/src/environment.rs
@@ -3,7 +3,7 @@ use std::sync::Arc;
 
 use serde_json::{Value, json};
 
-use proxmox_router::{RpcEnvironment, RpcEnvironmentType};
+use proxmox_router::{RpcEnvironment, RpcEnvironmentType, SharedStateRegistry};
 
 use crate::ApiConfig;
 
@@ -89,4 +89,8 @@ impl RpcEnvironment for RestEnvironment {
     fn get_client_ip(&self) -> Option<SocketAddr> {
         self.client_ip
     }
+
+    fn shared_state(&self) -> Option<&SharedStateRegistry> {
+        self.api.shared_state.as_ref()
+    }
 }
-- 
2.47.3





  parent reply	other threads:[~2026-08-27 11:42 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-27 11:42 [PATCH datacenter-manager/proxmox v3 00/21] inject application context via API macro for easier integration testing Lukas Wagner
2026-08-27 11:42 ` [PATCH proxmox v3 01/21] router: introduce shared state Lukas Wagner
2026-08-27 11:42 ` Lukas Wagner [this message]
2026-08-27 11:42 ` [PATCH proxmox v3 03/21] api-macro: support shared state extraction type Lukas Wagner
2026-08-27 11:42 ` [PATCH proxmox v3 04/21] product-config: add ProductConfig type Lukas Wagner
2026-08-27 11:42 ` [PATCH datacenter-manager v3 05/21] context: promote context to a dir-style module Lukas Wagner
2026-08-27 11:42 ` [PATCH datacenter-manager v3 06/21] pdm-config: remotes: rename trait methods to read/write/lock Lukas Wagner
2026-08-27 11:42 ` [PATCH datacenter-manager v3 07/21] pdm-config: subscriptions: " Lukas Wagner
2026-08-27 11:42 ` [PATCH datacenter-manager v3 08/21] remote iterator: pass remote config reader explicitly Lukas Wagner
2026-08-27 11:42 ` [PATCH datacenter-manager v3 09/21] context: introduce a ContextFactory to build application context Lukas Wagner
2026-08-27 11:42 ` [PATCH datacenter-manager v3 10/21] context: establish PdmApplication object Lukas Wagner
2026-08-27 11:42 ` [PATCH datacenter-manager v3 11/21] context: register PdmApplication in router Lukas Wagner
2026-08-27 11:42 ` [PATCH datacenter-manager v3 12/21] connection: use client factory from PdmApplication handle Lukas Wagner
2026-08-27 11:42 ` [PATCH datacenter-manager v3 13/21] parallel fetcher: pass arguments to closure in a single type Lukas Wagner
2026-08-27 11:42 ` [PATCH datacenter-manager v3 14/21] server: migrate existing ParallelFetcher users to use PdmApplication Lukas Wagner
2026-08-27 11:42 ` [PATCH datacenter-manager v3 15/21] tests: add helpers for building API-handler-level integration tests Lukas Wagner
2026-08-27 11:42 ` [PATCH datacenter-manager v3 16/21] tests: add example tests for SDN API routes Lukas Wagner
2026-08-27 11:42 ` [PATCH datacenter-manager v3 17/21] api-cache: add wrapper type Lukas Wagner
2026-08-27 11:42 ` [PATCH datacenter-manager v3 18/21] context: provide api-cache on the app object Lukas Wagner
2026-08-27 11:42 ` [PATCH datacenter-manager v3 19/21] api: subscriptions: use PdmApplication instead of globals Lukas Wagner
2026-08-27 11:42 ` [PATCH datacenter-manager v3 20/21] pdm-config: subscriptions: drop unused accessor functions Lukas Wagner
2026-08-27 11:42 ` [PATCH datacenter-manager v3 21/21] tests: add example tests for remote subscription management Lukas Wagner

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=20260827114244.424784-3-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal