From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 520161FF179 for ; Wed, 15 Oct 2025 14:47:38 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 3344A1B274; Wed, 15 Oct 2025 14:47:57 +0200 (CEST) From: Lukas Wagner To: pdm-devel@lists.proxmox.com Date: Wed, 15 Oct 2025 14:47:09 +0200 Message-ID: <20251015124711.312943-11-l.wagner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251015124711.312943-1-l.wagner@proxmox.com> References: <20251015124711.312943-1-l.wagner@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1760532437935 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.027 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 Subject: [pdm-devel] [PATCH proxmox-datacenter-manager 10/12] api: add APT endpoints for PBS remotes X-BeenThere: pdm-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Datacenter Manager development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Datacenter Manager development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pdm-devel-bounces@lists.proxmox.com Sender: "pdm-devel" Since the endpoints are exactly identical as the PVE ones, we move the implementation to a shared module and use the same for both. Signed-off-by: Lukas Wagner --- server/src/api/pbs/mod.rs | 4 ++ server/src/api/pbs/node.rs | 9 +++ server/src/api/pve/apt.rs | 119 ------------------------------- server/src/api/pve/mod.rs | 1 - server/src/api/pve/node.rs | 2 +- server/src/api/remote_updates.rs | 118 +++++++++++++++++++++++++++++- 6 files changed, 130 insertions(+), 123 deletions(-) create mode 100644 server/src/api/pbs/node.rs delete mode 100644 server/src/api/pve/apt.rs diff --git a/server/src/api/pbs/mod.rs b/server/src/api/pbs/mod.rs index b3bb126c..43bd1a28 100644 --- a/server/src/api/pbs/mod.rs +++ b/server/src/api/pbs/mod.rs @@ -20,6 +20,7 @@ use crate::{ use crate::remote_tasks; +mod node; mod rrddata; pub const ROUTER: Router = Router::new() @@ -41,8 +42,11 @@ pub const MAIN_ROUTER: Router = Router::new() .get(&list_subdirs_api_method!(REMOTE_SUBDIRS)) .subdirs(REMOTE_SUBDIRS); +const NODES_ROUTER: Router = Router::new().match_all("node", &node::ROUTER); + #[sortable] const REMOTE_SUBDIRS: SubdirMap = &sorted!([ + ("nodes", &NODES_ROUTER), ("status", &Router::new().get(&API_METHOD_GET_STATUS)), ("rrddata", &rrddata::PBS_NODE_RRD_ROUTER), ("datastore", &DATASTORE_ROUTER) diff --git a/server/src/api/pbs/node.rs b/server/src/api/pbs/node.rs new file mode 100644 index 00000000..286e1a11 --- /dev/null +++ b/server/src/api/pbs/node.rs @@ -0,0 +1,9 @@ +use proxmox_router::{list_subdirs_api_method, Router, SubdirMap}; +use proxmox_sortable_macro::sortable; + +pub const ROUTER: Router = Router::new() + .get(&list_subdirs_api_method!(SUBDIRS)) + .subdirs(SUBDIRS); + +#[sortable] +const SUBDIRS: SubdirMap = &sorted!([("apt", &crate::api::remote_updates::APT_ROUTER),]); diff --git a/server/src/api/pve/apt.rs b/server/src/api/pve/apt.rs deleted file mode 100644 index f5027fb8..00000000 --- a/server/src/api/pve/apt.rs +++ /dev/null @@ -1,119 +0,0 @@ -use anyhow::Error; - -use proxmox_apt_api_types::{APTGetChangelogOptions, APTUpdateInfo}; -use proxmox_router::{list_subdirs_api_method, Permission, Router, SubdirMap}; -use proxmox_schema::api; -use proxmox_schema::api_types::NODE_SCHEMA; - -use pdm_api_types::{remotes::REMOTE_ID_SCHEMA, RemoteUpid, PRIV_RESOURCE_MODIFY}; - -use crate::{api::remotes::get_remote, remote_updates}; - -#[api( - input: { - properties: { - remote: { - schema: REMOTE_ID_SCHEMA, - }, - node: { - schema: NODE_SCHEMA, - }, - }, - }, - returns: { - description: "A list of packages with available updates.", - type: Array, - items: { - type: APTUpdateInfo - }, - }, - access: { - permission: &Permission::Privilege(&["resource", "{remote}", "node", "{node}", "system"], PRIV_RESOURCE_MODIFY, false), - }, -)] -/// List available APT updates for a remote PVE node. -async fn apt_update_available(remote: String, node: String) -> Result, Error> { - let (config, _digest) = pdm_config::remotes::config()?; - let remote = get_remote(&config, &remote)?; - - let updates = remote_updates::list_available_updates(remote.clone(), &node).await?; - - Ok(updates) -} - -#[api( - input: { - properties: { - remote: { - schema: REMOTE_ID_SCHEMA, - }, - node: { - schema: NODE_SCHEMA, - }, - }, - }, - access: { - permission: &Permission::Privilege(&["resource", "{remote}", "node", "{node}", "system"], PRIV_RESOURCE_MODIFY, false), - }, -)] -/// Update the APT database of a remote PVE node. -pub async fn apt_update_database(remote: String, node: String) -> Result { - let (config, _digest) = pdm_config::remotes::config()?; - let remote = get_remote(&config, &remote)?; - - let upid = remote_updates::update_apt_database(remote, &node).await?; - - Ok(upid) -} - -#[api( - input: { - properties: { - remote: { - schema: REMOTE_ID_SCHEMA, - }, - node: { - schema: NODE_SCHEMA, - }, - options: { - type: APTGetChangelogOptions, - flatten: true, - }, - }, - }, - returns: { - description: "The Package changelog.", - type: String, - }, - access: { - permission: &Permission::Privilege(&["resource", "{remote}", "node", "{node}", "system"], PRIV_RESOURCE_MODIFY, false), - }, -)] -/// Retrieve the changelog of the specified package for a remote PVE node. -async fn apt_get_changelog( - remote: String, - node: String, - options: APTGetChangelogOptions, -) -> Result { - let (config, _digest) = pdm_config::remotes::config()?; - let remote = get_remote(&config, &remote)?; - - remote_updates::get_changelog(remote.clone(), &node, options.name).await -} - -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), - ), -]; - -pub const ROUTER: Router = Router::new() - .get(&list_subdirs_api_method!(SUBDIRS)) - .subdirs(SUBDIRS); diff --git a/server/src/api/pve/mod.rs b/server/src/api/pve/mod.rs index a94ab8d0..fd4ea542 100644 --- a/server/src/api/pve/mod.rs +++ b/server/src/api/pve/mod.rs @@ -33,7 +33,6 @@ use crate::connection::PveClient; use crate::connection::{self, probe_tls_connection}; use crate::remote_tasks; -mod apt; mod lxc; mod node; mod qemu; diff --git a/server/src/api/pve/node.rs b/server/src/api/pve/node.rs index 1924e252..301c0b19 100644 --- a/server/src/api/pve/node.rs +++ b/server/src/api/pve/node.rs @@ -15,7 +15,7 @@ pub const ROUTER: Router = Router::new() #[sortable] const SUBDIRS: SubdirMap = &sorted!([ - ("apt", &super::apt::ROUTER), + ("apt", &crate::api::remote_updates::APT_ROUTER), ("rrddata", &super::rrddata::NODE_RRD_ROUTER), ("network", &Router::new().get(&API_METHOD_GET_NETWORK)), ("storage", &STORAGE_ROUTER), diff --git a/server/src/api/remote_updates.rs b/server/src/api/remote_updates.rs index 724b705a..5907259f 100644 --- a/server/src/api/remote_updates.rs +++ b/server/src/api/remote_updates.rs @@ -2,10 +2,13 @@ use anyhow::Error; -use pdm_api_types::remote_updates::UpdateSummary; use pdm_api_types::remotes::Remote; -use pdm_api_types::{PRIV_RESOURCE_MODIFY, UPID}; +use pdm_api_types::{ + remote_updates::UpdateSummary, remotes::REMOTE_ID_SCHEMA, RemoteUpid, NODE_SCHEMA, + PRIV_RESOURCE_MODIFY, UPID, +}; use proxmox_access_control::CachedUserInfo; +use proxmox_apt_api_types::{APTGetChangelogOptions, APTUpdateInfo}; use proxmox_rest_server::WorkerTask; use proxmox_router::{ http_bail, list_subdirs_api_method, Permission, Router, RpcEnvironment, SubdirMap, @@ -15,6 +18,8 @@ use proxmox_sortable_macro::sortable; use crate::remote_updates; +use super::remotes::get_remote; + pub const ROUTER: Router = Router::new() .get(&list_subdirs_api_method!(SUBDIRS)) .subdirs(SUBDIRS); @@ -106,3 +111,112 @@ pub fn refresh_remote_update_summaries(rpcenv: &mut dyn RpcEnvironment) -> Resul upid_str.parse() } + +#[api( + input: { + properties: { + remote: { + schema: REMOTE_ID_SCHEMA, + }, + node: { + schema: NODE_SCHEMA, + }, + }, + }, + returns: { + description: "A list of packages with available updates.", + type: Array, + items: { + type: APTUpdateInfo + }, + }, + access: { + permission: &Permission::Privilege(&["resource", "{remote}", "node", "{node}", "system"], PRIV_RESOURCE_MODIFY, false), + }, +)] +/// List available APT updates for a remote PVE node. +async fn apt_update_available(remote: String, node: String) -> Result, Error> { + let (config, _digest) = pdm_config::remotes::config()?; + let remote = get_remote(&config, &remote)?; + + let updates = remote_updates::list_available_updates(remote.clone(), &node).await?; + + Ok(updates) +} + +#[api( + input: { + properties: { + remote: { + schema: REMOTE_ID_SCHEMA, + }, + node: { + schema: NODE_SCHEMA, + }, + }, + }, + access: { + permission: &Permission::Privilege(&["resource", "{remote}", "node", "{node}", "system"], PRIV_RESOURCE_MODIFY, false), + }, +)] +/// Update the APT database of a remote PVE node. +pub async fn apt_update_database(remote: String, node: String) -> Result { + let (config, _digest) = pdm_config::remotes::config()?; + let remote = get_remote(&config, &remote)?; + + let upid = remote_updates::update_apt_database(remote, &node).await?; + + Ok(upid) +} + +#[api( + input: { + properties: { + remote: { + schema: REMOTE_ID_SCHEMA, + }, + node: { + schema: NODE_SCHEMA, + }, + options: { + type: APTGetChangelogOptions, + flatten: true, + }, + }, + }, + returns: { + description: "The Package changelog.", + type: String, + }, + access: { + permission: &Permission::Privilege(&["resource", "{remote}", "node", "{node}", "system"], PRIV_RESOURCE_MODIFY, false), + }, +)] +/// Retrieve the changelog of the specified package for a remote PVE node. +async fn apt_get_changelog( + remote: String, + node: String, + options: APTGetChangelogOptions, +) -> Result { + let (config, _digest) = pdm_config::remotes::config()?; + let remote = get_remote(&config, &remote)?; + + remote_updates::get_changelog(remote.clone(), &node, options.name).await +} + +const APT_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), + ), +]; + +pub const APT_ROUTER: Router = Router::new() + .get(&list_subdirs_api_method!(APT_SUBDIRS)) + .subdirs(APT_SUBDIRS); -- 2.47.3 _______________________________________________ pdm-devel mailing list pdm-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel