Check conf. timestamp to reload (#2508)

This commit is contained in:
Christophe Maudoux 2021-04-25 23:21:09 +02:00
parent 96dbbd9ad4
commit 0f40e2d1bb
8 changed files with 63 additions and 22 deletions

View File

@ -17,7 +17,7 @@ sub accessToTrace {
my $params = $hash->{params}; my $params = $hash->{params};
my $session = $hash->{session}; my $session = $hash->{session};
return "$custom alias $params->[0]_$params->[1]:$session->{groups} with $session->{$params->[2]}"; return "$custom alias $params->[0]_$params->[1]:$session->{groups} ($session->{$params->[2]})";
} }
1; 1;

View File

@ -171,7 +171,7 @@
"vhostHttps": -1, "vhostHttps": -1,
"vhostAliases": "", "vhostAliases": "",
"vhostServiceTokenTTL": -1, "vhostServiceTokenTTL": -1,
"vhostAccessToTrace": "My::accessToTrace, Doctor, Who","vhostType":"Main" "vhostAccessToTrace": "My::accessToTrace, Doctor, Who, _whatToTrace","vhostType":"Main"
} }
}, },
"loginHistoryEnabled": 1, "loginHistoryEnabled": 1,

View File

@ -65,8 +65,9 @@ Options:
- safe <0|1> : fail in case the requested configuration is invalid - safe <0|1> : fail in case the requested configuration is invalid
- force <0|1> : allow overwrite of existing config number - force <0|1> : allow overwrite of existing config number
- cfgNum <num> : set new configuration number (requires -force 1) - cfgNum <num> : set new configuration number (requires -force 1)
- nohistory : do not increment configuration number (requires -force 1)
- sep <char> : separator of hierarchical values (by default: /) - sep <char> : separator of hierarchical values (by default: /)
- iniFile <file> : path to an alternate lemonldap-ng.ini file - iniFile <file> : path to an alternative lemonldap-ng.ini file
See Lemonldap::NG::Manager::Cli(3) for more See Lemonldap::NG::Manager::Cli(3) for more
}; };
@ -170,13 +171,25 @@ Allows you to set the log message that will be displayed in the manager
The configuration change will be aborted if it contains errors (default: 0) The configuration change will be aborted if it contains errors (default: 0)
=item -force
Allows you to force overwriting an existing configuration (default: 0)
=item -cfgNum =item -cfgNum
Choose a particular configuration number (default: latest) Choose a particular configuration number (default: latest)
=item -force =item -nohistory
Allows you to force overwriting an existing configuration (default: 0) Allows you to keep current configuration number
=item -sep
Allows you to define hierarchical separator
=item -iniFile
Allows you to set an alternative ini file
=back =back
@ -189,11 +202,13 @@ L<http://lemonldap-ng.org/>
=over =over
=item David Coutateur, E<lt>david.jose.delassus@gmail.comE<gt> =item Clement Oudot, E<lt>clement@oodo.netE<gt>
=item Clement Oudot, E<lt>clem.oudot@gmail.comE<gt> =item Xavier Guimard, E<lt>yadd@debian.orgE<gt>
=item Xavier Guimard, E<lt>x.guimard@free.frE<gt> =item Maxime Besson, E<lt>maxime.besson@worteks.comE<gt>
=item Christophe Maudoux, E<lt>chrmdx@gmail.comE<gt>
=back =back
@ -205,7 +220,7 @@ L<https://gitlab.ow2.org/lemonldap-ng/lemonldap-ng/issues>
=head1 DOWNLOAD =head1 DOWNLOAD
Lemonldap::NG is available at Lemonldap::NG is available at
L<http://forge.objectweb.org/project/showfiles.php?group_id=274> L<https://release.ow2.org/lemonldap/>
=head1 COPYRIGHT AND LICENSE =head1 COPYRIGHT AND LICENSE

View File

