Skip to content
Snippets Groups Projects
Commit 4f98dd71 authored by Andreas Romeyke's avatar Andreas Romeyke
Browse files

- fixed config store/load (YAML module expects hashref)

- fixed cache store/load  (YAML module expects hashref)
parent c62e0adf
No related branches found
No related tags found
No related merge requests found
...@@ -13,7 +13,6 @@ use IO::Zlib; ...@@ -13,7 +13,6 @@ use IO::Zlib;
use Text::CSV_PP; use Text::CSV_PP;
use SLUB::LZA::TA::Crypt; use SLUB::LZA::TA::Crypt;
# VERSION # VERSION
# ABSTRACT: main module for ta-tool # ABSTRACT: main module for ta-tool
...@@ -34,15 +33,17 @@ BEGIN { ...@@ -34,15 +33,17 @@ BEGIN {
my $config_path = $home->child('.config')->child('ta-tool.rc'); my $config_path = $home->child('.config')->child('ta-tool.rc');
our $config_file = $config_path; our $config_file = $config_path;
if ($config_path->is_file) { if ($config_path->is_file) {
%config = YAML::LoadFile($config_path); my $config_ref = YAML::LoadFile($config_path);
if (defined $config{password}) { if (defined $config_ref->{password}) {
warn "HINT: The password was stored in config file!"; warn "HINT: The password was stored in config file!";
$config{decrypted_password} = SLUB::LZA::Rosetta::TA::Crypt::decrypt($config{password}); $config_ref->{decrypted_password} = SLUB::LZA::TA::Crypt::decrypt($config_ref->{password});
} }
%config = %{$config_ref};
} }
$cache_path = $home->child('.cache')->child('ta-tool.cache'); $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 if ($cache_path->is_file and -s $cache_path < 8192 * 1024) { # if size > 8MB, write new at end, see END{}-block
%cache = YAML::LoadFile($cache_path); my $cache_ref = YAML::LoadFile($cache_path);
%cache = %{$cache_ref};
} }
} }
...@@ -50,7 +51,7 @@ BEGIN { ...@@ -50,7 +51,7 @@ BEGIN {
END { END {
if ($cache_path->parent->is_dir && !$cache_path->parent->parent->is_rootdir && $cache_path->touch()) { if ($cache_path->parent->is_dir && !$cache_path->parent->parent->is_rootdir && $cache_path->touch()) {
YAML::DumpFile($cache_path, %cache) YAML::DumpFile($cache_path, \%cache)
} else { } else {
warn "The $cache_path could not be written, because dir ".$cache_path->parent()." is not writeable"; warn "The $cache_path could not be written, because dir ".$cache_path->parent()." is not writeable";
} }
......
...@@ -9,20 +9,19 @@ use Crypt::Mode::CBC; ...@@ -9,20 +9,19 @@ use Crypt::Mode::CBC;
use Path::Tiny; use Path::Tiny;
use namespace::autoclean; use namespace::autoclean;
# VERSION # VERSION
# ABSTRACT: init module for ta-tool # ABSTRACT: init module for ta-tool
sub abstract {"Initialize $0";} sub abstract {"Initialize $0";}
sub description {"Initialize $0, preparing config"} sub description {"Initialize $0, preparing config file."}
sub opt_spec { sub opt_spec {
return( return(
["help|h" => "this usage screen"],
["verbose|v" => "enable verbose output"], ["verbose|v" => "enable verbose output"],
["rosettahost|r=s" => "host adress where Rosetta runs", {required=>1}], ["elasticsearchhost|e=s" => "host adress where Archivematica's ElasticSearch runs", {required=>1}],
["logdir|l=s" => "logdir where rosetta stores it server log files", {required=>1}], ["elasticsearchport|E=s" => "port of Archivematica's ElasticSearch", {default => 9200}],
["authentication|a" => "enable authentification (needed if Rosetta's general parameter 'sru_authentication=true'), password is stored salted only in config file!"], ["logdir|l=s" => "logdir where Archivematica stores it server log files", {required=>1}],
["httponly" => "with this flag only HTTP (instead HTTPS) is used"], ["httponly" => "with this flag only HTTP (instead HTTPS) is used"],
); );
} }
...@@ -35,15 +34,14 @@ sub validate_args { ...@@ -35,15 +34,14 @@ sub validate_args {
sub execute { sub execute {
my ($self, $opt, $args) = @_; my ($self, $opt, $args) = @_;
my %config; my %config;
$config{host} = $opt->{rosettahost}; $config{elasticsearchhost} = $opt->{elasticsearchhost};
$config{elasticsearchport} = $opt->{elasticsearchport};
$config{logdir} = $opt->{logdir}; $config{logdir} = $opt->{logdir};
$config{httponly} = $opt->{httponly}; $config{httponly} = $opt->{httponly};
if (defined $opt->{authentication}) { my $in_test = $ENV{TEST_ACTIVE};
local *IO::Prompt::Tiny::_is_interactive = sub {$in_test}; # fake it for testing
warn "HINT: The password will stored in config file!"; warn "HINT: The password will stored in config file!";
my $user = prompt('User:'); my $user = prompt('User:');
$config{user} = "$user";
my $institution = prompt('Institution:' );
$config{institution} = "$institution";
RETRY: RETRY:
my $passwd1 = prompt('Password:', -echo => "*"); my $passwd1 = prompt('Password:', -echo => "*");
my $passwd2 = prompt('Password, again:', -echo => "*"); my $passwd2 = prompt('Password, again:', -echo => "*");
...@@ -51,17 +49,20 @@ sub execute { ...@@ -51,17 +49,20 @@ sub execute {
say "you typed different passwords, retry"; say "you typed different passwords, retry";
goto RETRY; goto RETRY;
} }
say "user: $user";
say "pw1: $passwd1";
say "pw2: $passwd2";
$config{user} = "$user";
$config{password} = SLUB::LZA::TA::Crypt::encrypt("$passwd1"); $config{password} = SLUB::LZA::TA::Crypt::encrypt("$passwd1");
} if (defined $SLUB::LZA::TA::config_file) {
if (defined $SLUB::LZA::Rosetta::TA::config_file) {
if (defined $opt->{verbose}) { if (defined $opt->{verbose}) {
say "store config in $SLUB::LZA::Rosetta::TA::config_file"; say "store config in $SLUB::LZA::TA::config_file";
} }
my $file = path($SLUB::LZA::Rosetta::TA::config_file); my $file = path($SLUB::LZA::TA::config_file);
$file->touch(); $file->touch();
$file->chmod("0600"); $file->chmod("0600");
my $fh = path($SLUB::LZA::Rosetta::TA::config_file)->filehandle({exclusive => 0}, ">"); my $fh = path($SLUB::LZA::TA::config_file)->filehandle({ exclusive => 0 }, ">");
YAML::DumpFile($fh, %config); YAML::DumpFile($fh, \%config);
$fh->close; $fh->close;
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment