From c6648d59c66e93b4f51d63073fc4297633806cab Mon Sep 17 00:00:00 2001 From: Christian Ebner Date: Mon, 11 Nov 2024 16:43:24 +0100 Subject: [PATCH] sync: extend sync source's list namespaces method by filter callback 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 --- src/server/pull.rs | 5 ++++- src/server/sync.rs | 15 +++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/server/pull.rs b/src/server/pull.rs index c12ecec8..e56f1dfb 100644 --- a/src/server/pull.rs +++ b/src/server/pull.rs @@ -737,7 +737,10 @@ 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 +220,7 @@ pub(crate) trait SyncSource: Send + Sync { async fn list_namespaces( &self, max_depth: &mut Option, + filter_callback: NamespaceFilter, ) -> Result, Error>; /// Lists groups within a specific namespace from the source. @@ -260,6 +263,7 @@ impl SyncSource for RemoteSource { async fn list_namespaces( &self, max_depth: &mut Option, + 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 +311,8 @@ impl SyncSource for RemoteSource { .map(|list_item| list_item.ns) .collect(); + let list = list.into_iter().filter(filter_callback).collect(); + Ok(list) } @@ -400,13 +406,18 @@ impl SyncSource for LocalSource { async fn list_namespaces( &self, max_depth: &mut Option, + 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(filter_callback).collect(); + + Ok(list) } async fn list_groups(