all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: "Laurențiu Leahu-Vlăducu" <l.leahu-vladucu@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup v2 1/2] proxmox-backup-api/proxy: Add proxmox-product-config as dependency
Date: Thu,  6 Feb 2025 13:28:32 +0100	[thread overview]
Message-ID: <20250206122833.171965-3-l.leahu-vladucu@proxmox.com> (raw)
In-Reply-To: <20250206122833.171965-1-l.leahu-vladucu@proxmox.com>

The proxmox-product-config crate has now been added as a dependency
to allow easily serializing and deserializing config or state files.
While this functionality was already supported by pbs-config, the
previous code was always writing config files as the root user.

In order to serialize/deserialize further config or state files
without duplicating existing code unnecessarily, future code will be
able to use the proxmox-product-config crate.

If the backup or root user could not be found, it is unsafe
to continue, so the initialization will fail.

Signed-off-by: Laurențiu Leahu-Vlăducu <l.leahu-vladucu@proxmox.com>
---
 Cargo.toml                      | 2 ++
 src/bin/proxmox-backup-api.rs   | 2 ++
 src/bin/proxmox-backup-proxy.rs | 2 ++
 src/tools/mod.rs                | 9 +++++++++
 4 files changed, 15 insertions(+)

diff --git a/Cargo.toml b/Cargo.toml
index bc1e9ed2..55a80dcd 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -71,6 +71,7 @@ proxmox-ldap = "0.2.1"
 proxmox-metrics = "0.3.1"
 proxmox-notify = "0.5.1"
 proxmox-openid = "0.10.0"
+proxmox-product-config = "0.2.2"
 proxmox-rest-server = { version = "0.8.5", features = [ "templates" ] }
 # some use "cli", some use "cli" and "server", pbs-config uses nothing
 proxmox-router = { version = "3.0.0", default-features = false }
@@ -218,6 +219,7 @@ proxmox-ldap.workspace = true
 proxmox-metrics.workspace = true
 proxmox-notify = { workspace = true, features = [ "pbs-context" ] }
 proxmox-openid.workspace = true
+proxmox-product-config.workspace = true
 proxmox-rest-server = { workspace = true, features = [ "rate-limited-stream" ] }
 proxmox-router = { workspace = true, features = [ "cli", "server"] }
 proxmox-schema = { workspace = true, features = [ "api-macro" ] }
diff --git a/src/bin/proxmox-backup-api.rs b/src/bin/proxmox-backup-api.rs
index 829974d2..0b5863f3 100644
--- a/src/bin/proxmox-backup-api.rs
+++ b/src/bin/proxmox-backup-api.rs
@@ -43,6 +43,8 @@ fn get_index() -> Pin<Box<dyn Future<Output = Response<Body>> + Send>> {
 async fn run() -> Result<(), Error> {
     init_logger("PBS_LOG", LevelFilter::INFO)?;
 
+    proxmox_backup::tools::init_product_config()?;
+
     config::create_configdir()?;
 
     config::update_self_signed_cert(false)?;
diff --git a/src/bin/proxmox-backup-proxy.rs b/src/bin/proxmox-backup-proxy.rs
index e9870532..edd0a4cc 100644
--- a/src/bin/proxmox-backup-proxy.rs
+++ b/src/bin/proxmox-backup-proxy.rs
@@ -181,6 +181,8 @@ async fn get_index_future(env: RestEnvironment, parts: Parts) -> Response<Body>
 async fn run() -> Result<(), Error> {
     init_logger("PBS_LOG", LevelFilter::INFO)?;
 
+    proxmox_backup::tools::init_product_config()?;
+
     proxmox_backup::auth_helpers::setup_auth_context(false);
     proxmox_backup::server::notifications::init()?;
     metric_collection::init()?;
diff --git a/src/tools/mod.rs b/src/tools/mod.rs
index 322894dd..8887df6e 100644
--- a/src/tools/mod.rs
+++ b/src/tools/mod.rs
@@ -61,3 +61,12 @@ pub fn setup_safe_path_env() {
         std::env::remove_var(name);
     }
 }
+
+/// Initializes the global product configuration for the proxmox_product_config crate.
+pub fn init_product_config() -> Result<(), Error> {
+    let backup_user = pbs_config::backup_user()?;
+    let root_user = nix::unistd::User::from_uid(nix::unistd::ROOT)?
+        .ok_or(anyhow::format_err!("Could not find root user"))?;
+    proxmox_product_config::init(backup_user, root_user);
+    Ok(())
+}
-- 
2.39.5



_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel

  parent reply	other threads:[~2025-02-06 12:29 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-06 12:28 [pbs-devel] [PATCH proxmox/proxmox-backup v2] Automatically select a drive (if part of a changer) when loading tapes Laurențiu Leahu-Vlăducu
2025-02-06 12:28 ` [pbs-devel] [PATCH proxmox v2 1/1] pbs-api-types: Added changer schema for automatic drive assignment Laurențiu Leahu-Vlăducu
2025-02-06 12:28 ` Laurențiu Leahu-Vlăducu [this message]
2025-02-17 11:49   ` [pbs-devel] [PATCH proxmox-backup v2 1/2] proxmox-backup-api/proxy: Add proxmox-product-config as dependency Dominik Csapak
2025-02-06 12:28 ` [pbs-devel] [PATCH proxmox-backup v2 2/2] Automatically select a drive (if part of a changer) when loading tapes Laurențiu Leahu-Vlăducu
2025-02-17 11:49   ` Dominik Csapak

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=20250206122833.171965-3-l.leahu-vladucu@proxmox.com \
    --to=l.leahu-vladucu@proxmox.com \
    --cc=pbs-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