[pve-devel] applied: [PATCH pve-client 3/4] allow to setup remotes without password

Dietmar Maurer dietmar at proxmox.com
Wed Jun 6 08:15:52 CEST 2018


And query the password on demand.

Signed-off-by: Dietmar Maurer <dietmar at proxmox.com>
---
 PVE/APIClient/Commands/remote.pm |  7 ++++++-
 PVE/APIClient/Config.pm          | 12 +++++++++---
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/PVE/APIClient/Commands/remote.pm b/PVE/APIClient/Commands/remote.pm
index e8c876a..781fb63 100644
--- a/PVE/APIClient/Commands/remote.pm
+++ b/PVE/APIClient/Commands/remote.pm
@@ -61,9 +61,14 @@ __PACKAGE__->register_method ({
 
 	my $last_fp = 0;
 
+	my $password = $param->{password};
+	if (!defined($password)) {
+	    $password = PVE::PTY::read_password("Remote password: ");
+	}
+
 	my $setup = {
 	    username                => $param->{username},
-	    password                => $param->{password},
+	    password                => $password,
 	    host                    => $param->{host},
 	    port                    => $param->{port} // 8006,
 	};
diff --git a/PVE/APIClient/Config.pm b/PVE/APIClient/Config.pm
index 65c555f..8fa7691 100644
--- a/PVE/APIClient/Config.pm
+++ b/PVE/APIClient/Config.pm
@@ -76,7 +76,7 @@ sub options {
 	host => { optional => 0 },
 	comment => { optional => 1 },
 	username => { optional => 0 },
-	password => { optional => 0 },
+	password => { optional => 1 },
 	port => { optional => 1 },
 	fingerprint => { optional => 1 },
    };
@@ -138,11 +138,17 @@ sub remote_conn {
     my ($class, $cfg, $remote) = @_;
 
     my $section = $class->lookup_remote($cfg, $remote);
+
+    my $password = $section->{password};
+    if (!defined($password)) {
+	$password = PVE::PTY::read_password("Remote password: ")
+    }
+
     my $conn = PVE::APIClient::LWP->new(
 	username                => $section->{username},
-	password                => $section->{password},
+	password                => $password,
 	host                    => $section->{host},
-	port                    => $section->{port},
+	port                    => $section->{port} // 8006,
 	cached_fingerprints     => {
 	    $section->{fingerprint} => 1,
 	}
-- 
2.11.0



More information about the pve-devel mailing list