mirror of
https://git.proxmox.com/git/proxmox-backup
synced 2025-08-07 21:47:11 +00:00
apt: use apt changelog
for changelog fetching
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 <f.gruenbichler@proxmox.com>
This commit is contained in:
parent
3d342e13d3
commit
07f321ddb4
@ -398,8 +398,6 @@ pub struct APTUpdateInfo {
|
|||||||
pub priority: String,
|
pub priority: String,
|
||||||
/// Package section
|
/// Package section
|
||||||
pub section: String,
|
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
|
/// Custom extra field for additional package information
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub extra_info: Option<String>,
|
pub extra_info: Option<String>,
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
use anyhow::{bail, format_err, Error};
|
use anyhow::{bail, format_err, Error};
|
||||||
use serde_json::{json, Value};
|
use serde_json::{json, Value};
|
||||||
use std::collections::HashMap;
|
|
||||||
use std::os::unix::prelude::OsStrExt;
|
use std::os::unix::prelude::OsStrExt;
|
||||||
|
|
||||||
use proxmox_router::{
|
use proxmox_router::{
|
||||||
@ -19,10 +18,9 @@ use pbs_api_types::{
|
|||||||
APTUpdateInfo, NODE_SCHEMA, PRIV_SYS_AUDIT, PRIV_SYS_MODIFY, PROXMOX_CONFIG_DIGEST_SCHEMA,
|
APTUpdateInfo, NODE_SCHEMA, PRIV_SYS_AUDIT, PRIV_SYS_MODIFY, PROXMOX_CONFIG_DIGEST_SCHEMA,
|
||||||
UPID_SCHEMA,
|
UPID_SCHEMA,
|
||||||
};
|
};
|
||||||
use pbs_buildcfg::PROXMOX_BACKUP_SUBSCRIPTION_FN;
|
|
||||||
|
|
||||||
use crate::config::node;
|
use crate::config::node;
|
||||||
use crate::tools::{apt, pbs_simple_http};
|
use crate::tools::apt;
|
||||||
use proxmox_rest_server::WorkerTask;
|
use proxmox_rest_server::WorkerTask;
|
||||||
|
|
||||||
#[api(
|
#[api(
|
||||||
@ -224,81 +222,17 @@ pub fn apt_update_database(
|
|||||||
},
|
},
|
||||||
)]
|
)]
|
||||||
/// Retrieve the changelog of the specified package.
|
/// Retrieve the changelog of the specified package.
|
||||||
fn apt_get_changelog(param: Value) -> Result<Value, Error> {
|
fn apt_get_changelog(name: String, version: Option<String>) -> Result<Value, Error> {
|
||||||
let name = pbs_tools::json::required_string_param(¶m, "name")?.to_owned();
|
let mut command = std::process::Command::new("apt-get");
|
||||||
let version = param["version"].as_str();
|
command.arg("changelog");
|
||||||
|
command.arg("-qq"); // don't display download progress
|
||||||
let pkg_info = apt::list_installed_apt_packages(
|
if let Some(ver) = version {
|
||||||
|data| match version {
|
command.arg(format!("{name}={ver}"));
|
||||||
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))
|
|
||||||
} else {
|
} else {
|
||||||
let mut command = std::process::Command::new("apt-get");
|
|
||||||
command.arg("changelog");
|
|
||||||
command.arg("-qq"); // don't display download progress
|
|
||||||
command.arg(name);
|
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(
|
#[api(
|
||||||
@ -349,7 +283,6 @@ pub fn get_versions() -> Result<Vec<APTUpdateInfo>, Error> {
|
|||||||
origin: "unknown".into(),
|
origin: "unknown".into(),
|
||||||
priority: "unknown".into(),
|
priority: "unknown".into(),
|
||||||
section: "unknown".into(),
|
section: "unknown".into(),
|
||||||
change_log_url: "unknown".into(),
|
|
||||||
extra_info,
|
extra_info,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,70 +90,6 @@ const_regex! {
|
|||||||
FILENAME_EXTRACT_REGEX = r"^.*/.*?_(.*)_Packages$";
|
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<String, Error> {
|
|
||||||
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 <pkg> --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> {
|
pub struct FilterData<'a> {
|
||||||
/// package name
|
/// package name
|
||||||
pub package: &'a str,
|
pub package: &'a str,
|
||||||
@ -273,7 +209,6 @@ where
|
|||||||
let mut origin_res = "unknown".to_owned();
|
let mut origin_res = "unknown".to_owned();
|
||||||
let mut section_res = "unknown".to_owned();
|
let mut section_res = "unknown".to_owned();
|
||||||
let mut priority_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 short_desc = package.clone();
|
||||||
let mut long_desc = "".to_owned();
|
let mut long_desc = "".to_owned();
|
||||||
|
|
||||||
@ -317,17 +252,6 @@ where
|
|||||||
if let Some(origin_name) = pkg_file.origin() {
|
if let Some(origin_name) = pkg_file.origin() {
|
||||||
origin_res = origin_name;
|
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,
|
title: short_desc,
|
||||||
arch: view.arch(),
|
arch: view.arch(),
|
||||||
description: long_desc,
|
description: long_desc,
|
||||||
change_log_url,
|
|
||||||
origin: origin_res,
|
origin: origin_res,
|
||||||
version: candidate_version.clone(),
|
version: candidate_version.clone(),
|
||||||
old_version: match current_version {
|
old_version: match current_version {
|
||||||
|
Loading…
Reference in New Issue
Block a user