From: Lukas Wagner <l.wagner@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [PATCH datacenter-manager 10/20] context: register PdmApplication in router
Date: Mon, 17 Aug 2026 14:57:17 +0200 [thread overview]
Message-ID: <20260817125727.454039-11-l.wagner@proxmox.com> (raw)
In-Reply-To: <20260817125727.454039-1-l.wagner@proxmox.com>
Register the PdmApplication handle in a SharedStateRegistry and pass
it to the REST server config via with_shared_state(), so API handlers
can request it through the State<PdmApplication> extractor instead of
reaching for context::pdm_application() or other globals directly.
Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
cli/admin/src/main.rs | 9 +++++++--
server/src/bin/proxmox-datacenter-api/main.rs | 8 ++++++--
server/src/bin/proxmox-datacenter-privileged-api.rs | 8 ++++++--
3 files changed, 19 insertions(+), 6 deletions(-)
diff --git a/cli/admin/src/main.rs b/cli/admin/src/main.rs
index a2c5c623..2275eea3 100644
--- a/cli/admin/src/main.rs
+++ b/cli/admin/src/main.rs
@@ -3,14 +3,15 @@ use core::matches;
use anyhow::{Context, Error};
use serde_json::{Value, json};
-use proxmox_router::RpcEnvironment;
use proxmox_router::cli::{
CliCommand, CliCommandMap, CliEnvironment, ColumnConfig, OUTPUT_FORMAT,
default_table_format_options, format_and_print_result_full, get_output_format,
run_async_cli_command,
};
+use proxmox_router::{RpcEnvironment, SharedStateRegistry};
use proxmox_schema::api;
use proxmox_sys::fs::CreateOptions;
+use server::context::PdmApplication;
mod acme;
mod cert;
@@ -36,7 +37,7 @@ async fn run() -> Result<(), Error> {
.init()
.context("failed to set up logger")?;
- server::context::init().context("could not set up server context")?;
+ let app = server::context::init().context("could not set up server context")?;
let cmd_def = CliCommandMap::new()
.insert("acme", acme::acme_mgmt_cli())
@@ -68,7 +69,11 @@ async fn run() -> Result<(), Error> {
.context("failed to activate the socket")?;
}
+ let mut shared_state = SharedStateRegistry::default();
+ shared_state.register::<PdmApplication>(app)?;
+
let mut rpcenv = CliEnvironment::new();
+ rpcenv.set_shared_state_registry(shared_state);
rpcenv.set_auth_id(Some("root@pam".into()));
run_async_cli_command(cmd_def, rpcenv).await;
diff --git a/server/src/bin/proxmox-datacenter-api/main.rs b/server/src/bin/proxmox-datacenter-api/main.rs
index 8ae7192c..eac1585b 100644
--- a/server/src/bin/proxmox-datacenter-api/main.rs
+++ b/server/src/bin/proxmox-datacenter-api/main.rs
@@ -18,7 +18,7 @@ use url::form_urlencoded;
use proxmox_lang::try_block;
use proxmox_rest_server::{ApiConfig, RestEnvironment, RestServer};
-use proxmox_router::{RpcEnvironment, RpcEnvironmentType};
+use proxmox_router::{RpcEnvironment, RpcEnvironmentType, SharedStateRegistry};
use proxmox_sys::fs::CreateOptions;
use pdm_buildcfg::configdir;
@@ -160,6 +160,9 @@ async fn run(app: PdmApplication, debug: bool) -> Result<(), Error> {
let indexpath = Path::new(pdm_buildcfg::JS_DIR).join("index.hbs");
+ let mut shared_state = SharedStateRegistry::default();
+ shared_state.register::<PdmApplication>(app.clone())?;
+
let config = ApiConfig::new(pdm_buildcfg::JS_DIR, RpcEnvironmentType::PUBLIC)
.privileged_addr(
std::os::unix::net::SocketAddr::from_pathname(
@@ -195,7 +198,8 @@ async fn run(app: PdmApplication, debug: bool) -> Result<(), Error> {
Some(dir_opts),
Some(file_opts),
&mut command_sock,
- )?;
+ )?
+ .with_shared_state(shared_state);
let rest_server = RestServer::new(config);
let redirector = proxmox_rest_server::Redirector::new();
diff --git a/server/src/bin/proxmox-datacenter-privileged-api.rs b/server/src/bin/proxmox-datacenter-privileged-api.rs
index e1de53c3..3815ab03 100644
--- a/server/src/bin/proxmox-datacenter-privileged-api.rs
+++ b/server/src/bin/proxmox-datacenter-privileged-api.rs
@@ -11,7 +11,7 @@ use tracing::level_filters::LevelFilter;
use proxmox_lang::try_block;
use proxmox_rest_server::{ApiConfig, RestServer};
-use proxmox_router::RpcEnvironmentType;
+use proxmox_router::{RpcEnvironmentType, SharedStateRegistry};
use proxmox_sys::fs::CreateOptions;
use server::context::PdmApplication;
@@ -140,6 +140,9 @@ async fn run(app: PdmApplication) -> Result<(), Error> {
let dir_opts = CreateOptions::new().owner(api_user.uid).group(api_user.gid);
let file_opts = CreateOptions::new().owner(api_user.uid).group(api_user.gid);
+ let mut shared_state = SharedStateRegistry::default();
+ shared_state.register::<PdmApplication>(app)?;
+
let config = ApiConfig::new(pdm_buildcfg::JS_DIR, RpcEnvironmentType::PRIVILEGED)
.auth_handler_func(|h, m| Box::pin(auth::check_auth(h, m)))
.formatted_router(&["api2"], &server::api::ROUTER)
@@ -154,7 +157,8 @@ async fn run(app: PdmApplication) -> Result<(), Error> {
Some(dir_opts),
Some(file_opts),
&mut command_sock,
- )?;
+ )?
+ .with_shared_state(shared_state);
let rest_server = RestServer::new(config);
proxmox_rest_server::init_worker_tasks(pdm_buildcfg::PDM_LOG_DIR_M!().into(), file_opts)?;
--
2.47.3
next prev parent reply other threads:[~2026-08-17 12:57 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-17 12:57 [PATCH datacenter-manager/proxmox 00/20] inject application context via API macro for easier integration testing Lukas Wagner
2026-08-17 12:57 ` [PATCH proxmox 01/20] router: introduce shared state Lukas Wagner
2026-08-17 13:26 ` Lukas Wagner
2026-08-20 11:23 ` Lukas Wagner
2026-08-21 13:59 ` Robert Obkircher
2026-08-17 12:57 ` [PATCH proxmox 02/20] rest-server: allow to inject " Lukas Wagner
2026-08-17 12:57 ` [PATCH proxmox 03/20] api-macro: support shared state extraction type Lukas Wagner
2026-08-21 13:59 ` Robert Obkircher
2026-08-17 12:57 ` [PATCH datacenter-manager 04/20] context: promote context to a dir-style module Lukas Wagner
2026-08-17 12:57 ` [PATCH datacenter-manager 05/20] pdm-config: remotes: rename trait methods to read/write/lock Lukas Wagner
2026-08-17 12:57 ` [PATCH datacenter-manager 06/20] pdm-config: subscriptions: " Lukas Wagner
2026-08-21 14:00 ` Robert Obkircher
2026-08-17 12:57 ` [PATCH datacenter-manager 07/20] remote iterator: pass remote config reader explicitly Lukas Wagner
2026-08-17 12:57 ` [PATCH datacenter-manager 08/20] context: introduce a ContextFactory to build application context Lukas Wagner
2026-08-17 12:57 ` [PATCH datacenter-manager 09/20] context: establish PdmApplication object Lukas Wagner
2026-08-17 12:57 ` Lukas Wagner [this message]
2026-08-17 12:57 ` [PATCH datacenter-manager 11/20] parallel fetcher: pass arguments to closure in a single type Lukas Wagner
2026-08-21 14:00 ` Robert Obkircher
2026-08-17 12:57 ` [PATCH datacenter-manager 12/20] parallel fetcher: support a custom client factory Lukas Wagner
2026-08-17 12:57 ` [PATCH datacenter-manager 13/20] api: sdn: use PdmApplication handle for accessing remotes Lukas Wagner
2026-08-17 12:57 ` [PATCH datacenter-manager 14/20] tests: add helpers for building API-handler-level integration tests Lukas Wagner
2026-08-17 12:57 ` [PATCH datacenter-manager 15/20] tests: add example tests for SDN API routes Lukas Wagner
2026-08-17 12:57 ` [PATCH datacenter-manager 16/20] api-cache: add wrapper type Lukas Wagner
2026-08-17 12:57 ` [PATCH datacenter-manager 17/20] context: provide api-cache on the app object Lukas Wagner
2026-08-17 12:57 ` [PATCH datacenter-manager 18/20] api: subscriptions: use PdmApplication instead of globals Lukas Wagner
2026-08-17 12:57 ` [PATCH datacenter-manager 19/20] pdm-config: subscriptions: drop unused accessor functions Lukas Wagner
2026-08-17 12:57 ` [PATCH datacenter-manager 20/20] tests: add example tests for remote subscription management Lukas Wagner
2026-08-20 14:54 ` superseded: [PATCH datacenter-manager/proxmox 00/20] inject application context via API macro for easier integration testing 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=20260817125727.454039-11-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