Create a Mouse object to define configuration attributes and their default values (#686)

environments/ppa-mbqj77/deployments/1
Clément Oudot 11 years ago
parent f7bcf5b711
commit 25be47b266
  1. 1
      lemonldap-ng-common/MANIFEST
  2. 33
      lemonldap-ng-common/lib/Lemonldap/NG/Common/Conf.pm
  3. 53
      lemonldap-ng-common/lib/Lemonldap/NG/Common/Conf/Attributes.pm

@ -8,6 +8,7 @@ lib/Lemonldap/NG/Common/CGI/SOAPServer.pm
lib/Lemonldap/NG/Common/CGI/SOAPService.pm
lib/Lemonldap/NG/Common/Conf.pm
lib/Lemonldap/NG/Common/Conf/_DBI.pm
lib/Lemonldap/NG/Common/Conf/Attributes.pm
lib/Lemonldap/NG/Common/Conf/CDBI.pm
lib/Lemonldap/NG/Common/Conf/Constants.pm
lib/Lemonldap/NG/Common/Conf/DBI.pm

@ -9,7 +9,8 @@ package Lemonldap::NG::Common::Conf;
use strict;
no strict 'refs';
use Lemonldap::NG::Common::Conf::Constants; #inherits
use Lemonldap::NG::Common::Conf::Constants; #inherits
use Lemonldap::NG::Common::Conf::Attributes; #inherits
use Lemonldap::NG::Common::Crypto
; #link protected cipher Object "cypher" in configuration hash
use Config::IniFiles;
@ -19,7 +20,7 @@ use Config::IniFiles;
#inherits Lemonldap::NG::Common::Conf::SOAP
#inherits Lemonldap::NG::Common::Conf::LDAP
our $VERSION = '1.3.0';
our $VERSION = '1.4.0';
our $msg;
our $iniObj;
@ -138,6 +139,8 @@ sub saveConf {
# @return Lemonldap::NG configuration
sub getConf {
my ( $self, $args ) = @_;
# Use only cache to get conf
if ( $args->{local}
and ref( $self->{refLocalStorage} )
and my $res = $self->{refLocalStorage}->get('conf') )
@ -145,11 +148,13 @@ sub getConf {
$msg .= "Get configuration from cache without verification.\n";
return $res;
}
# Check cfgNum in conf backend
# Get conf in backend only if a newer configuration is available
else {
$args->{cfgNum} ||= $self->lastCfg;
unless ( $args->{cfgNum} ) {
$msg .= "No configuration available.\n";
return 0;
$msg .= "No configuration available in backend.\n";
}
my $r;
unless ( ref( $self->{refLocalStorage} ) ) {
@ -167,13 +172,19 @@ sub getConf {
$r = $self->getDBConf($args);
}
}
print STDERR "Warning: key is not defined, set it in the manager !\n"
unless ( $r->{key} );
eval {
$r->{cipher} =
Lemonldap::NG::Common::Crypto->new( $r->{key}
|| 'lemonldap-ng-key' );
};
# Get default values
my $confAttributes = Lemonldap::NG::Common::Conf::Attributes->new();
my @attributes = $confAttributes->meta()->get_attribute_list();
foreach my $name (@attributes) {
unless ( defined $r->{$name} ) {
$r->{$name} = $confAttributes->$name;
}
}
eval { $r->{cipher} = Lemonldap::NG::Common::Crypto->new( $r->{key} ); };
if ($@) {
$msg .= "Bad key: $@. \n";
return $r;

@ -0,0 +1,53 @@
##@file
# All configuration attributes
##@class
# All configuration attributes
package Lemonldap::NG::Common::Conf::Attributes;
use Mouse;
our $VERSION = 1.4.0;
has 'domain' => (
is => 'rw',
isa => 'Str',
default => 'example.com',
documentation => 'DNS domain',
);
has 'key' => (
is => 'rw',
isa => 'Str',
default => sub {
return join( '', map { chr( int( rand(94) ) + 33 ) } ( 1 .. 16 ) );
},
documentation => 'Secret key',
);
has 'globalStorage' => (
is => 'rw',
isa => 'Str',
default => 'Apache::Session::File',
documentation => 'Session backend module',
);
has 'globalStorageOptions' => (
is => 'rw',
isa => 'HashRef',
default => sub {
return { Directory => "/tmp" };
},
documentation => 'Session backend module options',
);
has 'portal' => (
is => 'rw',
default => 'http://auth.example.com',
documentation => 'Portal URL',
);
no Mouse;
1;
Loading…
Cancel
Save