From 1f71e44172b89fa2a4c450ab22500c0522a731aa Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Sat, 14 May 2022 17:16:25 +0200 Subject: [PATCH] client: make change-owner and prune namespace aware Signed-off-by: Thomas Lamprecht --- proxmox-backup-client/src/main.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/proxmox-backup-client/src/main.rs b/proxmox-backup-client/src/main.rs index 0547a528..b82746e5 100644 --- a/proxmox-backup-client/src/main.rs +++ b/proxmox-backup-client/src/main.rs @@ -354,6 +354,10 @@ fn merge_group_into(to: &mut serde_json::Map, group: BackupGroup) type: String, description: "Backup group.", }, + "ns": { + type: BackupNamespace, + optional: true, + }, "new-owner": { type: Authid, }, @@ -363,6 +367,7 @@ fn merge_group_into(to: &mut serde_json::Map, group: BackupGroup) /// Change owner of a backup group async fn change_backup_owner(group: String, mut param: Value) -> Result<(), Error> { let repo = extract_repository_from_value(¶m)?; + let ns = optional_ns_param(¶m)?; let client = connect(&repo)?; @@ -371,6 +376,9 @@ async fn change_backup_owner(group: String, mut param: Value) -> Result<(), Erro let group: BackupGroup = group.parse()?; merge_group_into(param.as_object_mut().unwrap(), group); + if !ns.is_root() { + param["ns"] = serde_json::to_value(ns)?; + } let path = format!("api2/json/admin/datastore/{}/change-owner", repo.store()); client.post(&path, Some(param)).await?; @@ -1234,11 +1242,7 @@ async fn restore(param: Value) -> Result { let client = connect_rate_limited(&repo, rate_limit)?; record_repository(&repo); - let ns = match param.get("ns") { - Some(Value::String(ns)) => ns.parse()?, - Some(_) => bail!("invalid namespace parameter"), - None => BackupNamespace::root(), - }; + let ns = optional_ns_param(¶m)?; let path = json::required_string_param(¶m, "snapshot")?; let backup_dir = dir_or_last_from_group(&client, &repo, &ns, &path).await?; @@ -1413,6 +1417,10 @@ async fn restore(param: Value) -> Result { type: String, description: "Backup group", }, + ns: { + type: BackupNamespace, + optional: true, + }, "prune-options": { type: PruneOptions, flatten: true, @@ -1443,6 +1451,7 @@ async fn prune( mut param: Value, ) -> Result { let repo = extract_repository_from_value(¶m)?; + let ns = optional_ns_param(¶m)?; let client = connect(&repo)?; @@ -1457,6 +1466,9 @@ async fn prune( api_param["dry-run"] = dry_run.into(); } merge_group_into(api_param.as_object_mut().unwrap(), group); + if !ns.is_root() { + api_param["ns"] = serde_json::to_value(ns)?; + } let mut result = client.post(&path, Some(api_param)).await?; -- 2.39.2