Select Git revision
TA.pm 3.41 KiB
package SLUB::LZA::TA;
use v5.36;
use Path::Tiny qw( path );
use YAML qw(LoadFile);
use LWP::UserAgent;
use SOAP::Lite;
use Carp qw( croak );
use Regexp::Optimizer;
use IO::Zlib;
use Text::CSV_PP;
use SLUB::LZA::TA::Crypt;
use namespace::clean;
use App::Cmd::Setup -app;
# VERSION
# ABSTRACT: main module for ta-tool
our %config;
our %cache;
our $cache_path;
our $SALT = pack("H16", "There is no security by obscurity!");
BEGIN {
my $rx_psep = qr{[/\\]};
my $rx_abs = qr{[A-Z]:};
my $rx_sub = qr{([[:print:]]+)};
$ENV{'HOME'} =~ m{^(($rx_abs)?($rx_psep$rx_sub)+)$}m;
# untaint $homestr
my $homestr = $1;
my $home = path($homestr);
if ($home->is_dir() && !$home->is_rootdir) {
my $config_path = $home->child('.config')->child('ta-tool.rc');
our $config_file = $config_path;
if ($config_path->is_file) {
my $config_ref = YAML::LoadFile($config_path);
if (defined $config_ref->{password}) {
$config_ref->{decrypted_password} = SLUB::LZA::TA::Crypt::decrypt($config_ref->{password});
}
%config = %{$config_ref};
$config{elasticsearch_protocol} = $config{http_only} ? 'http' : 'https';
}
$cache_path = $home->child('.cache')->child('ta-tool.cache');
if ($cache_path->is_file and -s $cache_path < 8192 * 1024) { # if size > 8MB, write new at end, see END{}-block
my $cache_ref = YAML::LoadFile($cache_path);
%cache = %{$cache_ref};
}
}
}
sub common_global_validate ($self, $opt, $args) {
no warnings;
foreach my $override (qw(elasticsearch_host elasticsearch_port http_only permanent_volume)) {
if (
(exists $opt->{$override})
and ($config{$override} ne $opt->{$override})
) {
say STDERR <<"HINT";
Hint: override local config with:
$override => $opt->{$override} (config: $config{$override})
HINT
$config{$override} = $opt->{$override};
}
}
use warnings;
# option overrides config
$config{elasticsearch_protocol} = $config{http_only} ? 'http' : 'https';
foreach my $volume (@{ $SLUB::LZA::TA::config{permanent_volume} }) {
if (! -d "$volume") {$self->usage_error("given volume '$volume', does not exist or readable, $!");}