From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 4615DBE92 for ; Tue, 4 Jul 2023 11:45:58 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 1844C27822 for ; Tue, 4 Jul 2023 11:45:28 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Tue, 4 Jul 2023 11:45:26 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 08B7043C7E for ; Tue, 4 Jul 2023 11:45:26 +0200 (CEST) From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= To: pve-devel@lists.proxmox.com Date: Tue, 4 Jul 2023 11:45:05 +0200 Message-Id: <20230704094507.92567-3-f.gruenbichler@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230704094507.92567-1-f.gruenbichler@proxmox.com> References: <20230704094507.92567-1-f.gruenbichler@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.071 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 SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - Subject: [pve-devel] [PATCH proxmox-backup 1/1] apt: use `apt changelog` for changelog fetching 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: , X-List-Received-Date: Tue, 04 Jul 2023 09:45:58 -0000 support for it got added to Proxmox repositories, so there is no need to use custom logic and manual fetching for this anymore. Signed-off-by: Fabian Grünbichler --- Notes: requires versioned depends on proxmox-widget-toolkit. pbs-api-types/src/lib.rs | 2 - src/api2/node/apt.rs | 85 +++++----------------------------------- src/tools/apt.rs | 77 ------------------------------------ 3 files changed, 9 insertions(+), 155 deletions(-) diff --git a/pbs-api-types/src/lib.rs b/pbs-api-types/src/lib.rs index 4764c51a..b663f2d7 100644 --- a/pbs-api-types/src/lib.rs +++ b/pbs-api-types/src/lib.rs @@ -395,8 +395,6 @@ pub struct APTUpdateInfo { pub priority: String, /// Package section pub section: String, - /// URL under which the package's changelog can be retrieved - pub change_log_url: String, /// Custom extra field for additional package information #[serde(skip_serializing_if = "Option::is_none")] pub extra_info: Option, diff --git a/src/api2/node/apt.rs b/src/api2/node/apt.rs index f7328b81..491b8cc9 100644 --- a/src/api2/node/apt.rs +++ b/src/api2/node/apt.rs @@ -1,6 +1,5 @@ use anyhow::{bail, format_err, Error}; use serde_json::{json, Value}; -use std::collections::HashMap; use std::os::unix::prelude::OsStrExt; use proxmox_router::{ @@ -19,10 +18,9 @@ use pbs_api_types::{ APTUpdateInfo, NODE_SCHEMA, PRIV_SYS_AUDIT, PRIV_SYS_MODIFY, PROXMOX_CONFIG_DIGEST_SCHEMA, UPID_SCHEMA, }; -use pbs_buildcfg::PROXMOX_BACKUP_SUBSCRIPTION_FN; use crate::config::node; -use crate::tools::{apt, pbs_simple_http}; +use crate::tools::apt; use proxmox_rest_server::WorkerTask; #[api( @@ -224,81 +222,17 @@ pub fn apt_update_database( }, )] /// Retrieve the changelog of the specified package. -fn apt_get_changelog(param: Value) -> Result { - let name = pbs_tools::json::required_string_param(¶m, "name")?.to_owned(); - let version = param["version"].as_str(); - - let pkg_info = apt::list_installed_apt_packages( - |data| match version { - Some(version) => version == data.active_version, - None => data.active_version == data.candidate_version, - }, - Some(&name), - ); - - if pkg_info.is_empty() { - bail!("Package '{}' not found", name); - } - - let proxy_config = read_and_update_proxy_config()?; - let client = pbs_simple_http(proxy_config); - - let changelog_url = &pkg_info[0].change_log_url; - // FIXME: use 'apt-get changelog' for proxmox packages as well, once repo supports it - if changelog_url.starts_with("http://download.proxmox.com/") { - let changelog = proxmox_async::runtime::block_on(client.get_string(changelog_url, None)) - .map_err(|err| { - format_err!( - "Error downloading changelog from '{}': {}", - changelog_url, - err - ) - })?; - Ok(json!(changelog)) - } else if changelog_url.starts_with("https://enterprise.proxmox.com/") { - let sub = match proxmox_subscription::files::read_subscription( - PROXMOX_BACKUP_SUBSCRIPTION_FN, - &[proxmox_subscription::files::DEFAULT_SIGNING_KEY], - )? { - Some(sub) => sub, - None => { - bail!("cannot retrieve changelog from enterprise repo: no subscription info found") - } - }; - let (key, id) = match sub.key { - Some(key) => match sub.serverid { - Some(id) => (key, id), - None => bail!("cannot retrieve changelog from enterprise repo: no server id found"), - }, - None => { - bail!("cannot retrieve changelog from enterprise repo: no subscription key found") - } - }; - - let mut auth_header = HashMap::new(); - auth_header.insert( - "Authorization".to_owned(), - format!("Basic {}", base64::encode(format!("{}:{}", key, id))), - ); - - let changelog = - proxmox_async::runtime::block_on(client.get_string(changelog_url, Some(&auth_header))) - .map_err(|err| { - format_err!( - "Error downloading changelog from '{}': {}", - changelog_url, - err - ) - })?; - Ok(json!(changelog)) +fn apt_get_changelog(name: String, version: Option) -> Result { + let mut command = std::process::Command::new("apt-get"); + command.arg("changelog"); + command.arg("-qq"); // don't display download progress + if let Some(ver) = version { + command.arg(format!("{name}={ver}")); } else { - let mut command = std::process::Command::new("apt-get"); - command.arg("changelog"); - command.arg("-qq"); // don't display download progress command.arg(name); - let output = proxmox_sys::command::run_command(command, None)?; - Ok(json!(output)) } + let output = proxmox_sys::command::run_command(command, None)?; + Ok(json!(output)) } #[api( @@ -349,7 +283,6 @@ pub fn get_versions() -> Result, Error> { origin: "unknown".into(), priority: "unknown".into(), section: "unknown".into(), - change_log_url: "unknown".into(), extra_info, } } diff --git a/src/tools/apt.rs b/src/tools/apt.rs index 5a8cd136..900843aa 100644 --- a/src/tools/apt.rs +++ b/src/tools/apt.rs @@ -90,70 +90,6 @@ const_regex! { FILENAME_EXTRACT_REGEX = r"^.*/.*?_(.*)_Packages$"; } -// FIXME: once the 'changelog' API call switches over to 'apt-get changelog' only, -// consider removing this function entirely, as it's value is never used anywhere -// then (widget-toolkit doesn't use the value either) -fn get_changelog_url( - package: &str, - filename: &str, - version: &str, - origin: &str, - component: &str, -) -> Result { - if origin.is_empty() { - bail!("no origin available for package {}", package); - } - - if origin == "Debian" { - let mut command = std::process::Command::new("apt-get"); - command.arg("changelog"); - command.arg("--print-uris"); - command.arg(package); - let output = proxmox_sys::command::run_command(command, None)?; // format: 'http://foo/bar' package.changelog - let output = match output.split_once(' ') { - Some((uri, _file_name)) if uri.len() > 2 => uri[1..uri.len() - 1].to_owned(), - Some((uri, _file_name)) => bail!( - "invalid output (URI part too short) from 'apt-get changelog --print-uris': {}", - uri - ), - None => bail!( - "invalid output from 'apt-get changelog --print-uris': {}", - output - ), - }; - return Ok(output); - } else if origin == "Proxmox" { - // FIXME: Use above call to 'apt changelog --print-uris' as well. - // Currently not possible as our packages do not have a URI set in their Release file. - let version = (VERSION_EPOCH_REGEX.regex_obj)().replace_all(version, ""); - - let base = match (FILENAME_EXTRACT_REGEX.regex_obj)().captures(filename) { - Some(captures) => { - let base_capture = captures.get(1); - match base_capture { - Some(base_underscore) => base_underscore.as_str().replace('_', "/"), - None => bail!("incompatible filename, cannot find regex group"), - } - } - None => bail!("incompatible filename, doesn't match regex"), - }; - - if component == "pbs-enterprise" { - return Ok(format!( - "https://enterprise.proxmox.com/{}/{}_{}.changelog", - base, package, version - )); - } else { - return Ok(format!( - "http://download.proxmox.com/{}/{}_{}.changelog", - base, package, version - )); - } - } - - bail!("unknown origin ({}) or component ({})", origin, component) -} - pub struct FilterData<'a> { /// package name pub package: &'a str, @@ -273,7 +209,6 @@ where let mut origin_res = "unknown".to_owned(); let mut section_res = "unknown".to_owned(); let mut priority_res = "unknown".to_owned(); - let mut change_log_url = "".to_owned(); let mut short_desc = package.clone(); let mut long_desc = "".to_owned(); @@ -317,17 +252,6 @@ where if let Some(origin_name) = pkg_file.origin() { origin_res = origin_name; } - - let filename = pkg_file.file_name(); - let component = pkg_file.component(); - - // build changelog URL from gathered information - // ignore errors, use empty changelog instead - let url = - get_changelog_url(&package, &filename, &version, &origin_res, &component); - if let Ok(url) = url { - change_log_url = url; - } } } @@ -352,7 +276,6 @@ where title: short_desc, arch: view.arch(), description: long_desc, - change_log_url, origin: origin_res, version: candidate_version.clone(), old_version: match current_version { -- 2.39.2