mirror of
https://git.proxmox.com/git/proxmox-backup
synced 2025-08-09 15:15:28 +00: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:
parent
19a621ab98
commit
c6648d59c6
@ -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) {
|
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!
|
vec![params.source.get_ns()] // backwards compat - don't query remote namespaces!
|
||||||
} else {
|
} 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(¶ms.source.get_ns(), ¶ms.target.ns, &namespaces)?;
|
check_namespace_depth_limit(¶ms.source.get_ns(), ¶ms.target.ns, &namespaces)?;
|
||||||
|
@ -208,6 +208,8 @@ impl SyncSourceReader for LocalSourceReader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub type NamespaceFilter = Box<dyn Fn(&BackupNamespace) -> bool + Send>;
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
/// `SyncSource` is a trait that provides an interface for synchronizing data/information from a
|
/// `SyncSource` is a trait that provides an interface for synchronizing data/information from a
|
||||||
/// source.
|
/// source.
|
||||||
@ -218,6 +220,7 @@ pub(crate) trait SyncSource: Send + Sync {
|
|||||||
async fn list_namespaces(
|
async fn list_namespaces(
|
||||||
&self,
|
&self,
|
||||||
max_depth: &mut Option<usize>,
|
max_depth: &mut Option<usize>,
|
||||||
|
filter_callback: NamespaceFilter,
|
||||||
) -> Result<Vec<BackupNamespace>, Error>;
|
) -> Result<Vec<BackupNamespace>, Error>;
|
||||||
|
|
||||||
/// Lists groups within a specific namespace from the source.
|
/// Lists groups within a specific namespace from the source.
|
||||||
@ -260,6 +263,7 @@ impl SyncSource for RemoteSource {
|
|||||||
async fn list_namespaces(
|
async fn list_namespaces(
|
||||||
&self,
|
&self,
|
||||||
max_depth: &mut Option<usize>,
|
max_depth: &mut Option<usize>,
|
||||||
|
filter_callback: NamespaceFilter,
|
||||||
) -> Result<Vec<BackupNamespace>, Error> {
|
) -> Result<Vec<BackupNamespace>, Error> {
|
||||||
if self.ns.is_root() && max_depth.map_or(false, |depth| depth == 0) {
|
if self.ns.is_root() && max_depth.map_or(false, |depth| depth == 0) {
|
||||||
return Ok(vec![self.ns.clone()]);
|
return Ok(vec![self.ns.clone()]);
|
||||||
@ -307,6 +311,8 @@ impl SyncSource for RemoteSource {
|
|||||||
.map(|list_item| list_item.ns)
|
.map(|list_item| list_item.ns)
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
let list = list.into_iter().filter(filter_callback).collect();
|
||||||
|
|
||||||
Ok(list)
|
Ok(list)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -400,13 +406,18 @@ impl SyncSource for LocalSource {
|
|||||||
async fn list_namespaces(
|
async fn list_namespaces(
|
||||||
&self,
|
&self,
|
||||||
max_depth: &mut Option<usize>,
|
max_depth: &mut Option<usize>,
|
||||||
|
filter_callback: NamespaceFilter,
|
||||||
) -> Result<Vec<BackupNamespace>, Error> {
|
) -> Result<Vec<BackupNamespace>, Error> {
|
||||||
ListNamespacesRecursive::new_max_depth(
|
let list: Result<Vec<BackupNamespace>, Error> = ListNamespacesRecursive::new_max_depth(
|
||||||
self.store.clone(),
|
self.store.clone(),
|
||||||
self.ns.clone(),
|
self.ns.clone(),
|
||||||
max_depth.unwrap_or(MAX_NAMESPACE_DEPTH),
|
max_depth.unwrap_or(MAX_NAMESPACE_DEPTH),
|
||||||
)?
|
)?
|
||||||
.collect()
|
.collect();
|
||||||
|
|
||||||
|
let list = list?.into_iter().filter(filter_callback).collect();
|
||||||
|
|
||||||
|
Ok(list)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn list_groups(
|
async fn list_groups(
|
||||||
|
Loading…
Reference in New Issue
Block a user