From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <pbs-devel-bounces@lists.proxmox.com> Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 716621FF165 for <inbox@lore.proxmox.com>; Thu, 8 May 2025 15:06:33 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 0C7B4FE8E; Thu, 8 May 2025 15:06:51 +0200 (CEST) From: Christian Ebner <c.ebner@proxmox.com> To: pbs-devel@lists.proxmox.com Date: Thu, 8 May 2025 15:05:51 +0200 Message-Id: <20250508130555.494782-18-c.ebner@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250508130555.494782-1-c.ebner@proxmox.com> References: <20250508130555.494782-1-c.ebner@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.029 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: [pbs-devel] [RFC v2 proxmox-backup 17/21] api: namespace: add option to list all namespaces, including trashed X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion <pbs-devel.lists.proxmox.com> List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pbs-devel>, <mailto:pbs-devel-request@lists.proxmox.com?subject=unsubscribe> List-Archive: <http://lists.proxmox.com/pipermail/pbs-devel/> List-Post: <mailto:pbs-devel@lists.proxmox.com> List-Help: <mailto:pbs-devel-request@lists.proxmox.com?subject=help> List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel>, <mailto:pbs-devel-request@lists.proxmox.com?subject=subscribe> Reply-To: Proxmox Backup Server development discussion <pbs-devel@lists.proxmox.com> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pbs-devel-bounces@lists.proxmox.com Sender: "pbs-devel" <pbs-devel-bounces@lists.proxmox.com> Add an optional parameter so all namespaces can be listed, including ones which are marked as trash. This allows to display all namespace in the UI, independent of their current state. Signed-off-by: Christian Ebner <c.ebner@proxmox.com> --- src/api2/admin/namespace.rs | 28 +++++++++++++++++-------- src/bin/proxmox-backup-manager.rs | 12 ++++++++--- src/bin/proxmox_backup_manager/prune.rs | 2 +- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/api2/admin/namespace.rs b/src/api2/admin/namespace.rs index 6f70497a6..098e69ee8 100644 --- a/src/api2/admin/namespace.rs +++ b/src/api2/admin/namespace.rs @@ -75,6 +75,12 @@ pub fn create_namespace( schema: NS_MAX_DEPTH_SCHEMA, optional: true, }, + "include-trashed": { + type: bool, + optional: true, + default: false, + description: "List also namespaces marked as trash.", + } }, }, returns: pbs_api_types::ADMIN_DATASTORE_LIST_NAMESPACE_RETURN_TYPE, @@ -89,6 +95,7 @@ pub fn list_namespaces( store: String, parent: Option<BackupNamespace>, max_depth: Option<usize>, + include_trashed: bool, rpcenv: &mut dyn RpcEnvironment, ) -> Result<Vec<NamespaceListItem>, Error> { let parent = parent.unwrap_or_default(); @@ -99,14 +106,17 @@ pub fn list_namespaces( let datastore = DataStore::lookup_datastore(&store, Some(Operation::Read))?; - let iter = - match datastore.recursive_iter_backup_ns_ok(parent, max_depth, NamespaceListFilter::Active) - { - Ok(iter) => iter, - // parent NS doesn't exists and user has no privs on it, avoid info leakage. - Err(_) if parent_access.is_err() => http_bail!(FORBIDDEN, "permission check failed"), - Err(err) => return Err(err), - }; + let filter = if include_trashed { + NamespaceListFilter::All + } else { + NamespaceListFilter::Active + }; + let iter = match datastore.recursive_iter_backup_ns_ok(parent, max_depth, filter) { + Ok(iter) => iter, + // parent NS doesn't exists and user has no privs on it, avoid info leakage. + Err(_) if parent_access.is_err() => http_bail!(FORBIDDEN, "permission check failed"), + Err(err) => return Err(err), + }; let ns_to_item = |ns: BackupNamespace| -> NamespaceListItem { NamespaceListItem { ns, comment: None } }; @@ -148,7 +158,7 @@ pub fn list_namespaces( "skip-trash": { type: bool, optional: true, - default: true, + default: false, description: "Remove and namespace immediately, skip moving to trash", }, }, diff --git a/src/bin/proxmox-backup-manager.rs b/src/bin/proxmox-backup-manager.rs index d4363e717..0c4d70b41 100644 --- a/src/bin/proxmox-backup-manager.rs +++ b/src/bin/proxmox-backup-manager.rs @@ -857,8 +857,14 @@ pub fn complete_remote_datastore_namespace( Some((None, source_store)) => { let mut rpcenv = CliEnvironment::new(); rpcenv.set_auth_id(Some(String::from("root@pam"))); - crate::api2::admin::namespace::list_namespaces(source_store, None, None, &mut rpcenv) - .ok() + crate::api2::admin::namespace::list_namespaces( + source_store, + None, + None, + false, + &mut rpcenv, + ) + .ok() } _ => None, } { @@ -893,7 +899,7 @@ pub fn complete_sync_local_datastore_namespace( if let Some(store) = store { if let Ok(data) = - crate::api2::admin::namespace::list_namespaces(store, None, None, &mut rpcenv) + crate::api2::admin::namespace::list_namespaces(store, None, None, false, &mut rpcenv) { for item in data { list.push(item.ns.name()); diff --git a/src/bin/proxmox_backup_manager/prune.rs b/src/bin/proxmox_backup_manager/prune.rs index 923eb6f51..b57c39bd7 100644 --- a/src/bin/proxmox_backup_manager/prune.rs +++ b/src/bin/proxmox_backup_manager/prune.rs @@ -164,7 +164,7 @@ fn complete_prune_local_datastore_namespace( if let Some(store) = store { if let Ok(data) = - crate::api2::admin::namespace::list_namespaces(store, None, None, &mut rpcenv) + crate::api2::admin::namespace::list_namespaces(store, None, None, false, &mut rpcenv) { for item in data { list.push(item.ns.name()); -- 2.39.5 _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel