]>
Commit | Line | Data |
---|---|---|
09281ad7 DM |
1 | package PVE::CLI::pveum; |
2 | ||
3 | use strict; | |
4 | use warnings; | |
042eaa3d | 5 | |
09281ad7 DM |
6 | use PVE::RPCEnvironment; |
7 | use PVE::API2::User; | |
8 | use PVE::API2::Group; | |
9 | use PVE::API2::Role; | |
10 | use PVE::API2::ACL; | |
11 | use PVE::API2::AccessControl; | |
369851ac | 12 | use PVE::CLIFormatter; |
09281ad7 | 13 | use PVE::CLIHandler; |
b34d76e7 | 14 | use PVE::PTY; |
369851ac | 15 | use PVE::RESTHandler; |
09281ad7 DM |
16 | |
17 | use base qw(PVE::CLIHandler); | |
18 | ||
e623414a DM |
19 | sub setup_environment { |
20 | PVE::RPCEnvironment->setup_default_cli_env(); | |
21 | } | |
22 | ||
b34d76e7 DC |
23 | sub param_mapping { |
24 | my ($name) = @_; | |
98007830 | 25 | |
b34d76e7 DC |
26 | my $mapping = { |
27 | 'change_password' => [ | |
28 | PVE::CLIHandler::get_standard_mapping('pve-password'), | |
29 | ], | |
30 | 'create_ticket' => [ | |
31 | PVE::CLIHandler::get_standard_mapping('pve-password', { | |
32 | func => sub { | |
33 | # do not accept values given on cmdline | |
34 | return PVE::PTY::read_password('Enter password: '); | |
35 | }, | |
36 | }), | |
37 | ] | |
38 | }; | |
39 | ||
40 | return $mapping->{$name}; | |
98007830 DM |
41 | } |
42 | ||
369851ac FG |
43 | my $print_api_result = sub { |
44 | my ($data, $schema, $options) = @_; | |
45 | PVE::CLIFormatter::print_api_result($data, $schema, undef, $options); | |
46 | }; | |
47 | ||
09281ad7 | 48 | our $cmddef = { |
1e41cdc9 PA |
49 | user => { |
50 | add => [ 'PVE::API2::User', 'create_user', ['userid'] ], | |
51 | modify => [ 'PVE::API2::User', 'update_user', ['userid'] ], | |
52 | delete => [ 'PVE::API2::User', 'delete_user', ['userid'] ], | |
369851ac | 53 | list => [ 'PVE::API2::User', 'index', [], {}, $print_api_result, $PVE::RESTHandler::standard_output_options], |
1e41cdc9 PA |
54 | }, |
55 | group => { | |
56 | add => [ 'PVE::API2::Group', 'create_group', ['groupid'] ], | |
57 | modify => [ 'PVE::API2::Group', 'update_group', ['groupid'] ], | |
58 | delete => [ 'PVE::API2::Group', 'delete_group', ['groupid'] ], | |
369851ac | 59 | list => [ 'PVE::API2::Group', 'index', [], {}, $print_api_result, $PVE::RESTHandler::standard_output_options], |
1e41cdc9 PA |
60 | }, |
61 | role => { | |
62 | add => [ 'PVE::API2::Role', 'create_role', ['roleid'] ], | |
63 | modify => [ 'PVE::API2::Role', 'update_role', ['roleid'] ], | |
64 | delete => [ 'PVE::API2::Role', 'delete_role', ['roleid'] ], | |
369851ac | 65 | list => [ 'PVE::API2::Role', 'index', [], {}, $print_api_result, $PVE::RESTHandler::standard_output_options], |
1e41cdc9 PA |
66 | }, |
67 | acl => { | |
68 | modify => [ 'PVE::API2::ACL', 'update_acl', ['path'], { delete => 0 }], | |
69 | delete => [ 'PVE::API2::ACL', 'update_acl', ['path'], { delete => 1 }], | |
369851ac | 70 | list => [ 'PVE::API2::ACL', 'read_acl', [], {}, $print_api_result, $PVE::RESTHandler::standard_output_options], |
1e41cdc9 | 71 | }, |
09281ad7 DM |
72 | ticket => [ 'PVE::API2::AccessControl', 'create_ticket', ['username'], undef, |
73 | sub { | |
74 | my ($res) = @_; | |
75 | print "$res->{ticket}\n"; | |
76 | }], | |
77 | ||
765305e2 | 78 | passwd => [ 'PVE::API2::AccessControl', 'change_password', ['userid'] ], |
09281ad7 | 79 | |
1e41cdc9 PA |
80 | useradd => { alias => 'user add' }, |
81 | usermod => { alias => 'user modify' }, | |
82 | userdel => { alias => 'user delete' }, | |
09281ad7 | 83 | |
1e41cdc9 PA |
84 | groupadd => { alias => 'group add' }, |
85 | groupmod => { alias => 'group modify' }, | |
86 | groupdel => { alias => 'group delete' }, | |
09281ad7 | 87 | |
1e41cdc9 PA |
88 | roleadd => { alias => 'role add' }, |
89 | rolemod => { alias => 'role modify' }, | |
90 | roledel => { alias => 'role delete' }, | |
09281ad7 | 91 | |
1e41cdc9 PA |
92 | aclmod => { alias => 'acl modify' }, |
93 | acldel => { alias => 'acl delete' }, | |
09281ad7 DM |
94 | }; |
95 | ||
96 | 1; |