5
0
mirror of git://git.proxmox.com/git/proxmox-backup.git synced 2025-01-20 14:03:53 +03:00

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 <c.ebner@proxmox.com>
This commit is contained in:
Christian Ebner 2024-11-11 16:43:24 +01:00 committed by Fabian Grünbichler
parent 19a621ab98
commit c6648d59c6
2 changed files with 17 additions and 3 deletions

View File

@ -737,7 +737,10 @@ pub(crate) async fn pull_store(mut params: PullParameters) -> Result<SyncStats,
let mut namespaces = if params.source.get_ns().is_root() && old_max_depth == Some(0) {
vec![params.source.get_ns()] // backwards compat - don't query remote namespaces!
} else {
params.source.list_namespaces(&mut params.max_depth).await?
params
.source
.list_namespaces(&mut params.max_depth, Box::new(|_| true))
.await?
};
check_namespace_depth_limit(&params.source.get_ns(), &params.target.ns, &namespaces)?;

View File

@ -208,6 +208,8 @@ impl SyncSourceReader for LocalSourceReader {
}
}
pub type NamespaceFilter = Box<dyn Fn(&BackupNamespace) -> 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<usize>,
filter_callback: NamespaceFilter,
) -> Result<Vec<BackupNamespace>, 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<usize>,
filter_callback: NamespaceFilter,
) -> Result<Vec<BackupNamespace>, 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<usize>,
filter_callback: NamespaceFilter,
) -> Result<Vec<BackupNamespace>, Error> {
ListNamespacesRecursive::new_max_depth(
let list: Result<Vec<BackupNamespace>, 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(