@ -1,6 +1,6 @@
package Lemonldap::NG::Handler::Main::Reload; package Lemonldap::NG::Handler::Main::Reload;
our $VERSION = '2.0.10'; our $VERSION = '2.0.12';
package Lemonldap::NG::Handler::Main; package Lemonldap::NG::Handler::Main;
@ -59,9 +59,16 @@ sub checkConf {
} }
$Lemonldap::NG::Common::Conf::msg = ''; $Lemonldap::NG::Common::Conf::msg = '';
if ( $force or !$class->cfgNum or $class->cfgNum != $conf->{cfgNum} ) { if ( $force
or !$class->cfgNum
or !$class->cfgDate
or $class->cfgNum != $conf->{cfgNum}
or $class->cfgDate != $conf->{cfgDate} )
{
$class->logger->debug("Get configuration $conf->{cfgNum}"); $class->logger->debug("Get configuration $conf->{cfgNum}");
unless ( $class->cfgNum( $conf->{cfgNum} ) ) { unless ( $class->cfgNum( $conf->{cfgNum} )
&& $class->cfgDate( $conf->{cfgDate} ) )
{
$class->logger->error('No configuration available'); $class->logger->error('No configuration available');
return 0; return 0;
} }
@ -80,7 +87,7 @@ sub checkConf {
} }
} }
} }
$class->checkTime($conf->{checkTime}) if ( $conf->{checkTime} ); $class->checkTime( $conf->{checkTime} ) if $conf->{checkTime};
$class->lastCheck( time() ); $class->lastCheck( time() );
$class->logger->debug("$class: configuration is up to date"); $class->logger->debug("$class: configuration is up to date");
return 1; return 1;

View File

