use anyhow::{bail, format_err, Error};
use serde_json::{json, Value};
-use std::collections::HashMap;
use std::os::unix::prelude::OsStrExt;
use proxmox_router::{
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(
},
)]
/// Retrieve the changelog of the specified package.
-fn apt_get_changelog(param: Value) -> Result<Value, Error> {
- 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<String>) -> Result<Value, Error> {
+ 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(
origin: "unknown".into(),
priority: "unknown".into(),
section: "unknown".into(),
- change_log_url: "unknown".into(),
extra_info,
}
}
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> {
/// package name
pub package: &'a str,
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();
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;
- }
}
}
title: short_desc,
arch: view.arch(),
description: long_desc,
- change_log_url,
origin: origin_res,
version: candidate_version.clone(),
old_version: match current_version {