[pve-devel] [PATCH manager] replace read_password with param_mapping in pvesh
Dominik Csapak
d.csapak at proxmox.com
Tue Jun 12 13:27:56 CEST 2018
Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
this belongs to my series for removing 'read_password'
we also have to do the same in pmgsh if the patches get applied
to pve-common
bin/pvesh | 34 ++++++++++++++++------------------
1 file changed, 16 insertions(+), 18 deletions(-)
diff --git a/bin/pvesh b/bin/pvesh
index 36ce7636..4ab26b8f 100755
--- a/bin/pvesh
+++ b/bin/pvesh
@@ -11,6 +11,7 @@ use Getopt::Long;
use HTTP::Status qw(:constants :is status_message);
use Text::ParseWords;
use String::ShellQuote;
+use PVE::PTY;
use PVE::JSONSchema;
use PVE::SafeSyslog;
use PVE::Cluster;
@@ -184,23 +185,20 @@ sub abs_path {
return $ret;
}
-my $read_password = sub {
- my $attribs = $term->Attribs;
- my $old = $attribs->{redisplay_function};
- $attribs->{redisplay_function} = $attribs->{shadow_redisplay};
- my $input = $term->readline('password: ');
- my $conf = $term->readline('Retype new password: ');
- $attribs->{redisplay_function} = $old;
-
- # remove password from history
- if ($term->Features->{autohistory}) {
- my $historyPosition = $term->where_history();
- $term->remove_history($historyPosition);
- $term->remove_history($historyPosition - 1);
- }
+my $param_mapping = sub {
+ my ($name) = @_;
+
+ my $password_map = [
+ 'password',
+ sub {
+ my ($value) = @_;
+ return $value if $value;
+ return PVE::PTY::get_confirmed_password();
+ },
+ '<password>', 1
+ ];
- die "Passwords do not match.\n" if ($input ne $conf);
- return $input;
+ return [$password_map];
};
sub reverse_map_cmd {
@@ -279,7 +277,7 @@ sub call_method {
my ($node, $remip) = check_proxyto($info, $uri_param);
return proxy_handler($node, $remip, $dir, $cmd, $args) if $node;
- my $data = $handler->cli_handler("$cmd $dir", $info->{name}, $args, [], $uri_param, $read_password);
+ my $data = $handler->cli_handler("$cmd $dir", $info->{name}, $args, [], $uri_param, $param_mapping);
return if $nooutput;
@@ -450,7 +448,7 @@ sub list_dir {
return proxy_handler($node, $remip, $dir, 'ls', $args) if $node;
- my $data = $handler->cli_handler("ls $dir", $info->{name}, $args, [], $uri_param, $read_password);
+ my $data = $handler->cli_handler("ls $dir", $info->{name}, $args, [], $uri_param, $param_mapping);
my $lnk = PVE::JSONSchema::method_get_child_link($info);
my $children = extract_children($lnk, $data);
--
2.11.0
More information about the pve-devel
mailing list