@ -1,8 +1,8 @@
package Lemonldap::NG::Handler::Main::SharedVariables; package Lemonldap::NG::Handler::Main::SharedVariables;
our $VERSION = '2.0.0'; our $VERSION = '2.0.12';
# Since handler has no instances but only static classes, this module provides # Since handler has no instance but only static classes, this module provides
# classes properties with accessors # classes properties with accessors
package Lemonldap::NG::Handler::Main; package Lemonldap::NG::Handler::Main;
@ -14,6 +14,7 @@ BEGIN {
our $_tshv = { our $_tshv = {
tsv => {}, tsv => {},
cfgNum => 0, cfgNum => 0,
cfgDate => 0,
lastCheck => 0, lastCheck => 0,
checkTime => 600, checkTime => 600,
confAcc => {}, confAcc => {},
@ -30,7 +31,7 @@ BEGIN {
foreach ( keys %$_tshv ) { foreach ( keys %$_tshv ) {
eval " sub $_ { eval " sub $_ {
my \$v = \$_[1]; my \$v = \$_[1];
\$_tshv->{$_} = \$v if(defined \$v); \$_tshv->{$_} = \$v if (defined \$v);
return \$_tshv->{$_}; return \$_tshv->{$_};
}"; }";
die $@ if ($@); die $@ if ($@);
@ -41,7 +42,7 @@ BEGIN {
foreach ( keys %$_v ) { foreach ( keys %$_v ) {
eval " sub $_ { eval " sub $_ {
my \$v = \$_[1]; my \$v = \$_[1];
\$_v->{$_} = \$v if(\$v); \$_v->{$_} = \$v if (\$v);
return \$_v->{$_}; return \$_v->{$_};
}"; }";
die $@ if ($@); die $@ if ($@);

View File

@ -7,7 +7,7 @@ use Data::Dumper;
use JSON; use JSON;
use Lemonldap::NG::Common::Conf::ReConstants; use Lemonldap::NG::Common::Conf::ReConstants;
our $VERSION = '2.0.10'; our $VERSION = '2.0.12';
$Data::Dumper::Useperl = 1; $Data::Dumper::Useperl = 1;
extends('Lemonldap::NG::Manager::Cli::Lib'); extends('Lemonldap::NG::Manager::Cli::Lib');
@ -29,6 +29,7 @@ has format => ( is => 'rw', isa => 'Str', default => "%-25s | %-25s | %-25s" );
has yes => ( is => 'rw', isa => 'Bool', default => 0 ); has yes => ( is => 'rw', isa => 'Bool', default => 0 );
has safe => ( is => 'rw', isa => 'Bool', default => 0 ); has safe => ( is => 'rw', isa => 'Bool', default => 0 );
has force => ( is => 'rw', isa => 'Bool', default => 0 ); has force => ( is => 'rw', isa => 'Bool', default => 0 );
has nohistory => ( is => 'rw', isa => 'Bool', default => 0 );
has logger => ( is => 'ro', lazy => 1, builder => sub { $_[0]->mgr->logger } ); has logger => ( is => 'ro', lazy => 1, builder => sub { $_[0]->mgr->logger } );
has userLogger => has userLogger =>
( is => 'ro', lazy => 1, builder => sub { $_[0]->mgr->userLogger } ); ( is => 'ro', lazy => 1, builder => sub { $_[0]->mgr->userLogger } );
@ -355,7 +356,7 @@ sub rollback {
or die $Lemonldap::NG::Common::Conf::msg; or die $Lemonldap::NG::Common::Conf::msg;
$conf->{cfgNum} = $lastCfg; $conf->{cfgNum} = $lastCfg;
$conf->{cfgAuthor} = scalar( getpwuid $< ) . '(command-line-interface)'; $conf->{cfgAuthor} = scalar( getpwuid $< ) . ' (command-line-interface)';
chomp $conf->{cfgAuthor}; chomp $conf->{cfgAuthor};
$conf->{cfgAuthorIP} = '127.0.0.1'; $conf->{cfgAuthorIP} = '127.0.0.1';
$conf->{cfgDate} = time; $conf->{cfgDate} = time;
@ -416,8 +417,7 @@ sub _setKey {
sub _save { sub _save {
my ( $self, $new ) = @_; my ( $self, $new ) = @_;
require Lemonldap::NG::Manager::Conf::Parser; require Lemonldap::NG::Manager::Conf::Parser;
my $parser = Lemonldap::NG::Manager::Conf::Parser->new( my $parser = Lemonldap::NG::Manager::Conf::Parser->new( {
{
newConf => $new, newConf => $new,
refConf => $self->mgr->hLoadedPlugins->{conf}->currentConf, refConf => $self->mgr->hLoadedPlugins->{conf}->currentConf,
req => $self->req req => $self->req
@ -433,6 +433,7 @@ sub _save {
print STDERR "$msg\n"; print STDERR "$msg\n";
} }
} }
my $saveParams = { force => $self->force }; my $saveParams = { force => $self->force };
if ( $self->force and $self->cfgNum ) { if ( $self->force and $self->cfgNum ) {
$self->logger->debug( "CLI: cfgNum forced with " . $self->cfgNum ); $self->logger->debug( "CLI: cfgNum forced with " . $self->cfgNum );
@ -440,6 +441,15 @@ sub _save {
$saveParams->{cfgNum} = $self->cfgNum; $saveParams->{cfgNum} = $self->cfgNum;
$saveParams->{cfgNumFixed} = 1; $saveParams->{cfgNumFixed} = 1;
} }
if ( $self->force and $self->nohistory ) {
my $lastCfg = $self->mgr->confAcc->lastCfg;
$self->logger->debug(
"CLI: No history required. cfgNum forced with " . $lastCfg );
print STDERR "No history required. cfgNum forced with ", $lastCfg;
$saveParams->{cfgNum} = $lastCfg;
$saveParams->{cfgNumFixed} = 1;
}
$new->{cfgAuthor} = scalar( getpwuid $< ) . '(command-line-interface)'; $new->{cfgAuthor} = scalar( getpwuid $< ) . '(command-line-interface)';
chomp $new->{cfgAuthor}; chomp $new->{cfgAuthor};
$new->{cfgAuthorIP} = '127.0.0.1'; $new->{cfgAuthorIP} = '127.0.0.1';

0
lemonldap-ng-manager/scripts/lmConfigEditor Normal file → Executable file
View File

View File

@ -4,7 +4,7 @@ use JSON;
use strict; use strict;
require 't/test-lib.pm'; require 't/test-lib.pm';
my $tests = 17; my $tests = 18;
use_ok('Lemonldap::NG::Common::Cli'); use_ok('Lemonldap::NG::Common::Cli');
use_ok('Lemonldap::NG::Manager::Cli'); use_ok('Lemonldap::NG::Manager::Cli');
@ -77,6 +77,14 @@ combined_like(
'"Force cfgNum" OK' '"Force cfgNum" OK'
); );
# Test 'set' command with nohistory
@cmd = qw(-yes 1 -force 1 -nohistory 1 set cookieName test);
combined_like(
sub { llclient->run(@cmd) },
qr#cfgNum forced with 6#s,
'"Force cfgNum" OK'
);
# Test 'info' command with force # Test 'info' command with force
@cmd = qw(info); @cmd = qw(info);
combined_like( combined_like(