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: [PATCH datacenter-manager v3 11/21] context: register PdmApplication in router
Date: Thu, 27 Aug 2026 13:42:34 +0200	[thread overview]
Message-ID: <20260827114244.424784-12-l.wagner@proxmox.com> (raw)
In-Reply-To: <20260827114244.424784-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                             | 10 ++++++++--
 server/src/bin/proxmox-datacenter-api/main.rs     | 15 ++++++++++-----
 .../src/bin/proxmox-datacenter-privileged-api.rs  | 15 ++++++++++-----
 3 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/cli/admin/src/main.rs b/cli/admin/src/main.rs
index a2c5c623..a514d2fc 100644
--- a/cli/admin/src/main.rs
+++ b/cli/admin/src/main.rs
@@ -3,15 +3,17 @@ 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;
 mod remotes;
@@ -36,7 +38,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 +70,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 57aa6e22..64326b9b 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;
@@ -28,6 +28,7 @@ use proxmox_auth_api::api::assemble_csrf_prevention_token;
 
 use server::auth;
 use server::auth::csrf::csrf_secret;
+use server::context::PdmApplication;
 use server::metric_collection;
 use server::resource_cache;
 use server::task_utils;
@@ -67,9 +68,9 @@ fn main() -> Result<(), Error> {
     }
 
     proxmox_product_config::init(pdm_config::api_user()?, pdm_config::priv_user()?);
-    server::context::init()?;
+    let app = server::context::init()?;
 
-    proxmox_async::runtime::main(run(debug))
+    proxmox_async::runtime::main(run(app, debug))
 }
 
 async fn get_index_future(env: RestEnvironment, parts: Parts) -> Response<proxmox_http::Body> {
@@ -144,7 +145,7 @@ async fn get_index_future(env: RestEnvironment, parts: Parts) -> Response<proxmo
     resp
 }
 
-async fn run(debug: bool) -> Result<(), Error> {
+async fn run(app: PdmApplication, debug: bool) -> Result<(), Error> {
     auth::init(false);
 
     proxmox_acme_api::init(configdir!("/acme"), false)?;
@@ -159,6 +160,9 @@ async fn run(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(
@@ -194,7 +198,8 @@ async fn run(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 59d30513..3815ab03 100644
--- a/server/src/bin/proxmox-datacenter-privileged-api.rs
+++ b/server/src/bin/proxmox-datacenter-privileged-api.rs
@@ -11,9 +11,10 @@ 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;
 use server::{api_cache, auth};
 
 use pdm_buildcfg::configdir;
@@ -54,9 +55,9 @@ fn main() -> Result<(), Error> {
         }
     }
 
-    server::context::init()?;
+    let app = server::context::init()?;
 
-    proxmox_async::runtime::main(run())
+    proxmox_async::runtime::main(run(app))
 }
 
 fn create_directories() -> Result<(), Error> {
@@ -114,7 +115,7 @@ fn create_directories() -> Result<(), Error> {
     Ok(())
 }
 
-async fn run() -> Result<(), Error> {
+async fn run(app: PdmApplication) -> Result<(), Error> {
     auth::init(true);
 
     proxmox_acme_api::init(configdir!("/acme"), true)?;
@@ -139,6 +140,9 @@ async fn run() -> 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)
@@ -153,7 +157,8 @@ async fn run() -> 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





  parent reply	other threads:[~2026-08-27 11:43 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 ` [PATCH proxmox v3 02/21] rest-server: allow to inject " Lukas Wagner
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 ` Lukas Wagner [this message]
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-12-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