Skip to content
Snippets Groups Projects
Select Git revision
  • 6d4ce4fd161cd6ba166a0505d1e0b932f18b7076
  • master default protected
  • diag
  • version1.3-archivematica
  • version1.2-archivematica
  • version1.1-archivematica
  • version1.0-archivematica
  • version1.0-rosetta
8 results

TA.pm

Blame
  • TA.pm 3.92 KiB
    package SLUB::LZA::TA;
    use v5.36;
    use Path::Tiny qw( path );
    use Carp qw( croak );
    use Data::Printer;
    use IO::Zlib;
    use LWP::UserAgent;
    use Regexp::Optimizer;
    use SLUB::LZA::TA::Crypt;
    use SOAP::Lite;
    use Text::CSV_PP;
    use YAML qw(LoadFile);
    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) {
        if (exists $opt->{$override}) {
            if (!exists $config{$override}) {
                $config{$override} = $opt->{$override};
            }