[pbs-devel] [PATCH proxmox-backup-qemu 2/2] use new HttpClientOptions constructors

Fabian Grünbichler f.gruenbichler at proxmox.com
Mon Jan 25 14:43:02 CET 2021


and make password non-optional from the start.

Signed-off-by: Fabian Grünbichler <f.gruenbichler at proxmox.com>
---

Notes:
    needs corresponding proxmox_backup commit

 src/backup.rs  | 7 ++++---
 src/lib.rs     | 8 +++++---
 src/restore.rs | 7 ++++---
 3 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/src/backup.rs b/src/backup.rs
index b5e1263..e2062e7 100644
--- a/src/backup.rs
+++ b/src/backup.rs
@@ -107,9 +107,10 @@ impl BackupTask {
         self.check_aborted()?;
 
         let command_future = async  {
-            let options = HttpClientOptions::new()
-                .fingerprint(self.setup.fingerprint.clone())
-                .password(self.setup.password.clone());
+            let options = HttpClientOptions::new_non_interactive(
+                self.setup.password.clone(),
+                self.setup.fingerprint.clone(),
+            );
 
             let http = HttpClient::new(&self.setup.host, self.setup.port, &self.setup.auth_id, options)?;
             let writer = BackupWriter::start(
diff --git a/src/lib.rs b/src/lib.rs
index b755014..fd7c064 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -134,7 +134,7 @@ pub(crate) struct BackupSetup {
     pub backup_type: String,
     pub backup_id: String,
     pub backup_time: i64,
-    pub password: Option<String>,
+    pub password: String,
     pub keyfile: Option<std::path::PathBuf>,
     pub key_password: Option<String>,
     pub fingerprint: Option<String>,
@@ -222,7 +222,8 @@ pub extern "C" fn proxmox_backup_new(
         let backup_id = tools::utf8_c_string(backup_id)?
             .ok_or_else(|| format_err!("backup_id must not be NULL"))?;
 
-        let password = tools::utf8_c_string(password)?;
+        let password = tools::utf8_c_string(password)?
+            .ok_or_else(|| format_err!("password must not be NULL"))?;
         let keyfile = tools::utf8_c_string(keyfile)?.map(std::path::PathBuf::from);
         let key_password = tools::utf8_c_string(key_password)?;
         let fingerprint = tools::utf8_c_string(fingerprint)?;
@@ -701,7 +702,8 @@ pub extern "C" fn proxmox_restore_new(
         let backup_id = snapshot.group().backup_id().to_owned();
         let backup_time = snapshot.backup_time();
 
-        let password = tools::utf8_c_string(password)?;
+        let password = tools::utf8_c_string(password)?
+            .ok_or_else(|| format_err!("password must not be null"))?;
         let keyfile = tools::utf8_c_string(keyfile)?.map(std::path::PathBuf::from);
         let key_password = tools::utf8_c_string(key_password)?;
         let fingerprint = tools::utf8_c_string(fingerprint)?;
diff --git a/src/restore.rs b/src/restore.rs
index 1cc99a6..0790d7f 100644
--- a/src/restore.rs
+++ b/src/restore.rs
@@ -75,9 +75,10 @@ impl RestoreTask {
 
     pub async fn connect(&self) -> Result<libc::c_int, Error> {
 
-        let options = HttpClientOptions::new()
-            .fingerprint(self.setup.fingerprint.clone())
-            .password(self.setup.password.clone());
+        let options = HttpClientOptions::new_non_interactive(
+            self.setup.password.clone(),
+            self.setup.fingerprint.clone(),
+        );
 
         let http = HttpClient::new(&self.setup.host, self.setup.port, &self.setup.auth_id, options)?;
         let client = BackupReader::start(
-- 
2.20.1






More information about the pbs-devel mailing list