summaryrefslogtreecommitdiff
path: root/perl/lib
diff options
context:
space:
mode:
authorRuss Allbery <eagle@eyrie.org>2014-07-15 20:29:19 -0700
committerRuss Allbery <rra@stanford.edu>2014-07-15 21:10:37 -0700
commitb1bd88daea1dde6de9e6a8688c6190cdc0b5c617 (patch)
treeb6a9cf2a7dd3ef14b28ec0f83067359db09c8b7a /perl/lib
parent0b97ce27ea443be1e4b63fb5ebffa8a274a00f40 (diff)
Record the ACL name in the acl_history table
Store the current name of the ACL with each history row, and index the name. This will eventually allow retrieval of history by name for ACLs that have been deleted, although the rest of the code is not yet in place. The initial creation and membership of the ADMIN ACL during database initialization or reinitialization is no longer recorded in the acl_history table, since otherwise it produces errors due to the missing ah_name field when building the database with schema 0.07. There should be some better solution to this, but this will be okay for the time being. Change-Id: I015a00c972e0c2730c3d449952fcfe9b79c6e54f Reviewed-on: https://gerrit.stanford.edu/1553 Reviewed-by: Russ Allbery <rra@stanford.edu> Tested-by: Russ Allbery <rra@stanford.edu>
Diffstat (limited to 'perl/lib')
-rw-r--r--perl/lib/Wallet/ACL.pm5
-rw-r--r--perl/lib/Wallet/Admin.pm19
-rw-r--r--perl/lib/Wallet/Schema/Result/AclHistory.pm10
3 files changed, 28 insertions, 6 deletions
diff --git a/perl/lib/Wallet/ACL.pm b/perl/lib/Wallet/ACL.pm
index 57097c0..6f5172a 100644
--- a/perl/lib/Wallet/ACL.pm
+++ b/perl/lib/Wallet/ACL.pm
@@ -80,6 +80,7 @@ sub create {
# Add to the history table.
my $date = DateTime->from_epoch (epoch => $time);
%record = (ah_acl => $id,
+ ah_name => $name,
ah_action => 'create',
ah_by => $user,
ah_from => $host,
@@ -165,6 +166,7 @@ sub log_acl {
}
my $date = DateTime->from_epoch (epoch => $time);
my %record = (ah_acl => $self->{id},
+ ah_name => $self->{name},
ah_action => $action,
ah_scheme => $scheme,
ah_identifier => $identifier,
@@ -243,7 +245,8 @@ sub destroy {
# Create new history line for the deletion.
my $date = DateTime->from_epoch (epoch => $time);
- my %record = (ah_acl => $self->{id},
+ my %record = (ah_acl => $self->{id},
+ ah_name => $self->{name},
ah_action => 'destroy',
ah_by => $user,
ah_from => $host,
diff --git a/perl/lib/Wallet/Admin.pm b/perl/lib/Wallet/Admin.pm
index 29b2f21..b07c7d1 100644
--- a/perl/lib/Wallet/Admin.pm
+++ b/perl/lib/Wallet/Admin.pm
@@ -98,13 +98,22 @@ sub initialize {
$self->default_data;
# Create a default admin ACL.
- my $acl = Wallet::ACL->create ('ADMIN', $self->{schema}, $user,
- 'localhost');
- unless ($acl->add ('krb5', $user, $user, 'localhost')) {
- $self->error ($acl->error);
+ eval {
+ my $guard = $self->{schema}->txn_scope_guard;
+ $self->{schema}->resultset ('Acl')->populate ([
+ [ qw/ac_id ac_name/ ],
+ [ 1, 'ADMIN' ],
+ ]);
+ $self->{schema}->resultset ('AclEntry')->populate ([
+ [ qw/ae_id ae_scheme ae_identifier/ ],
+ [ 1, 'krb5', $user ],
+ ]);
+ $guard->commit;
+ };
+ if ($@) {
+ $self->error ("cannot add ADMIN ACL: $@");
return;
}
-
return 1;
}
diff --git a/perl/lib/Wallet/Schema/Result/AclHistory.pm b/perl/lib/Wallet/Schema/Result/AclHistory.pm
index 11593b7..82e18a9 100644
--- a/perl/lib/Wallet/Schema/Result/AclHistory.pm
+++ b/perl/lib/Wallet/Schema/Result/AclHistory.pm
@@ -41,6 +41,12 @@ __PACKAGE__->table("acl_history");
data_type: 'integer'
is_nullable: 0
+=head2 ah_name
+
+ data_type: 'varchar'
+ is_nullable: 1
+ size: 255
+
=head2 ah_action
data_type: 'varchar'
@@ -84,6 +90,8 @@ __PACKAGE__->add_columns(
{ data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
"ah_acl",
{ data_type => "integer", is_nullable => 0 },
+ "ah_name",
+ { data_type => "varchar", is_nullable => 1, size => 255 },
"ah_action",
{ data_type => "varchar", is_nullable => 0, size => 16 },
"ah_scheme",
@@ -108,6 +116,8 @@ sub sqlt_deploy_hook {
my ($self, $sqlt_table) = @_;
my $name = 'acl_history_idx_ah_acl';
$sqlt_table->add_index (name => $name, fields => [qw(ah_acl)]);
+ $name = 'acl_history_idx_ah_name';
+ $sqlt_table->add_index (name => $name, fields => [qw(ah_name)]);
}
1;