]> git.proxmox.com Git - proxmox-backup.git/commitdiff
client: more backup namespace support
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Mon, 25 Apr 2022 09:23:15 +0000 (11:23 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 12 May 2022 07:33:50 +0000 (09:33 +0200)
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
proxmox-backup-client/src/main.rs
proxmox-backup-client/src/snapshot.rs
src/api2/admin/datastore.rs

index 5b5a791500c9ccff894bc61be036921de2c3fc44..4fd9156375f3bcd2a5336aca2cd6fa704e1b450f 100644 (file)
@@ -134,11 +134,10 @@ async fn api_datastore_list_snapshots(
 ) -> Result<Value, Error> {
     let path = format!("api2/json/admin/datastore/{}/snapshots", store);
 
-    let mut args = json!({});
-    if let Some(group) = group {
-        args["backup-type"] = group.ty.to_string().into();
-        args["backup-id"] = group.id.into();
-    }
+    let args = match group {
+        Some(group) => serde_json::to_value(group)?,
+        None => json!({}),
+    };
 
     let mut result = client.get(&path, Some(args)).await?;
 
@@ -243,6 +242,10 @@ async fn backup_image<P: AsRef<Path>>(
                 schema: REPO_URL_SCHEMA,
                 optional: true,
             },
+            "ns": {
+                type: BackupNamespace,
+                optional: true,
+            },
             "output-format": {
                 schema: OUTPUT_FORMAT,
                 optional: true,
@@ -260,7 +263,13 @@ async fn list_backup_groups(param: Value) -> Result<Value, Error> {
 
     let path = format!("api2/json/admin/datastore/{}/groups", repo.store());
 
-    let mut result = client.get(&path, None).await?;
+    let backup_ns: BackupNamespace = match &param["ns"] {
+        Value::String(s) => s.parse()?,
+        _ => BackupNamespace::root(),
+    };
+    let mut result = client
+        .get(&path, Some(json!({ "backup-ns": backup_ns })))
+        .await?;
 
     record_repository(&repo);
 
@@ -309,6 +318,13 @@ async fn list_backup_groups(param: Value) -> Result<Value, Error> {
     Ok(Value::Null)
 }
 
+fn merge_group_into(to: &mut serde_json::Map<String, Value>, group: BackupGroup) {
+    match serde_json::to_value(group).unwrap() {
+        Value::Object(group) => to.extend(group),
+        _ => unreachable!(),
+    }
+}
+
 #[api(
    input: {
         properties: {
@@ -336,8 +352,7 @@ async fn change_backup_owner(group: String, mut param: Value) -> Result<(), Erro
 
     let group: BackupGroup = group.parse()?;
 
-    param["backup-type"] = group.ty.to_string().into();
-    param["backup-id"] = group.id.into();
+    merge_group_into(param.as_object_mut().unwrap(), group);
 
     let path = format!("api2/json/admin/datastore/{}/change-owner", repo.store());
     client.post(&path, Some(param)).await?;
@@ -1419,8 +1434,7 @@ async fn prune(
     if let Some(dry_run) = dry_run {
         api_param["dry-run"] = dry_run.into();
     }
-    api_param["backup-type"] = group.ty.to_string().into();
-    api_param["backup-id"] = group.id.into();
+    merge_group_into(api_param.as_object_mut().unwrap(), group);
 
     let mut result = client.post(&path, Some(api_param)).await?;
 
index 75f6d327eca58b4fcc0ae5d5944cca9142f5e77a..79d9ba56fcaf8c67520124b4811893c03fdfe7ac 100644 (file)
@@ -122,14 +122,7 @@ async fn list_snapshot_files(param: Value) -> Result<Value, Error> {
     let path = format!("api2/json/admin/datastore/{}/files", repo.store());
 
     let mut result = client
-        .get(
-            &path,
-            Some(json!({
-                "backup-type": snapshot.group.ty,
-                "backup-id": snapshot.group.id,
-                "backup-time": snapshot.time,
-            })),
-        )
+        .get(&path, Some(serde_json::to_value(snapshot)?))
         .await?;
 
     record_repository(&repo);
@@ -171,14 +164,7 @@ async fn forget_snapshots(param: Value) -> Result<Value, Error> {
     let path = format!("api2/json/admin/datastore/{}/snapshots", repo.store());
 
     let result = client
-        .delete(
-            &path,
-            Some(json!({
-                "backup-type": snapshot.group.ty,
-                "backup-id": snapshot.group.id,
-                "backup-time": snapshot.time,
-            })),
-        )
+        .delete(&path, Some(serde_json::to_value(snapshot)?))
         .await?;
 
     record_repository(&repo);
@@ -290,11 +276,7 @@ async fn show_notes(param: Value) -> Result<Value, Error> {
 
     let path = format!("api2/json/admin/datastore/{}/notes", repo.store());
 
-    let args = json!({
-        "backup-type": snapshot.group.ty,
-        "backup-id": snapshot.group.id,
-        "backup-time": snapshot.time,
-    });
+    let args = serde_json::to_value(snapshot)?;
 
     let output_format = get_output_format(&param);
 
@@ -347,12 +329,8 @@ async fn update_notes(param: Value) -> Result<Value, Error> {
 
     let path = format!("api2/json/admin/datastore/{}/notes", repo.store());
 
-    let args = json!({
-        "backup-type": snapshot.group.ty,
-        "backup-id": snapshot.group.id,
-        "backup-time": snapshot.time,
-        "notes": notes,
-    });
+    let mut args = serde_json::to_value(snapshot)?;
+    args["notes"] = Value::from(notes);
 
     client.put(&path, Some(args)).await?;
 
@@ -387,11 +365,7 @@ async fn show_protection(param: Value) -> Result<(), Error> {
 
     let path = format!("api2/json/admin/datastore/{}/protected", repo.store());
 
-    let args = json!({
-        "backup-type": snapshot.group.ty,
-        "backup-id": snapshot.group.id,
-        "backup-time": snapshot.time,
-    });
+    let args = serde_json::to_value(snapshot)?;
 
     let output_format = get_output_format(&param);
 
@@ -443,12 +417,8 @@ async fn update_protection(protected: bool, param: Value) -> Result<(), Error> {
 
     let path = format!("api2/json/admin/datastore/{}/protected", repo.store());
 
-    let args = json!({
-        "backup-type": snapshot.group.ty,
-        "backup-id": snapshot.group.id,
-        "backup-time": snapshot.time,
-        "protected": protected,
-    });
+    let mut args = serde_json::to_value(snapshot)?;
+    args["protected"] = Value::from(protected);
 
     client.put(&path, Some(args)).await?;
 
index a083a4a9942f8db252c28200188531535750afc8..49fa01e8a5f343e973f55ec12c226c5e24f4342d 100644 (file)
@@ -147,6 +147,10 @@ fn get_all_snapshot_files(
             store: {
                 schema: DATASTORE_SCHEMA,
             },
+            "backup-ns": {
+                type: BackupNamespace,
+                optional: true,
+            },
         },
     },
     returns: pbs_api_types::ADMIN_DATASTORE_LIST_GROUPS_RETURN_TYPE,
@@ -160,6 +164,7 @@ fn get_all_snapshot_files(
 /// List backup groups.
 pub fn list_groups(
     store: String,
+    backup_ns: Option<BackupNamespace>,
     rpcenv: &mut dyn RpcEnvironment,
 ) -> Result<Vec<GroupListItem>, Error> {
     let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
@@ -170,7 +175,7 @@ pub fn list_groups(
     let list_all = (user_privs & PRIV_DATASTORE_AUDIT) != 0;
 
     datastore
-        .iter_backup_groups(Default::default())? // FIXME: Namespaces and recursion parameters!
+        .iter_backup_groups(backup_ns.unwrap_or_default())? // FIXME: Namespaces and recursion parameters!
         .try_fold(Vec::new(), |mut group_info, group| {
             let group = group?;
             let owner = match datastore.get_owner(group.as_ref()) {