]> git.proxmox.com Git - pmg-api.git/commitdiff
pmgsh: initialize RPC/REST environment late
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 26 Jun 2023 13:12:22 +0000 (15:12 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 26 Jun 2023 13:13:42 +0000 (15:13 +0200)
other wise a (s)build gets broken in restricted & clean environments.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
src/bin/pmgsh

index 114b98aecb3d0dc0a03f74252505db08cab2ab5a..f9816cd7e177ada7dcaf0a73305dd2e00207e134 100755 (executable)
@@ -21,13 +21,6 @@ use PMG::API2;
 
 use JSON;
 
-PMG::RESTEnvironment->setup_default_cli_env();
-
-my $rpcenv = PMG::RESTEnvironment->get();
-
-my $logid = $ENV{PVE_LOG_ID} || 'pmgsh';
-initlog($logid);
-
 my $basedir = '/api2/json';
 
 my $cdir = '';
@@ -67,8 +60,9 @@ if ($cmd) {
     if ($cmd eq 'verifyapi') {
        PVE::RESTHandler::validate_method_schemas();
        exit 0;
-    } elsif ($cmd eq 'ls' || $cmd eq 'get' || $cmd eq 'create' || 
-            $cmd eq 'set' || $cmd eq 'delete' ||$cmd eq 'help' ) {
+    } elsif ($cmd =~ /^(?:ls|get|create|set|delete|help)$/) {
+       PMG::RESTEnvironment->setup_default_cli_env(); # only set up once actually required
+       initlog($ENV{PVE_LOG_ID} || 'pmgsh');
        pmg_command([ $cmd, @ARGV],  $opt_nooutput);
        exit(0);
     } else {
@@ -82,6 +76,11 @@ if (scalar (@ARGV) != 0) {
     exit(-1);
 }
 
+# only set up once actually required allows calling verifyapi in restriced clean sbuild env
+PMG::RESTEnvironment->setup_default_cli_env();
+my $rpcenv = PMG::RESTEnvironment->get();
+initlog($ENV{PVE_LOG_ID} || 'pmgsh');
+
 print "entering PMG shell - type 'help' for help\n";
 
 my $term = new Term::ReadLine('pmgsh');