From: Stefan Reiter <s.reiter@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup 7/7] apt: add /changelog API call similar to PVE
Date: Wed, 21 Oct 2020 11:41:16 +0200 [thread overview]
Message-ID: <20201021094116.32501-8-s.reiter@proxmox.com> (raw)
In-Reply-To: <20201021094116.32501-1-s.reiter@proxmox.com>
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 <s.reiter@proxmox.com>
---
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<Value, Error> {
+
+ 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
next prev parent reply other threads:[~2020-10-21 9:42 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-21 9:41 [pbs-devel] [PATCH 0/7] apt: add changelog API and fix #2934 (list new packages) Stefan Reiter
2020-10-21 9:41 ` [pbs-devel] [PATCH proxmox-backup 1/7] apt: allow filter to select different package version Stefan Reiter
2020-10-21 9:41 ` [pbs-devel] [PATCH proxmox-backup 2/7] add tools::http for generic HTTP GET and move HttpsConnector there Stefan Reiter
2020-10-21 18:31 ` [pbs-devel] applied: " Thomas Lamprecht
2020-10-21 9:41 ` [pbs-devel] [PATCH proxmox-backup 3/7] apt: use 'apt-get changelog --print-uris' in get_changelog_url Stefan Reiter
2020-10-21 9:41 ` [pbs-devel] [PATCH proxmox-backup 4/7] bump apt-pkg-native dependency to 0.3.2 Stefan Reiter
2020-10-21 9:41 ` [pbs-devel] [PATCH proxmox-backup 5/7] apt: refactor package detail reading into function Stefan Reiter
2020-10-21 9:41 ` [pbs-devel] [PATCH proxmox-backup 6/7] fix #2934: list to-be-installed packages in updates Stefan Reiter
2020-10-21 9:41 ` Stefan Reiter [this message]
2020-10-22 15:20 ` [pbs-devel] applied-series: [PATCH 0/7] apt: add changelog API and fix #2934 (list new packages) Fabian Grünbichler
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=20201021094116.32501-8-s.reiter@proxmox.com \
--to=s.reiter@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox