Skip to content

Commit

Permalink
mxproxmox: Move ua creation into subroutine
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
donald committed Dec 7, 2022
1 parent 44b957b commit 8d7e2ef
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions mxproxmox/mxproxmox
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) = @_;
Expand Down Expand Up @@ -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') {
Expand Down

0 comments on commit 8d7e2ef

Please sign in to comment.