PVE/CLI/pveum.pm: call setup_default_cli_env()
[pve-access-control.git] / PVE / CLI / pveum.pm
1 package PVE::CLI::pveum;
2
3 use strict;
4 use warnings;
5 use Getopt::Long;
6 use PVE::Tools qw(run_command);
7 use PVE::Cluster;
8 use PVE::SafeSyslog;
9 use PVE::AccessControl;
10 use File::Path qw(make_path remove_tree);
11 use Term::ReadLine;
12 use PVE::INotify;
13 use PVE::RPCEnvironment;
14 use PVE::API2::User;
15 use PVE::API2::Group;
16 use PVE::API2::Role;
17 use PVE::API2::ACL;
18 use PVE::API2::AccessControl;
19 use PVE::JSONSchema qw(get_standard_option);
20 use PVE::CLIHandler;
21
22 use base qw(PVE::CLIHandler);
23
24 sub setup_environment {
25     PVE::RPCEnvironment->setup_default_cli_env();
26 }
27
28 sub read_password {
29     # return $ENV{PVE_PW_TICKET} if defined($ENV{PVE_PW_TICKET});
30
31     my $term = new Term::ReadLine ('pveum');
32     my $attribs = $term->Attribs;
33     $attribs->{redisplay_function} = $attribs->{shadow_redisplay};
34     my $input = $term->readline('Enter new password: ');
35     my $conf = $term->readline('Retype new password: ');
36     die "Passwords do not match.\n" if ($input ne $conf);
37     return $input;
38 }
39
40 our $cmddef = {
41     ticket => [ 'PVE::API2::AccessControl', 'create_ticket', ['username'], undef,
42                 sub {
43                     my ($res) = @_;
44                     print "$res->{ticket}\n";
45                 }],
46
47     passwd => [ 'PVE::API2::AccessControl', 'change_passsword', ['userid'] ],
48
49     useradd => [ 'PVE::API2::User', 'create_user', ['userid'] ],
50     usermod => [ 'PVE::API2::User', 'update_user', ['userid'] ],
51     userdel => [ 'PVE::API2::User', 'delete_user', ['userid'] ],
52
53     groupadd => [ 'PVE::API2::Group', 'create_group', ['groupid'] ],
54     groupmod => [ 'PVE::API2::Group', 'update_group', ['groupid'] ],
55     groupdel => [ 'PVE::API2::Group', 'delete_group', ['groupid'] ],
56
57     roleadd => [ 'PVE::API2::Role', 'create_role', ['roleid'] ],
58     rolemod => [ 'PVE::API2::Role', 'update_role', ['roleid'] ],
59     roledel => [ 'PVE::API2::Role', 'delete_role', ['roleid'] ],
60
61     aclmod => [ 'PVE::API2::ACL', 'update_acl', ['path'], { delete => 0 }],
62     acldel => [ 'PVE::API2::ACL', 'update_acl', ['path'], { delete => 1 }],
63 };
64
65 1;