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 D13871FF173 for ; Mon, 11 Nov 2024 16:44:36 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id A9D02FF58; Mon, 11 Nov 2024 16:44:36 +0100 (CET) From: Christian Ebner To: pbs-devel@lists.proxmox.com Date: Mon, 11 Nov 2024 16:43:24 +0100 Message-Id: <20241111154353.482734-3-c.ebner@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241111154353.482734-1-c.ebner@proxmox.com> References: <20241111154353.482734-1-c.ebner@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.030 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] [PATCH v7 proxmox-backup 02/31] sync: extend sync source's list namespaces method by filter callback X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Backup Server development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pbs-devel-bounces@lists.proxmox.com Sender: "pbs-devel" Allow to filter namespaces by given callback function. This will be used to pre-filter the list of namespaces to push to a remote target for sync jobs in push direction, based on the privs of the sync jobs local user on the source datastore. Signed-off-by: Christian Ebner --- changes since version 6: - not present in previous version src/server/pull.rs | 11 ++++++++++- src/server/sync.rs | 29 +++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/server/pull.rs b/src/server/pull.rs index c12ecec82..d059c3ff6 100644 --- a/src/server/pull.rs +++ b/src/server/pull.rs @@ -737,7 +737,16 @@ pub(crate) async fn pull_store(mut params: PullParameters) -> Result bool + Send>; + #[async_trait::async_trait] /// `SyncSource` is a trait that provides an interface for synchronizing data/information from a /// source. @@ -218,6 +222,9 @@ pub(crate) trait SyncSource: Send + Sync { async fn list_namespaces( &self, max_depth: &mut Option, + auth_id: &Authid, + user_info: &CachedUserInfo, + filter_callback: NamespaceFilter, ) -> Result, Error>; /// Lists groups within a specific namespace from the source. @@ -260,6 +267,9 @@ impl SyncSource for RemoteSource { async fn list_namespaces( &self, max_depth: &mut Option, + auth_id: &Authid, + user_info: &CachedUserInfo, + mut filter_callback: NamespaceFilter, ) -> Result, Error> { if self.ns.is_root() && max_depth.map_or(false, |depth| depth == 0) { return Ok(vec![self.ns.clone()]); @@ -307,6 +317,11 @@ impl SyncSource for RemoteSource { .map(|list_item| list_item.ns) .collect(); + let list = list + .into_iter() + .filter(|namespace| filter_callback((namespace, self.get_store(), auth_id, user_info))) + .collect(); + Ok(list) } @@ -400,13 +415,23 @@ impl SyncSource for LocalSource { async fn list_namespaces( &self, max_depth: &mut Option, + auth_id: &Authid, + user_info: &CachedUserInfo, + mut filter_callback: NamespaceFilter, ) -> Result, Error> { - ListNamespacesRecursive::new_max_depth( + let list: Result, Error> = ListNamespacesRecursive::new_max_depth( self.store.clone(), self.ns.clone(), max_depth.unwrap_or(MAX_NAMESPACE_DEPTH), )? - .collect() + .collect(); + + let list = list? + .into_iter() + .filter(|namespace| filter_callback((namespace, self.get_store(), auth_id, user_info))) + .collect(); + + Ok(list) } async fn list_groups( -- 2.39.5 _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel