Compact conf

environments/ppa-mbqj77/deployments/1
Xavier Guimard 8 years ago
parent 990006ce80
commit 1ccad93701
  1. 2
      lemonldap-ng-common/MANIFEST
  2. 7
      lemonldap-ng-common/lib/Lemonldap/NG/Common/Conf.pm
  3. 69
      lemonldap-ng-common/lib/Lemonldap/NG/Common/Conf/Compact.pm
  4. 1
      lemonldap-ng-manager/MANIFEST
  5. 64
      lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Conf/Parser.pm

@ -21,8 +21,10 @@ lib/Lemonldap/NG/Common/Conf/Backends/LDAP.pm
lib/Lemonldap/NG/Common/Conf/Backends/MongoDB.pm
lib/Lemonldap/NG/Common/Conf/Backends/RDBI.pm
lib/Lemonldap/NG/Common/Conf/Backends/SOAP.pm
lib/Lemonldap/NG/Common/Conf/Compact.pm
lib/Lemonldap/NG/Common/Conf/Constants.pm
lib/Lemonldap/NG/Common/Conf/DefaultValues.pm
lib/Lemonldap/NG/Common/Conf/ReConstants.pm
lib/Lemonldap/NG/Common/Conf/RESTServer.pm
lib/Lemonldap/NG/Common/Conf/SAML/Metadata.pm
lib/Lemonldap/NG/Common/Conf/Serializer.pm

