make read_password a CLIHandler class method

And use new run_cli_handler() method.
This commit is contained in:
Dietmar Maurer 2015-10-02 10:45:58 +02:00
parent 90399ca489
commit 98007830ee
2 changed files with 13 additions and 14 deletions

View File

@ -21,6 +21,18 @@ use PVE::CLIHandler;
use base qw(PVE::CLIHandler);
sub read_password {
# return $ENV{PVE_PW_TICKET} if defined($ENV{PVE_PW_TICKET});
my $term = new Term::ReadLine ('pveum');
my $attribs = $term->Attribs;
$attribs->{redisplay_function} = $attribs->{shadow_redisplay};
my $input = $term->readline('Enter new password: ');
my $conf = $term->readline('Retype new password: ');
die "Passwords do not match.\n" if ($input ne $conf);
return $input;
}
our $cmddef = {
ticket => [ 'PVE::API2::AccessControl', 'create_ticket', ['username'], undef,
sub {

15
pveum
View File

@ -5,22 +5,9 @@ use warnings;
use PVE::CLI::pveum;
my $read_password = sub {
# return $ENV{PVE_PW_TICKET} if defined($ENV{PVE_PW_TICKET});
my $term = new Term::ReadLine ('pveum');
my $attribs = $term->Attribs;
$attribs->{redisplay_function} = $attribs->{shadow_redisplay};
my $input = $term->readline('Enter new password: ');
my $conf = $term->readline('Retype new password: ');
die "Passwords do not match.\n" if ($input ne $conf);
return $input;
};
my $prepare = sub {
# autmatically generate the private key if it does not already exists
PVE::Cluster::gen_auth_key();
};
PVE::CLI::pveum->run_cli($read_password, undef, $prepare);
PVE::CLI::pveum->run_cli_handler(prepare => $prepare);