[pmg-devel] [PATCH 1/3] pmgsh: replace read_password with param_mapping

Thomas Lamprecht t.lamprecht at proxmox.com
Wed Jun 27 14:46:33 CEST 2018


Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
 bin/pmgsh | 24 ++++++------------------
 1 file changed, 6 insertions(+), 18 deletions(-)

diff --git a/bin/pmgsh b/bin/pmgsh
index 5447cea..63fc56a 100755
--- a/bin/pmgsh
+++ b/bin/pmgsh
@@ -11,6 +11,7 @@ use Text::ParseWords;
 use PVE::JSONSchema;
 use PVE::SafeSyslog;
 use PVE::INotify;
+use PVE::CLIHandler;
 
 use PMG::RESTEnvironment;
 
@@ -182,23 +183,10 @@ 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;
+my $param_mapping = sub {
+    my ($name) = @_;
 
-    # remove password from history
-    if ($term->Features->{autohistory}) {
-	my $historyPosition = $term->where_history();
-	$term->remove_history($historyPosition);
-	$term->remove_history($historyPosition - 1);
-    }
-
-    die "Passwords do not match.\n" if ($input ne $conf);
-    return $input;
+    return [ PVE::CLIHandler::get_standard_mapping('pve-password') ];
 };
 
 sub reverse_map_cmd {
@@ -282,7 +270,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;
 
@@ -453,7 +441,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.17.1




More information about the pmg-devel mailing list