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

report.pm

Blame
  • init.pm 2.56 KiB
    package SLUB::LZA::TA::Command::init;
    use SLUB::LZA::TA -command;
    use v5.36;
    use YAML qw(DumpFile);
    use IO::Prompt::Tiny qw/prompt/;
    use Crypt::Mode::CBC;
    use Path::Tiny;
    use namespace::autoclean -except => qr{^SLUB::LZA::TA::.*};
    
    # VERSION
    
    # ABSTRACT: init module for ta-tool
    
    sub abstract { return "Initialize $0";}
    sub description { return "Initialize $0, preparing config file using given options"}
    sub opt_spec {
        #my $common_global_opts= SLUB::LZA::TA::global_opt_spec();
        my @local_opts = (
            [ "help|h" => "this usage screen" ],
            [ "verbose|v" => "enable verbose output" ],
            [],
            [ "elasticsearch-host|e=s" => "host adress of Archivematica's ElasticSearch (mandatory)" ],
            [ "elasticsearch-port|E=s" => "port of Archivematica's ElasticSearch", { default => 9200 } ],
            [ "http-only" => "use HTTP instead HTTPS" ],
        );
            #[ "logdir|l=s" => "logdir where Archivematica stores it server log files", {required => 1}],
        # return ($global_opts, $local_opts);
        return (@local_opts);
    }
    sub validate_args {
        my ($self, $opt, $args) = @_;
        # no args allowed but options!
        $self->usage_error("No args allowed") if @$args;
        $self->usage_error("Missed mandatory parameter '--elasticsearch-host'") if (
            !exists($opt->{elasticsearch_host})
            and exists($opt->{help})
        );
        return 1;
    }
    
    sub execute {
        my ($self, $opt, $args) = @_;
        my %config;
        $config{elasticsearch_host} = $opt->{elasticsearch_host};
        $config{elasticsearch_port} = $opt->{elasticsearch_port};
        #$config{logdir} = $opt->{logdir};
        $config{http_only} = $opt->{http_only};
        my $in_test = $ENV{TEST_ACTIVE};
        local *IO::Prompt::Tiny::_is_interactive = sub {$in_test}; # fake it for testing
        say STDERR "HINT: The password  stored in config file!";
        my $user = prompt('User:');
    RETRY:
        my $passwd1 = prompt('Password:', -echo => "*");
        my $passwd2 = prompt('Password, again:', -echo => "*");
        if ($passwd1 ne $passwd2) {
            say "you typed different passwords, retry";
            goto RETRY;
        }
        $config{user} = "$user";
        $config{password} = SLUB::LZA::TA::Crypt::encrypt("$passwd1");
        if (defined $SLUB::LZA::TA::config_file) {
            if (defined $opt->{verbose}) {
                say "store config in $SLUB::LZA::TA::config_file";
            }
            my $file = path($SLUB::LZA::TA::config_file);
            $file->touch();
            $file->chmod("0600");
            my $fh = path($SLUB::LZA::TA::config_file)->filehandle({ exclusive => 0 }, ">");
            YAML::DumpFile($fh, \%config);
            $fh->close;