CLI: add rollback option (#2103)
This commit is contained in:
parent
2c11111547
commit
53ac31e3c3
|
@ -22,7 +22,7 @@ for ( my $i = 0 ; $i < @ARGV ; $i++ ) {
|
||||||
|
|
||||||
$action ||= "help";
|
$action ||= "help";
|
||||||
|
|
||||||
if ( $action =~ /^(?:[gs]et|(?:add|del)Key|save|restore)$/ ) {
|
if ( $action =~ /^(?:[gs]et|(?:add|del)Key|save|restore|rollback)$/ ) {
|
||||||
eval { require Lemonldap::NG::Manager::Cli; };
|
eval { require Lemonldap::NG::Manager::Cli; };
|
||||||
die "Manager libraries not available, aborting ($@)" if ($@);
|
die "Manager libraries not available, aborting ($@)" if ($@);
|
||||||
Lemonldap::NG::Manager::Cli->run(@ARGV);
|
Lemonldap::NG::Manager::Cli->run(@ARGV);
|
||||||
|
@ -50,6 +50,7 @@ Available actions:
|
||||||
- save : export configuration to STDOUT
|
- save : export configuration to STDOUT
|
||||||
- restore - : import configuration from STDIN
|
- restore - : import configuration from STDIN
|
||||||
- restore <file> : import configuration from file
|
- restore <file> : import configuration from file
|
||||||
|
- rollback : restore previous configuration
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
- yes <0|1> : accept confirmation prompt automatically
|
- yes <0|1> : accept confirmation prompt automatically
|
||||||
|
@ -90,6 +91,10 @@ Restore configuration
|
||||||
# OR
|
# OR
|
||||||
$ lemonldap-ng-cli restore - <conf.json
|
$ lemonldap-ng-cli restore - <conf.json
|
||||||
|
|
||||||
|
Cancel the last configuration change
|
||||||
|
|
||||||
|
$ lemonldap-ng-cli rollback
|
||||||
|
|
||||||
Get a configuration parameter value
|
Get a configuration parameter value
|
||||||
|
|
||||||
$ lemonldap-ng-cli get portal domain cookieName
|
$ lemonldap-ng-cli get portal domain cookieName
|
||||||
|
|
|
@ -229,6 +229,33 @@ sub restore {
|
||||||
print STDERR Dumper($res);
|
print STDERR Dumper($res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub rollback {
|
||||||
|
my ($self) = @_;
|
||||||
|
my $lastCfg = $self->mgr->confAcc->lastCfg;
|
||||||
|
my $previousCfg = $lastCfg - 1;
|
||||||
|
my $conf =
|
||||||
|
$self->mgr->confAcc->getConf( { cfgNum => $previousCfg, raw => 1 } )
|
||||||
|
or die $Lemonldap::NG::Common::Conf::msg;
|
||||||
|
|
||||||
|
$conf->{cfgNum} = $lastCfg;
|
||||||
|
$conf->{cfgAuthor} = scalar( getpwuid $< ) . '(command-line-interface)';
|
||||||
|
chomp $conf->{cfgAuthor};
|
||||||
|
$conf->{cfgAuthorIP} = '127.0.0.1';
|
||||||
|
$conf->{cfgDate} = time;
|
||||||
|
$conf->{cfgVersion} = $Lemonldap::NG::Manager::VERSION;
|
||||||
|
$conf->{cfgLog} = $self->log // "Rolled back configuration $lastCfg";
|
||||||
|
|
||||||
|
my $s = $self->mgr->confAcc->saveConf($conf);
|
||||||
|
if ( $s > 0 ) {
|
||||||
|
$self->logger->info("CLI: Configuration $lastCfg has been rolled back");
|
||||||
|
print STDERR "Configuration $lastCfg has been rolled back\n";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$self->logger->error("CLI: Failed to rollback configuration $lastCfg");
|
||||||
|
print STDERR "Failed to rollback configuration $lastCfg\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sub _getKey {
|
sub _getKey {
|
||||||
my ( $self, $key ) = @_;
|
my ( $self, $key ) = @_;
|
||||||
my $sep = $self->sep;
|
my $sep = $self->sep;
|
||||||
|
@ -355,7 +382,7 @@ sub run {
|
||||||
}
|
}
|
||||||
$self->cfgNum( $self->lastCfg ) unless ( $self->cfgNum );
|
$self->cfgNum( $self->lastCfg ) unless ( $self->cfgNum );
|
||||||
my $action = shift;
|
my $action = shift;
|
||||||
unless ( $action =~ /^(?:get|set|addKey|delKey|save|restore)$/ ) {
|
unless ( $action =~ /^(?:get|set|addKey|delKey|save|restore|rollback)$/ ) {
|
||||||
die "Unknown action $action. Only get, set, addKey or delKey allowed";
|
die "Unknown action $action. Only get, set, addKey or delKey allowed";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user