From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 8CC7D1FF15C for ; Fri, 17 Oct 2025 08:39:23 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id C74CA1FC9B; Fri, 17 Oct 2025 08:39:36 +0200 (CEST) From: Hannes Laimer To: pve-devel@lists.proxmox.com Date: Fri, 17 Oct 2025 08:39:28 +0200 Message-ID: <20251017063929.30890-2-h.laimer@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251017063929.30890-1-h.laimer@proxmox.com> References: <20251017063929.30890-1-h.laimer@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1760683168877 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.042 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [proxmox-offline-mirror-helper.rs] Subject: [pve-devel] [PATCH proxmox-offline-mirror 1/2] helper: allow URL as source for offline key activation X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" If the HTTP server is setup like in our exmaple, `.mirror-state` is accessible over HTTP. With this the `offline-key` subcommand also accepts an URL as a source. So instead of reading the `.mirror-state` file directly from the fs, we'd load it over HTTP if an URL specified. This removes to need for mounting the medium directly just for key activation. Signed-off-by: Hannes Laimer --- src/bin/proxmox-offline-mirror-helper.rs | 63 ++++++++++++++++++------ 1 file changed, 49 insertions(+), 14 deletions(-) diff --git a/src/bin/proxmox-offline-mirror-helper.rs b/src/bin/proxmox-offline-mirror-helper.rs index 07537f0..849465c 100644 --- a/src/bin/proxmox-offline-mirror-helper.rs +++ b/src/bin/proxmox-offline-mirror-helper.rs @@ -5,6 +5,8 @@ use std::{collections::HashMap, path::Path}; use anyhow::{Error, bail, format_err}; +use proxmox_http::client::sync::Client; +use proxmox_http::{HttpClient, HttpOptions, ProxyConfig}; use proxmox_offline_mirror::types::Snapshot; use proxmox_subscription::{ProductType, SubscriptionInfo}; use proxmox_sys::command::run_command; @@ -24,6 +26,48 @@ use proxmox_offline_mirror::helpers::tty::{ }; use proxmox_offline_mirror::medium::{self, MediumState, generate_repo_snippet}; +fn load_mirror_state(source: &str) -> Result { + if source.starts_with("http://") || source.starts_with("https://") { + let state_url = if source.ends_with('/') { + format!("{}.mirror-state", source) + } else { + format!("{}/.mirror-state", source) + }; + + let options = HttpOptions { + user_agent: Some( + concat!("proxmox-offline-mirror-helper/", env!("CARGO_PKG_VERSION")).to_string(), + ), + proxy_config: ProxyConfig::from_proxy_env()?, + ..Default::default() + }; + let client = Client::new(options); + + let response = client.get(&state_url, None)?; + if !response.status().is_success() { + bail!( + "Failed to download mirror state from {}: {}", + state_url, + response.status() + ); + } + + let body: Vec = response.into_body(); + serde_json::from_slice(&body).map_err(Error::from) + } else { + let mountpoint = Path::new(source); + if !mountpoint.exists() { + bail!("Medium mountpoint doesn't exist."); + } + + let mut statefile = mountpoint.to_path_buf(); + statefile.push(".mirror-state"); + + let raw = file_get_contents(&statefile)?; + serde_json::from_slice(&raw).map_err(Error::from) + } +} + fn set_subscription_key( product: &ProductType, subscription: &SubscriptionInfo, @@ -264,9 +308,9 @@ async fn setup(_param: Value) -> Result<(), Error> { #[api( input: { properties: { - mountpoint: { + source: { type: String, - description: "Path to medium mountpoint", + description: "Path to medium mountpoint or URL for key activation", }, product: { type: ProductType, @@ -277,7 +321,7 @@ async fn setup(_param: Value) -> Result<(), Error> { )] /// Configures and offline subscription key async fn setup_offline_key( - mountpoint: String, + source: String, product: Option, _param: Value, ) -> Result<(), Error> { @@ -288,17 +332,8 @@ async fn setup_offline_key( ); } - let mountpoint = Path::new(&mountpoint); - if !mountpoint.exists() { - bail!("Medium mountpoint doesn't exist."); - } - - let mut statefile = mountpoint.to_path_buf(); - statefile.push(".mirror-state"); - - println!("Loading state from {statefile:?}.."); - let raw = file_get_contents(&statefile)?; - let state: MediumState = serde_json::from_slice(&raw)?; + println!("Loading state from {}..", source); + let state = load_mirror_state(&source)?; println!( "Last sync timestamp: {}", epoch_to_rfc3339_utc(state.last_sync)? -- 2.47.3 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel