From 8d7e2ef79f500056287324050b1299f52cc78a26 Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Wed, 7 Dec 2022 08:40:11 +0100 Subject: [PATCH] mxproxmox: Move ua creation into subroutine We want to add a command which doesn't need to run with privileges to read the credential file. Initialization of the ua needs to read the credential file. Factor out the code to initialize the ua so that we can make that optional on a per-command basis. --- mxproxmox/mxproxmox | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/mxproxmox/mxproxmox b/mxproxmox/mxproxmox index 57c0b40..0a81bf7 100755 --- a/mxproxmox/mxproxmox +++ b/mxproxmox/mxproxmox @@ -37,7 +37,6 @@ sub read_cred_file { chomp($PBS_PASSWORD); $ENV{'PBS_PASSWORD'} = $PBS_PASSWORD; } -read_cred_file(); my $hostname = `hostname -s`;chomp $hostname; @@ -77,8 +76,11 @@ sub do_map { return (@out); } -my $ua = new LWP::UserAgent( ssl_opts => { verify_hostname => 0 } ); -$ua->default_header( Authorization => 'PBSAPIToken mariux64@pbs!backup:'.$PBS_PASSWORD ); +our $ua; +sub init_ua { + $ua = new LWP::UserAgent( ssl_opts => { verify_hostname => 0 } ); + $ua->default_header( Authorization => 'PBSAPIToken mariux64@pbs!backup:'.$PBS_PASSWORD ); +} sub get { my ($path) = @_; @@ -266,6 +268,9 @@ sub cmd_tclient { sys(@cmd); } +read_cred_file(); +init_ua(); + @ARGV >= 1 or die USAGE; my ($cmd,@rest) = shift; if ($cmd eq 'test') {