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 C75B51FF0A8 for ; Thu, 20 Aug 2026 16:52:41 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 42AD521630; Thu, 20 Aug 2026 16:52:35 +0200 (CEST) From: Lukas Wagner To: pdm-devel@lists.proxmox.com Subject: [PATCH datacenter-manager v2 10/20] context: register PdmApplication in router Date: Thu, 20 Aug 2026 16:52:10 +0200 Message-ID: <20260820145220.418032-11-l.wagner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260820145220.418032-1-l.wagner@proxmox.com> References: <20260820145220.418032-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: 1787237519038 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.733 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: E743DD76AJWHFJYYZGZKRGNH4FT7NALN X-Message-ID-Hash: E743DD76AJWHFJYYZGZKRGNH4FT7NALN 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: 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 extractor instead of reaching for context::pdm_application() or other globals directly. Signed-off-by: Lukas Wagner --- 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::(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::(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::(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