Select Git revision
Elasticsearch.pm
TA.pm 3.73 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!");
sub load_config_if_possible ($homestr) {
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';
}
}
return 1;
}
sub load_cache_if_possible ($homestr) {
my $home = path($homestr);
if ($home->is_dir() && !$home->is_rootdir) {
$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};
}
}
return 1;
}
BEGIN {
my $rx_psep = qr{[/\\]};
my $rx_abs = qr{[A-Z]:};
my $rx_sub = qr{([[:print:]]+)};
if ($ENV{'HOME'} =~ m{^(($rx_abs)?($rx_psep$rx_sub)+)$}m) {
load_config_if_possible($1);
load_cache_if_possible($1);
}
}
sub _override_config ($override, $opt) {
#no warnings;
if (
(exists $opt->{$override})
and ($config{$override} ne $opt->{$override})
) {