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 24871616E6 for ; Wed, 21 Oct 2020 11:42:03 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 6A77E168B7 for ; Wed, 21 Oct 2020 11:41:32 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (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 id CD4E316854 for ; Wed, 21 Oct 2020 11:41:29 +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 989BF45EA0 for ; Wed, 21 Oct 2020 11:41:29 +0200 (CEST) From: Stefan Reiter To: pbs-devel@lists.proxmox.com Date: Wed, 21 Oct 2020 11:41:16 +0200 Message-Id: <20201021094116.32501-8-s.reiter@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201021094116.32501-1-s.reiter@proxmox.com> References: <20201021094116.32501-1-s.reiter@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.032 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment 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 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.com, apt.rs] Subject: [pbs-devel] [PATCH proxmox-backup 7/7] apt: add /changelog API call similar to PVE X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 Oct 2020 09:42:03 -0000 For proxmox packages it works the same way as PVE, by retrieving the changelog URL and issuing a HTTP GET to it, forwarding the output to the client. As this is only supposed to be a workaround removed in the future, a simple block_on is used to avoid async. For debian packages we can simply call 'apt-get changelog' and forward it's output. Signed-off-by: Stefan Reiter --- src/api2/node/apt.rs | 63 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/src/api2/node/apt.rs b/src/api2/node/apt.rs index 20a738c0..1c5b7db9 100644 --- a/src/api2/node/apt.rs +++ b/src/api2/node/apt.rs @@ -1,7 +1,7 @@ use std::collections::HashSet; use apt_pkg_native::Cache; -use anyhow::{Error, bail}; +use anyhow::{Error, bail, format_err}; use serde_json::{json, Value}; use proxmox::{list_subdirs_api_method, const_regex}; @@ -9,6 +9,7 @@ use proxmox::api::{api, RpcEnvironment, RpcEnvironmentType, Permission}; use proxmox::api::router::{Router, SubdirMap}; use crate::server::WorkerTask; +use crate::tools::http; use crate::config::acl::{PRIV_SYS_AUDIT, PRIV_SYS_MODIFY}; use crate::api2::types::{APTUpdateInfo, NODE_SCHEMA, Userid, UPID_SCHEMA}; @@ -373,7 +374,67 @@ pub fn apt_update_database( Ok(upid_str) } +#[api( + input: { + properties: { + node: { + schema: NODE_SCHEMA, + }, + name: { + description: "Package name to get changelog of.", + type: String, + }, + version: { + description: "Package version to get changelog of. Omit to use candidate version.", + type: String, + optional: true, + }, + }, + }, + returns: { + schema: UPID_SCHEMA, + }, + access: { + permission: &Permission::Privilege(&[], PRIV_SYS_MODIFY, false), + }, +)] +/// Retrieve the changelog of the specified package. +fn apt_get_changelog( + param: Value, +) -> Result { + + let name = crate::tools::required_string_param(¶m, "name")?.to_owned(); + let version = param["version"].as_str(); + + let pkg_info = 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.len() == 0 { + bail!("Package '{}' not found", name); + } + + 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 = crate::tools::runtime::block_on(http::get_string(changelog_url)) + .map_err(|err| format_err!("Error downloading changelog: {}", err))?; + return Ok(json!(changelog)); + } 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 = crate::tools::run_command(command, None)?; + return Ok(json!(output)); + } +} + const SUBDIRS: SubdirMap = &[ + ("changelog", &Router::new().get(&API_METHOD_APT_GET_CHANGELOG)), ("update", &Router::new() .get(&API_METHOD_APT_UPDATE_AVAILABLE) .post(&API_METHOD_APT_UPDATE_DATABASE) -- 2.20.1