]> git.proxmox.com Git - proxmox-backup.git/commitdiff
pbs-client: avoid mut self in http_client methods.
authorDietmar Maurer <dietmar@proxmox.com>
Sat, 4 Dec 2021 13:11:55 +0000 (14:11 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Sat, 4 Dec 2021 13:44:05 +0000 (14:44 +0100)
It is not necessary, so avoid it. The client can now be used
with multiple threads (without using a Mutex).

Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
pbs-client/src/http_client.rs
pbs-client/src/task_log.rs
proxmox-backup-client/src/main.rs
proxmox-backup-client/src/snapshot.rs
proxmox-backup-client/src/task.rs
src/bin/proxmox-backup-manager.rs
src/bin/proxmox-tape.rs
src/bin/proxmox_backup_debug/api.rs

index 046a7b1791a259ce212ce7fe03214df1e6743beb..2d55b3b6ff9d04d9932b606947e32a6a21b0b5e4 100644 (file)
@@ -587,7 +587,7 @@ impl HttpClient {
     }
 
     pub async fn delete(
-        &mut self,
+        &self,
         path: &str,
         data: Option<Value>,
     ) -> Result<Value, Error> {
@@ -596,7 +596,7 @@ impl HttpClient {
     }
 
     pub async fn post(
-        &mut self,
+        &self,
         path: &str,
         data: Option<Value>,
     ) -> Result<Value, Error> {
@@ -605,7 +605,7 @@ impl HttpClient {
     }
 
     pub async fn put(
-        &mut self,
+        &self,
         path: &str,
         data: Option<Value>,
     ) -> Result<Value, Error> {
@@ -614,7 +614,7 @@ impl HttpClient {
     }
 
     pub async fn download(
-        &mut self,
+        &self,
         path: &str,
         output: &mut (dyn Write + Send),
     ) -> Result<(), Error> {
@@ -651,7 +651,7 @@ impl HttpClient {
     }
 
     pub async fn upload(
-        &mut self,
+        &self,
         content_type: &str,
         body: Body,
         path: &str,
index e607829a9584bf19bb8bb3b8c6d6e28168cf3e0c..f97b982332afe8751511bf62c02fe82a3390353b 100644 (file)
@@ -18,7 +18,7 @@ use super::HttpClient;
 /// the user presses CTRL-C. Two interrupts cause an immediate end of
 /// the loop. The task may still run in that case.
 pub async fn display_task_log(
-    client: &mut HttpClient,
+    client: &HttpClient,
     upid_str: &str,
     strip_date: bool,
 ) -> Result<(), Error> {
@@ -100,7 +100,7 @@ pub async fn display_task_log(
 
 /// Display task result (upid), or view task log - depending on output format
 pub async fn view_task_result(
-    client: &mut HttpClient,
+    client: &HttpClient,
     result: Value,
     output_format: &str,
 ) -> Result<(), Error> {
index 95f82c780139e5d2b8d01df4405f9510f0669b0c..94cffa1932eab3321f298ae06d7e3b35707641fc 100644 (file)
@@ -329,7 +329,7 @@ async fn change_backup_owner(group: String, mut param: Value) -> Result<(), Erro
 
     let repo = extract_repository_from_value(&param)?;
 
-    let mut client = connect(&repo)?;
+    let client = connect(&repo)?;
 
     param.as_object_mut().unwrap().remove("repository");
 
@@ -464,7 +464,7 @@ async fn start_garbage_collection(param: Value) -> Result<Value, Error> {
 
     let output_format = get_output_format(&param);
 
-    let mut client = connect(&repo)?;
+    let client = connect(&repo)?;
 
     let path = format!("api2/json/admin/datastore/{}/gc", repo.store());
 
@@ -472,7 +472,7 @@ async fn start_garbage_collection(param: Value) -> Result<Value, Error> {
 
     record_repository(&repo);
 
-    view_task_result(&mut client, result, &output_format).await?;
+    view_task_result(&client, result, &output_format).await?;
 
     Ok(Value::Null)
 }
@@ -1310,7 +1310,7 @@ async fn prune(
 ) -> Result<Value, Error> {
     let repo = extract_repository_from_value(&param)?;
 
-    let mut client = connect(&repo)?;
+    let client = connect(&repo)?;
 
     let path = format!("api2/json/admin/datastore/{}/prune", repo.store());
 
index 55c4c33370ba73b8d33467e6b2b0095d96f73200..891b21e99c4e41b4ecd4c720fe0e04c851212d24 100644 (file)
@@ -171,7 +171,7 @@ async fn forget_snapshots(param: Value) -> Result<Value, Error> {
     let path = required_string_param(&param, "snapshot")?;
     let snapshot: BackupDir = path.parse()?;
 
-    let mut client = connect(&repo)?;
+    let client = connect(&repo)?;
 
     let path = format!("api2/json/admin/datastore/{}/snapshots", repo.store());
 
@@ -225,7 +225,7 @@ async fn upload_log(param: Value) -> Result<Value, Error> {
     let snapshot = required_string_param(&param, "snapshot")?;
     let snapshot: BackupDir = snapshot.parse()?;
 
-    let mut client = connect(&repo)?;
+    let client = connect(&repo)?;
 
     let crypto = crypto_parameters(&param)?;
 
@@ -342,7 +342,7 @@ async fn update_notes(param: Value) -> Result<Value, Error> {
     let notes = required_string_param(&param, "notes")?;
 
     let snapshot: BackupDir = path.parse()?;
-    let mut client = connect(&repo)?;
+    let client = connect(&repo)?;
 
     let path = format!("api2/json/admin/datastore/{}/notes", repo.store());
 
@@ -438,7 +438,7 @@ async fn update_protection(protected: bool, param: Value) -> Result<(), Error> {
     let path = required_string_param(&param, "snapshot")?;
 
     let snapshot: BackupDir = path.parse()?;
-    let mut client = connect(&repo)?;
+    let client = connect(&repo)?;
 
     let path = format!("api2/json/admin/datastore/{}/protected", repo.store());
 
index f879d05758f50a6f7c8731c6a417f115f4f8129e..6d7695749b21e0904efda38bf13af6ed93dfb5bd 100644 (file)
@@ -99,9 +99,9 @@ async fn task_log(param: Value) -> Result<Value, Error> {
     let repo = extract_repository_from_value(&param)?;
     let upid =  required_string_param(&param, "upid")?;
 
-    let mut client = connect(&repo)?;
+    let client = connect(&repo)?;
 
-    display_task_log(&mut client, upid, true).await?;
+    display_task_log(&client, upid, true).await?;
 
     Ok(Value::Null)
 }
@@ -125,7 +125,7 @@ async fn task_stop(param: Value) -> Result<Value, Error> {
     let repo = extract_repository_from_value(&param)?;
     let upid_str =  required_string_param(&param, "upid")?;
 
-    let mut client = connect(&repo)?;
+    let client = connect(&repo)?;
 
     let path = format!("api2/json/nodes/localhost/tasks/{}", percent_encode_component(upid_str));
     let _ = client.delete(&path, None).await?;
index 0867ce45a63e145a887a607d4711d1bfba717ff7..b62b7715107261626fe361d29562074ac6846211 100644 (file)
@@ -47,13 +47,13 @@ async fn start_garbage_collection(param: Value) -> Result<Value, Error> {
 
     let store = required_string_param(&param, "store")?;
 
-    let mut client = connect_to_localhost()?;
+    let client = connect_to_localhost()?;
 
     let path = format!("api2/json/admin/datastore/{}/gc", store);
 
     let result = client.post(&path, None).await?;
 
-    view_task_result(&mut client, result, &output_format).await?;
+    view_task_result(&client, result, &output_format).await?;
 
     Ok(Value::Null)
 }
@@ -178,9 +178,9 @@ async fn task_log(param: Value) -> Result<Value, Error> {
 
     let upid = required_string_param(&param, "upid")?;
 
-    let mut client = connect_to_localhost()?;
+    let client = connect_to_localhost()?;
 
-    display_task_log(&mut client, upid, true).await?;
+    display_task_log(&client, upid, true).await?;
 
     Ok(Value::Null)
 }
@@ -199,7 +199,7 @@ async fn task_stop(param: Value) -> Result<Value, Error> {
 
     let upid_str = required_string_param(&param, "upid")?;
 
-    let mut client = connect_to_localhost()?;
+    let client = connect_to_localhost()?;
 
     let path = format!("api2/json/nodes/localhost/tasks/{}", percent_encode_component(upid_str));
     let _ = client.delete(&path, None).await?;
@@ -263,7 +263,7 @@ async fn pull_datastore(
 
     let output_format = get_output_format(&param);
 
-    let mut client = connect_to_localhost()?;
+    let client = connect_to_localhost()?;
 
     let mut args = json!({
         "store": local_store,
@@ -281,7 +281,7 @@ async fn pull_datastore(
 
     let result = client.post("api2/json/pull", Some(args)).await?;
 
-    view_task_result(&mut client, result, &output_format).await?;
+    view_task_result(&client, result, &output_format).await?;
 
     Ok(Value::Null)
 }
@@ -315,7 +315,7 @@ async fn verify(
 
     let output_format = extract_output_format(&mut param);
 
-    let mut client = connect_to_localhost()?;
+    let client = connect_to_localhost()?;
 
     let args = json!(param);
 
@@ -323,7 +323,7 @@ async fn verify(
 
     let result = client.post(&path, Some(args)).await?;
 
-    view_task_result(&mut client, result, &output_format).await?;
+    view_task_result(&client, result, &output_format).await?;
 
     Ok(Value::Null)
 }
index eadadfa7bd09e63ce24a21ec7ee78f643eaf0f3e..1f90445279153a4c6a1335798b95ab357b13bb65 100644 (file)
@@ -146,12 +146,12 @@ async fn format_media(mut param: Value) -> Result<(), Error> {
 
     let drive = extract_drive_name(&mut param, &config)?;
 
-    let mut client = connect_to_localhost()?;
+    let client = connect_to_localhost()?;
 
     let path = format!("api2/json/tape/drive/{}/format-media", drive);
     let result = client.post(&path, Some(param)).await?;
 
-    view_task_result(&mut client, result, &output_format).await?;
+    view_task_result(&client, result, &output_format).await?;
 
     Ok(())
 }
@@ -179,12 +179,12 @@ async fn rewind(mut param: Value) -> Result<(), Error> {
 
     let drive = extract_drive_name(&mut param, &config)?;
 
-    let mut client = connect_to_localhost()?;
+    let client = connect_to_localhost()?;
 
     let path = format!("api2/json/tape/drive/{}/rewind", drive);
     let result = client.post(&path, Some(param)).await?;
 
-    view_task_result(&mut client, result, &output_format).await?;
+    view_task_result(&client, result, &output_format).await?;
 
     Ok(())
 }
@@ -212,12 +212,12 @@ async fn eject_media(mut param: Value) -> Result<(), Error> {
 
     let drive = extract_drive_name(&mut param, &config)?;
 
-    let mut client = connect_to_localhost()?;
+    let client = connect_to_localhost()?;
 
     let path = format!("api2/json/tape/drive/{}/eject-media", drive);
     let result = client.post(&path, Some(param)).await?;
 
-    view_task_result(&mut client, result, &output_format).await?;
+    view_task_result(&client, result, &output_format).await?;
 
     Ok(())
 }
@@ -248,12 +248,12 @@ async fn load_media(mut param: Value) -> Result<(), Error> {
 
     let drive = extract_drive_name(&mut param, &config)?;
 
-    let mut client = connect_to_localhost()?;
+    let client = connect_to_localhost()?;
 
     let path = format!("api2/json/tape/drive/{}/load-media", drive);
     let result = client.post(&path, Some(param)).await?;
 
-    view_task_result(&mut client, result, &output_format).await?;
+    view_task_result(&client, result, &output_format).await?;
 
     Ok(())
 }
@@ -278,7 +278,7 @@ async fn export_media(mut param: Value) -> Result<(), Error> {
 
     let drive = extract_drive_name(&mut param, &config)?;
 
-    let mut client = connect_to_localhost()?;
+    let client = connect_to_localhost()?;
 
     let path = format!("api2/json/tape/drive/{}/export-media", drive);
     client.put(&path, Some(param)).await?;
@@ -308,7 +308,7 @@ async fn load_media_from_slot(mut param: Value) -> Result<(), Error> {
 
     let drive = extract_drive_name(&mut param, &config)?;
 
-    let mut client = connect_to_localhost()?;
+    let client = connect_to_localhost()?;
 
     let path = format!("api2/json/tape/drive/{}/load-slot", drive);
     client.put(&path, Some(param)).await?;
@@ -345,12 +345,12 @@ async fn unload_media(mut param: Value) -> Result<(), Error> {
 
     let drive = extract_drive_name(&mut param, &config)?;
 
-    let mut client = connect_to_localhost()?;
+    let client = connect_to_localhost()?;
 
     let path = format!("api2/json/tape/drive/{}/unload", drive);
     let result = client.post(&path, Some(param)).await?;
 
-    view_task_result(&mut client, result, &output_format).await?;
+    view_task_result(&client, result, &output_format).await?;
 
     Ok(())
 }
@@ -385,12 +385,12 @@ async fn label_media(mut param: Value) -> Result<(), Error> {
 
     let drive = extract_drive_name(&mut param, &config)?;
 
-    let mut client = connect_to_localhost()?;
+    let client = connect_to_localhost()?;
 
     let path = format!("api2/json/tape/drive/{}/label-media", drive);
     let result = client.post(&path, Some(param)).await?;
 
-    view_task_result(&mut client, result, &output_format).await?;
+    view_task_result(&client, result, &output_format).await?;
 
     Ok(())
 }
@@ -484,7 +484,7 @@ async fn inventory(
 
     let do_read = read_labels.unwrap_or(false) || read_all_labels.unwrap_or(false);
 
-    let mut client = connect_to_localhost()?;
+    let client = connect_to_localhost()?;
 
     let path = format!("api2/json/tape/drive/{}/inventory", drive);
 
@@ -496,7 +496,7 @@ async fn inventory(
         }
 
         let result = client.put(&path, Some(param)).await?; // update inventory
-        view_task_result(&mut client, result, &output_format).await?;
+        view_task_result(&client, result, &output_format).await?;
     }
 
     let mut result = client.get(&path, None).await?;
@@ -541,12 +541,12 @@ async fn barcode_label_media(mut param: Value) -> Result<(), Error> {
 
     let drive = extract_drive_name(&mut param, &config)?;
 
-    let mut client = connect_to_localhost()?;
+    let client = connect_to_localhost()?;
 
     let path = format!("api2/json/tape/drive/{}/barcode-label-media", drive);
     let result = client.post(&path, Some(param)).await?;
 
-    view_task_result(&mut client, result, &output_format).await?;
+    view_task_result(&client, result, &output_format).await?;
 
     Ok(())
 }
@@ -819,12 +819,12 @@ async fn clean_drive(mut param: Value) -> Result<(), Error> {
 
     let drive = extract_drive_name(&mut param, &config)?;
 
-    let mut client = connect_to_localhost()?;
+    let client = connect_to_localhost()?;
 
     let path = format!("api2/json/tape/drive/{}/clean", drive);
     let result = client.put(&path, Some(param)).await?;
 
-    view_task_result(&mut client, result, &output_format).await?;
+    view_task_result(&client, result, &output_format).await?;
 
     Ok(())
 }
@@ -894,11 +894,11 @@ async fn backup(mut param: Value) -> Result<(), Error> {
 
     param["drive"] = extract_drive_name(&mut param, &config)?.into();
 
-    let mut client = connect_to_localhost()?;
+    let client = connect_to_localhost()?;
 
     let result = client.post("api2/json/tape/backup", Some(param)).await?;
 
-    view_task_result(&mut client, result, &output_format).await?;
+    view_task_result(&client, result, &output_format).await?;
 
     Ok(())
 }
@@ -949,11 +949,11 @@ async fn restore(mut param: Value) -> Result<(), Error> {
 
     param["drive"] = extract_drive_name(&mut param, &config)?.into();
 
-    let mut client = connect_to_localhost()?;
+    let client = connect_to_localhost()?;
 
     let result = client.post("api2/json/tape/restore", Some(param)).await?;
 
-    view_task_result(&mut client, result, &output_format).await?;
+    view_task_result(&client, result, &output_format).await?;
 
     Ok(())
 }
@@ -996,12 +996,12 @@ async fn catalog_media(mut param: Value)  -> Result<(), Error> {
 
     let drive = extract_drive_name(&mut param, &config)?;
 
-    let mut client = connect_to_localhost()?;
+    let client = connect_to_localhost()?;
 
     let path = format!("api2/json/tape/drive/{}/catalog", drive);
     let result = client.post(&path, Some(param)).await?;
 
-    view_task_result(&mut client, result, &output_format).await?;
+    view_task_result(&client, result, &output_format).await?;
 
     Ok(())
 }
index 4b6e9d081a626235ebab57e27414817d77a8ec57..de1b45f85e27c3ec7e29749655b6a9428c0d4736 100644 (file)
@@ -190,7 +190,7 @@ async fn call_api(
 }
 
 async fn call_api_http(method: &str, path: &str, params: Option<Value>) -> Result<Value, Error> {
-    let mut client = connect_to_localhost()?;
+    let client = connect_to_localhost()?;
 
     let path = format!(
         "api2/json/{}",
@@ -260,8 +260,8 @@ async fn call_api_and_format_result(
     if let Some(upid) = result.as_str() {
         if PROXMOX_UPID_REGEX.is_match(upid) {
             if use_http_client() {
-                let mut client = connect_to_localhost()?;
-                view_task_result(&mut client, json!({ "data": upid }), &output_format).await?;
+                let client = connect_to_localhost()?;
+                view_task_result(&client, json!({ "data": upid }), &output_format).await?;
                 return Ok(());
             }