aboutsummaryrefslogtreecommitdiff
path: root/lib/App/Glacier/Command.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/App/Glacier/Command.pm')
-rw-r--r--lib/App/Glacier/Command.pm55
1 files changed, 22 insertions, 33 deletions
diff --git a/lib/App/Glacier/Command.pm b/lib/App/Glacier/Command.pm
index 0888b4b..47bfce6 100644
--- a/lib/App/Glacier/Command.pm
+++ b/lib/App/Glacier/Command.pm
@@ -11,9 +11,9 @@ use App::Glacier::EclatCreds;
use App::Glacier::Config;
use Net::Amazon::Glacier;
use App::Glacier::HttpCatch;
-use App::Glacier::DB;
use App::Glacier::Timestamp;
use App::Glacier::Directory;
+use App::Glacier::Roster;
use Digest::SHA qw(sha256_hex);
use File::Path qw(make_path);
@@ -79,16 +79,14 @@ my %parameters = (
section => {
job => {
section => {
- file => { default => '/var/lib/glacier/job.db' },
- mode => { default => 0644 },
- ttl => { default => 72000, check => \&ck_number },
+ backend => { default => 'GDBM' },
+ '*' => '*'
},
},
inv => {
section => {
- directory => { default => '/var/lib/glacier/inv' },
- mode => { default => 0644 },
- ttl => { default => 72000, check => \&ck_number },
+ backend => { default => 'GDBM' },
+ '*' => '*'
}
}
}
@@ -121,6 +119,13 @@ sub new {
parameters => \%parameters);
exit(EX_CONFIG) unless $self->{_config}->parse();
+ App::Glacier::Roster->configtest($self->cfget(qw(database job backend)),
+ $self->config, 'database', 'job')
+ or exit(EX_CONFIG);
+ App::Glacier::Directory->configtest($self->cfget(qw(database inv backend)),
+ $self->config, 'database', 'inv')
+ or exit(EX_CONFIG);
+
unless ($self->{_config}->isset(qw(glacier access))
&& $self->{_config}->isset(qw(glacier secret))) {
if ($self->{_config}->isset(qw(glacier credentials))) {
@@ -185,14 +190,11 @@ sub touchdir {
sub jobdb {
my $self = shift;
unless ($self->{_jobdb}) {
- my $file = $self->cfget(qw(database job file));
- $self->touchdir(dirname($file));
- $self->{_jobdb} = new App::Glacier::DB(
- 'GDBM',
- filename => $file,
- encoding => 'json',
- mode => $self->cfget(qw(database job mode))
- );
+ my $be = $self->cfget(qw(database job backend));
+ $self->{_jobdb} = new App::Glacier::Roster(
+ $be,
+ %{$self->config->as_hash(qw(database job)) // {}}
+ );
}
return $self->{_jobdb};
}
@@ -211,29 +213,16 @@ sub describe_vault {
return timestamp_deserialize($res);
}
-sub _filename {
- my ($self, $name) = @_;
- $name =~ s/([^A-Za-z_0-9\.-])/sprintf("%%%02X", ord($1))/gex;
- return $name;
-}
-
sub directory {
my ($self, $vault_name) = @_;
unless (exists($self->{_dir}{$vault_name})) {
- my $file = $self->cfget(qw(database inv directory))
- . '/' . $self->_filename($vault_name) . '.db';
- unless (-e $file) {
- return undef unless $self->describe_vault($vault_name);
- }
- $self->touchdir($self->cfget(qw(database inv directory)));
+ my $be = $self->cfget(qw(database inv backend));
$self->{_dir}{$vault_name} =
new App::Glacier::Directory(
- 'GDBM',
- filename => $file,
- encoding => 'json',
- mode => $self->cfget(qw(database inv mode)),
- ttl => $self->cfget(qw(database inv ttl))
- );
+ $be,
+ $vault_name,
+ create => sub { $self->describe_vault($vault_name) },
+ %{$self->config->as_hash(qw(database inv)) // {}});
}
return $self->{_dir}{$vault_name};
}

Return to:

Send suggestions and report system problems to the System administrator.