]> git.proxmox.com Git - pve-access-control.git/commitdiff
convert pveum into a PVE::CLI class
authorDietmar Maurer <dietmar@proxmox.com>
Thu, 1 Oct 2015 14:44:43 +0000 (16:44 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 1 Oct 2015 14:49:37 +0000 (16:49 +0200)
Makefile
PVE/CLI/Makefile [new file with mode: 0644]
PVE/CLI/pveum.pm [new file with mode: 0755]
PVE/Makefile
pveum

index 4d7e64b26b2b2b39bb9bc74b6cb7c87fd1e663db..88a2311f0093a250f40d032eb27296dd425f614d 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -30,8 +30,8 @@ dinstall: deb
        cat $<|pod2man -n $* -s 1 -r ${VERSION} -c "Proxmox Documentation"|gzip -c9 >$@.tmp
        mv $@.tmp $@
 
-pveum.1.pod: pveum
-       perl -I. ./pveum printmanpod >$@.tmp
+pveum.1.pod: PVE/CLI/pveum.pm
+       perl -I. -T -e "use PVE::CLI::pveum; PVE::CLI::pveum->generate_pod_manpage();" >$@.tmp
        mv $@.tmp $@
 
 .PHONY: install
@@ -41,7 +41,8 @@ install: pveum.1.pod pveum.1.gz oathkeygen
        install -m 0755 pveum ${DESTDIR}${SBINDIR}
        install -m 0755 oathkeygen ${DESTDIR}${BINDIR}
        make -C PVE install
-       perl -I. ./pveum verifyapi 
+       perl -I. ./pveum verifyapi
+       perl -I. -T -e "use PVE::CLI::pveum; PVE::CLI::pveum->verify_api();"
        install -d ${DESTDIR}/usr/share/man/man1
        install -d ${DESTDIR}${PODDIR}
        install -m 0644 pveum.1.gz ${DESTDIR}/usr/share/man/man1/
diff --git a/PVE/CLI/Makefile b/PVE/CLI/Makefile
new file mode 100644 (file)
index 0000000..3054212
--- /dev/null
@@ -0,0 +1,9 @@
+SOURCES=pveum.pm
+
+.PHONY: install
+install: ${SOURCES}
+       install -d -m 0755 ${DESTDIR}${PERLDIR}/PVE/CLI
+       for i in ${SOURCES}; do install -D -m 0644 $$i ${DESTDIR}${PERLDIR}/PVE/CLI/$$i; done
+
+
+clean:
diff --git a/PVE/CLI/pveum.pm b/PVE/CLI/pveum.pm
new file mode 100755 (executable)
index 0000000..772ba29
--- /dev/null
@@ -0,0 +1,65 @@
+package PVE::CLI::pveum;
+
+use strict;
+use warnings;
+use Getopt::Long;
+use PVE::Tools qw(run_command);
+use PVE::Cluster;
+use PVE::SafeSyslog;
+use PVE::AccessControl;
+use File::Path qw(make_path remove_tree);
+use Term::ReadLine;
+use PVE::INotify;
+use PVE::RPCEnvironment;
+use PVE::API2::User;
+use PVE::API2::Group;
+use PVE::API2::Role;
+use PVE::API2::ACL;
+use PVE::API2::AccessControl;
+use PVE::JSONSchema qw(get_standard_option);
+use PVE::CLIHandler;
+
+use base qw(PVE::CLIHandler);
+
+our $cmddef = {
+    ticket => [ 'PVE::API2::AccessControl', 'create_ticket', ['username'], undef,
+               sub {
+                   my ($res) = @_;
+                   print "$res->{ticket}\n";
+               }],
+
+    passwd => [ 'PVE::API2::AccessControl', 'change_passsword', ['userid'] ],
+
+    useradd => [ 'PVE::API2::User', 'create_user', ['userid'] ],
+    usermod => [ 'PVE::API2::User', 'update_user', ['userid'] ],
+    userdel => [ 'PVE::API2::User', 'delete_user', ['userid'] ],
+
+    groupadd => [ 'PVE::API2::Group', 'create_group', ['groupid'] ],
+    groupmod => [ 'PVE::API2::Group', 'update_group', ['groupid'] ],
+    groupdel => [ 'PVE::API2::Group', 'delete_group', ['groupid'] ],
+
+    roleadd => [ 'PVE::API2::Role', 'create_role', ['roleid'] ],
+    rolemod => [ 'PVE::API2::Role', 'update_role', ['roleid'] ],
+    roledel => [ 'PVE::API2::Role', 'delete_role', ['roleid'] ],
+
+    aclmod => [ 'PVE::API2::ACL', 'update_acl', ['path'], { delete => 0 }],
+    acldel => [ 'PVE::API2::ACL', 'update_acl', ['path'], { delete => 1 }],
+};
+
+1;
+
+__END__
+
+=head1 NAME
+
+pveum - PVE User Manager
+
+=head1 SYNOPSIS
+
+=include synopsis
+
+=head1 DESCRIPTION
+
+No description available.
+
+=include pve_copyright
index 79cafae7df167f89e11b6e2b7dc4647fed5cc56d..410d9d8575981ca8953e1ad1746ce59d3ee32bc2 100644 (file)
@@ -5,4 +5,5 @@ install:
        make -C Auth install
        install -D -m 0644 AccessControl.pm ${DESTDIR}${PERLDIR}/PVE/AccessControl.pm
        install -D -m 0644 RPCEnvironment.pm ${DESTDIR}${PERLDIR}/PVE/RPCEnvironment.pm
-       make -C API2 install
\ No newline at end of file
+       make -C API2 install
+       make -C CLI install
diff --git a/pveum b/pveum
index c9d602e589869300cdd699341689d56e5f6592a2..4ab2e0c4c4b9672d68fa987103ed4bdba7b29f44 100755 (executable)
--- a/pveum
+++ b/pveum
@@ -2,32 +2,8 @@
 
 use strict;
 use warnings;
-use Getopt::Long;
-use PVE::Tools qw(run_command);
-use PVE::Cluster;
-use PVE::SafeSyslog;
-use PVE::AccessControl;
-use File::Path qw(make_path remove_tree);
-use Term::ReadLine;
-use PVE::INotify;
-use PVE::RPCEnvironment;
-use PVE::API2::User;
-use PVE::API2::Group;
-use PVE::API2::Role;
-use PVE::API2::ACL;
-use PVE::API2::AccessControl;
-use PVE::JSONSchema qw(get_standard_option);
-use PVE::CLIHandler;
 
-use base qw(PVE::CLIHandler);
-
-use Data::Dumper; # fixme: remove
-
-$ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
-
-initlog('pveum');
-
-#fixme: logging?
+use PVE::CLI::pveum;
 
 my $read_password = sub {
 
@@ -42,64 +18,9 @@ my $read_password = sub {
     return $input;
 };
 
-my $cmddef = {
-    ticket => [ 'PVE::API2::AccessControl', 'create_ticket', ['username'], undef,
-               sub {
-                   my ($res) = @_;
-                   print "$res->{ticket}\n";
-               }],
-
-    passwd => [ 'PVE::API2::AccessControl', 'change_passsword', ['userid'] ],
-
-    useradd => [ 'PVE::API2::User', 'create_user', ['userid'] ],
-    usermod => [ 'PVE::API2::User', 'update_user', ['userid'] ],
-    userdel => [ 'PVE::API2::User', 'delete_user', ['userid'] ],
-
-    groupadd => [ 'PVE::API2::Group', 'create_group', ['groupid'] ],
-    groupmod => [ 'PVE::API2::Group', 'update_group', ['groupid'] ],
-    groupdel => [ 'PVE::API2::Group', 'delete_group', ['groupid'] ],
-
-    roleadd => [ 'PVE::API2::Role', 'create_role', ['roleid'] ],
-    rolemod => [ 'PVE::API2::Role', 'update_role', ['roleid'] ],
-    roledel => [ 'PVE::API2::Role', 'delete_role', ['roleid'] ],
-
-    aclmod => [ 'PVE::API2::ACL', 'update_acl', ['path'], { delete => 0 }],
-    acldel => [ 'PVE::API2::ACL', 'update_acl', ['path'], { delete => 1 }],
-};
-
-my $cmd = shift;
-
-if (defined($cmd) && $cmd ne 'verifyapi' && $cmd ne 'printmanpod') {
-    die "please run as root\n" if $> != 0;
-
-    PVE::INotify::inotify_init();
-
-    my $rpcenv = PVE::RPCEnvironment->init('cli');
-
-    $rpcenv->init_request();
-    $rpcenv->set_language($ENV{LANG});
-    $rpcenv->set_user('root@pam'); 
-
-# autmatically generate the private key if it does not already exists
+my $prepare = sub {
+    # autmatically generate the private key if it does not already exists
     PVE::Cluster::gen_auth_key();
-}
-
-PVE::CLIHandler::handle_cmd($cmddef, "pveum", $cmd, \@ARGV, $read_password, $0);
-
-exit 0;
-
-__END__
-
-=head1 NAME
-
-pveum - PVE User Manager
-
-=head1 SYNOPSIS
-
-=include synopsis
-
-=head1 DESCRIPTION
-
-No description available.
+};
 
-=include pve_copyright
+PVE::CLI::pveum->run_cli($read_password, undef, $prepare);