@ -12,6 +12,10 @@ use utf8;
no strict 'refs';
use Lemonldap::NG::Common::Conf::Constants; #inherits
# Import compacter
use Lemonldap::NG::Common::Conf::Compact;
*compactConf = \&Lemonldap::NG::Common::Conf::Compact::compactConf;
# TODO: don't import this big file, use a proxy
use Lemonldap::NG::Common::Conf::DefaultValues; #inherits
use Lemonldap::NG::Common::Crypto
@ -169,6 +173,7 @@ sub getConf {
unless ( ref( $self->{refLocalStorage} ) ) {
$msg .= "Get remote configuration (localStorage unavailable).\n";
$r = $self->getDBConf($args);
$self->compactConf($r);
}
else {
eval { $r = $self->{refLocalStorage}->get('conf') }
@ -206,6 +211,8 @@ sub getConf {
$r->{whatToTrace} =~ s/^\$//;
}
$self->compactConf($r);
# Store modified configuration in cache
$self->setLocalConf($r)
if ( $self->{refLocalStorage}

@ -0,0 +1,69 @@
package Lemonldap::NG::Common::Conf::Compact;
use strict;
use Mouse;
use Lemonldap::NG::Common::Conf::ReConstants;
our $VERSION = '2.0.0';
sub compactConf {
my ( $self, $conf ) = @_;
# Remove unused auth parameters
my %keep;
foreach my $type (qw(authentication userDB passwordDB)) {
my $mod = $conf->{$type} || 'Null';
$mod =~ s/OpenIDConnect/oidc/i;
$mod = lc($mod);
$keep{$mod} = 1;
}
if ( $keep{multi} ) {
foreach my $prm (qw(multiAuthStack multiUserDBStack)) {
my @tmp = split /;\s*/, $conf->{$prm};
foreach (@tmp) {
s/^(\w+).*$/lc($1)/e;
s/OpenIDConnect/oidc/i;
$keep{$_} = 1;
}
}
}
if ( $keep{choice} ) {
foreach my $key ( values %{ $conf->{authChoiceModules} } ) {
my @tmp = split /[;|\|]/, $key;
foreach (@tmp) {
s/^(\w+).*$/lc($1)/e;
s/OpenIDConnect/oidc/i;
$keep{$_} = 1;
}
}
}
foreach my $key (%$authParameters) {
my $mod = $key;
$mod =~ s/Params$//;
unless ( $keep{$mod} ) {
delete $conf->{$_} foreach ( @{ $authParameters->{$key} } );
}
}
# Disabled for now:
## Remove unused issuerDB parameters
#foreach my $k ( keys %$issuerParameters ) {
# unless ( $conf->{ $k . "Activation" } ) {
# delete $conf->{$_} foreach ( @{ $issuerParameters->{$k} } );
# }
#}
## Remove SAML service unless used
#unless ( $keep{saml} or $conf->{issuerDBSAMLActivation} ) {
# delete $conf->{$_} foreach (@$samlServiceParameters);
#}
## Remove OpenIF-Connect service unless used
#unless ( $keep{oidc} or $conf->{issuerDBOpenIDConnectActivation} ) {
# delete $conf->{$_} foreach (@$oidcServiceParameters);
#}
return $conf;
}
1;

@ -18,7 +18,6 @@ lib/Lemonldap/NG/Manager/Conf/Diff.pm
lib/Lemonldap/NG/Manager/Conf/Parser.pm
lib/Lemonldap/NG/Manager/Conf/Tests.pm
lib/Lemonldap/NG/Manager/Conf/Zero.pm
lib/Lemonldap/NG/Manager/Constants.pm
lib/Lemonldap/NG/Manager/Notifications.pm
lib/Lemonldap/NG/Manager/Sessions.pm
Makefile.PL

@ -26,6 +26,8 @@ use Lemonldap::NG::Manager::Attributes;
our $VERSION = '2.0.0';
extends 'Lemonldap::NG::Common::Conf::Compact';
# High debugging for developpers, set this to 1
use constant HIGHDEBUG => 0;
@ -94,7 +96,7 @@ sub check {
unless ( $self->newConf ) {
return 0 unless ( $self->scanTree );
}
$self->compactConf;
$self->compactConf( $self->newConf );
unless ( $self->testNewConf ) {
hdebug(" testNewConf() failed");
return 0;
@ -1068,66 +1070,6 @@ sub _globalTest {
return $result;
}
sub compactConf {
my $self = shift;
my $conf = $self->newConf or die("No new conf");
# Remove unused auth parameters
my %keep;
foreach my $type (qw(authentication userDB passwordDB)) {
my $mod = $conf->{$type};
$mod =~ s/OpenIDConnect/oidc/i;
$mod = lc($mod);
$keep{$mod} = 1;
}
if ( $keep{multi} ) {
foreach my $prm (qw(multiAuthStack multiUserDBStack)) {
my @tmp = split /;\s*/, $conf->{$prm};
foreach (@tmp) {
s/^(\w+).*$/lc($1)/e;
s/OpenIDConnect/oidc/i;
$keep{$_} = 1;
}
}
}
if ( $keep{choice} ) {
foreach my $key ( values %{ $conf->{authChoiceModules} } ) {
my @tmp = split /[;|\|]/, $key;
foreach (@tmp) {
s/^(\w+).*$/lc($1)/e;
s/OpenIDConnect/oidc/i;
$keep{$_} = 1;
}
}
}
foreach my $key (%$authParameters) {
my $mod = $key;
$mod =~ s/Params$//;
unless ( $keep{$mod} ) {
delete $conf->{$_} foreach ( @{ $authParameters->{$key} } );
}
}
# Disabled for now:
## Remove unused issuerDB parameters
#foreach my $k ( keys %$issuerParameters ) {
# unless ( $conf->{ $k . "Activation" } ) {
# delete $conf->{$_} foreach ( @{ $issuerParameters->{$k} } );
# }
#}
## Remove SAML service unless used
#unless ( $keep{saml} or $conf->{issuerDBSAMLActivation} ) {
# delete $conf->{$_} foreach (@$samlServiceParameters);
#}
## Remove OpenIF-Connect service unless used
#unless ( $keep{oidc} or $conf->{issuerDBOpenIDConnectActivation} ) {
# delete $conf->{$_} foreach (@$oidcServiceParameters);
#}
}
1;
__END__

Loading…
Cancel
Save