« blib/lib/Lemonldap/NG/Common/Logger/Sentry.pm
↑ Summary
blib/lib/Lemonldap/NG/Common/Notifications/JSON.pm »
| 1 | ##@file | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # Base package for Lemonldap::NG configuration system | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | ##@class | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # Implements Lemonldap::NG shared configuration system. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # In case of error or warning, the message is stored in the global variable | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # $Lemonldap::NG::Common::Conf::msg | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | package Lemonldap::NG::Common::Conf; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 16 | ▶ | use strict; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 16 | ▶ | use utf8; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 16 | ▶ | no strict 'refs'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 16 | ▶ | use Lemonldap::NG::Common::Conf::Constants; #inherits | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # Import compacter | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 16 | ▶ | use Lemonldap::NG::Common::Conf::Compact; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 16 | *compactConf = \&Lemonldap::NG::Common::Conf::Compact::compactConf; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | # TODO: don't import this big file, use a proxy | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 16 | ▶ | use Lemonldap::NG::Common::Conf::DefaultValues; #inherits | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | use Lemonldap::NG::Common::Crypto | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 16 | ▶ | ; #link protected cipher Object "cypher" in configuration hash | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 16 | ▶ | use Config::IniFiles; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | #inherits Lemonldap::NG::Common::Conf::Backends::File | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | #inherits Lemonldap::NG::Common::Conf::Backends::DBI | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | #inherits Lemonldap::NG::Common::Conf::Backends::SOAP | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | #inherits Lemonldap::NG::Common::Conf::Backends::LDAP | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 16 | our $VERSION = '2.23.0'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 16 | our $msg = ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 16 | our $iniObj; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 16 | ▶ | BEGIN { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 16 | eval { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 16 | require threads::shared; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 16 | threads::shared::share($iniObj); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | ## @cmethod Lemonldap::NG::Common::Conf new(hashRef arg) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | # Constructor. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | # Succeed if it has found a way to access to Lemonldap::NG configuration with | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | # $arg (or default file). It can be : | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | # - Nothing: default configuration file is tested, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | # - { confFile => "/path/to/storage.conf" }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | # - { Type => "File", dirName => "/path/to/conf/dir/" }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | # - { Type => "DBI", dbiChain => "DBI:MariaDB:database=lemonldap-ng;host=1.2.3.4", | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | # dbiUser => "user", dbiPassword => "password" }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | # - { Type => "SOAP", proxy => "https://auth.example.com/config" }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | # - { Type => "LDAP", ldapServer => "ldap://localhost", ldapConfBranch => "ou=conf,ou=applications,dc=example,dc=com", | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | # ldapBindDN => "cn=manager,dc=example,dc=com", ldapBindPassword => "secret"}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | # | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | # $self->{type} contains the type of configuration access system and the | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | # corresponding package is loaded. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | # @param $arg hash reference or hash table | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | # @return New Lemonldap::NG::Common::Conf object | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 28 | ▶ | sub new { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=15 SCAR=27.6
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 28 | my $class = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 28 | my $self = bless {}, $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 28 | ▶ | if ( ref( $_[0] ) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 19 | %$self = %{ $_[0] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 9 | ▶ | if ( (@_) && $#_ % 2 == 1 ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ and $#_ % 2 == 1
MC/DC0%0/2
@_ and $#_ % 2 == 1
@_
$#_ % 2 == 1
Truth table33%1/3
A and B
A= @_B= $#_ % 2 == 1
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 9 | %$self = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 28 | ▶ | unless ( $self->{mdone} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 28 | ▶ | unless ( $self->{type} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | # Use local conf to get configStorage and localStorage | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | my $localConfAccessPrms = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 11 | $self->getLocalConf( CONFSECTION, $self->{confFile}, 0 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 11 | ▶ | if ( defined $localConfAccessPrms ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 11 | %$self = ( %$self, %$localConfAccessPrms ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 11 | $self->replacePlaceholders($localConfAccessPrms); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | # localConfAccessPrms might have changed so we need to | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | # update $self | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 11 | %$self = ( %$self, %$localConfAccessPrms ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 28 | ▶ | unless ( $self->{type} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | $msg .= "Error: configStorage: type is not defined.\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 28 | ▶ | unless ( $self->{type} =~ /^[\w:]+$/ ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | $msg .= "Error: configStorage: type is not well formed.\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | $self->{type} = "Lemonldap::NG::Common::Conf::Backends::$self->{type}" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 28 | ▶ | unless $self->{type} =~ /::/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 28 | eval "require $self->{type}"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 28 | ▶ | if ($@) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 1 | $msg .= "Error: failed to load $self->{type}: \n $@"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 1 | return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 27 | ▶ | return 0 unless $self->prereq; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 26 | $self->{mdone}++; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 26 | $msg = "$self->{type} loaded.\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 26 | ▶ | if ( $self->{localStorage} and not defined( $self->{refLocalStorage} ) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"localStorage"} and not defined $self->{"refLocalStorage"}
MC/DC50%1/2
$self->{"localStorage"} and not defined $self->{"refLocalStorage"}
$self->{"localStorage"}
not defined $self->{"refLocalStorage"}
Truth table66%2/3
A and not(B)
A= $self->{"localStorage"}B= not defined $self->{"refLocalStorage"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 1 | ▶ | eval "use $self->{localStorage};"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 7 | ▶ | if ($@) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | $msg .= "Error: Unable to load $self->{localStorage}: $@.\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | # TODO: defer that until $> > 0 (to avoid creating local cache with | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | # root privileges | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | $self->{refLocalStorage} = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 7 | $self->{localStorage}->new( $self->{localStorageOptions} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 26 | return $self; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | ## @method int saveConf(hashRef conf, hash args) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | # Serialize $conf and call store(). | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | # @param $conf Lemonldap::NG configuration hashRef | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | # @param %args Parameters | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | # @return Number of the saved configuration, <=0 in case of error. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | sub saveConf { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
saveConf: not called CC=14 SCAR=53.5
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | my ( $self, $conf, %args ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | # noCache => 1 disables the localStorage fallback in lastCfg, so a stale | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | # cached cfgNum cannot let us overwrite a newer central configuration. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | my $last = $self->lastCfg( { noCache => 1 } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | # If configuration was modified, return an error | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | if ( not $args{force} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | if ( $conf->{cfgNum} ne $last | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$conf->{"cfgNum"} ne $last or $args{"cfgDate"} and $args{"cfgDate"} ne $args{"currentCfgDate"}
$args{"cfgDate"} and $args{"cfgDate"} ne $args{"currentCfgDate"}
MC/DC0%0/3
$conf->{"cfgNum"} ne $last or $args{"cfgDate"} and $args{"cfgDate"} ne $args{"currentCfgDate"}
$conf->{"cfgNum"} ne $last
$args{"cfgDate"}
$args{"cfgDate"} ne $args{"currentCfgDate"}
Truth table0%0/4
A or B and C
A= $conf->{"cfgNum"} ne $lastB= $args{"cfgDate"}C= $args{"cfgDate"} ne $args{"currentCfgDate"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | || $args{cfgDate} && $args{cfgDate} ne $args{currentCfgDate} ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | if ( $conf->{cfgNum} ne $last ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | $msg .= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | "Configuration $last was changed since $conf->{cfgNum}.\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | if ( $args{cfgDate} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | $msg .= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | "Configuration date $args{currentCfgDate}" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | . " was changed since $args{cfgDate}.\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | return CONFIG_WAS_CHANGED; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | if ( $self->isLocked() or not $self->lock() ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->isLocked or not $self->lock
MC/DC0%0/2
$self->isLocked or not $self->lock
$self->isLocked
not $self->lock
Truth table0%0/3
A or not(B)
A= $self->isLockedB= not $self->lock
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | $msg .= "Configuration is locked.\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | return DATABASE_LOCKED; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | ▶ | $conf->{cfgNum} = $last + 1 unless ( $args{cfgNumFixed} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | delete $conf->{cipher}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | # Try to store configuration | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | my $tmp = $self->store($conf); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | unless ( $tmp > 0 ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | $msg .= "Error: Configuration $conf->{cfgNum} not stored.\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | $self->unlock(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | ▶ | return ( $tmp ? $tmp : UNKNOWN_ERROR ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | $msg .= "Configuration $conf->{cfgNum} stored.\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | $self->setDefault($conf); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | $self->setValuesFromEnv($conf); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | $self->compactConf($conf); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | ▶ | if ( Lemonldap::NG::Handler::Main->can('tsv') | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
"Lemonldap::NG::Handler::Main"->can("tsv") and "Lemonldap::NG::Handler::Main"->tsv->{"msgBrokerWriter"}
MC/DC0%0/2
"Lemonldap::NG::Handler::Main"->can("tsv") and "Lemonldap::NG::Handler::Main"->tsv->{"msgBrokerWriter"}
"Lemonldap::NG::Handler::Main"->can("tsv")
"Lemonldap::NG::Handler::Main"->tsv->{"msgBrokerWriter"}
Truth table0%0/3
A and B
A= "Lemonldap::NG::Handler::Main"->can("tsv")B= "Lemonldap::NG::Handler::Main"->tsv->{"msgBrokerWriter"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | and Lemonldap::NG::Handler::Main->tsv->{msgBrokerWriter} ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | Lemonldap::NG::Handler::Main->tsv->{msgBrokerWriter} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | ->publish( $conf->{eventQueueName}, { action => 'newConf' } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | eval { Lemonldap::NG::Handler::Main->reload() }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | $self->unlock(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | return $tmp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | ## @method hashRef getConf(hashRef args) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | # Get configuration from remote configuration storage system or from local | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | # cache if configuration has not been changed. If $args->{local} is set and if | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | # a local configuration is available, remote configuration is not tested. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | # | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | # Uses lastCfg to test and getDBConf() to get the remote configuration | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | # @param $args Optional, contains {local=>1} or nothing | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | # @return Lemonldap::NG configuration | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 22 | ▶ | sub getConf { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getConf: called CC=28 SCAR=34.1
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 22 | my ( $self, $args ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 22 | my $res; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 22 | my $local = $args->{local}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 22 | my $cfgNum = $args->{cfgNum}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 22 | my $localPrm = $args->{localPrm}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 22 | my $noCache = $args->{noCache}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 22 | my $raw = $args->{raw}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | my $allow_cache_for_root = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | $self->{localStorageOptions} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | ? $self->{localStorageOptions}->{allow_cache_for_root} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 22 | ▶ | : 0 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | # If running as UID=0, disabled the cache unless explicitely allowed | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 22 | ▶ | if ( $> == 0 and !$allow_cache_for_root ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$> == 0 and not $allow_cache_for_root
MC/DC0%0/2
$> == 0 and not $allow_cache_for_root
$> == 0
not $allow_cache_for_root
Truth table33%1/3
A and not(B)
A= $> == 0B= not $allow_cache_for_root
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | $noCache = 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | # Use only cache to get conf if $local is set | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 22 | ▶ | if ( !$noCache | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition88%8/9
not $noCache and $local and ref $self->{"refLocalStorage"} and $res = $self->{"refLocalStorage"}->get("conf")
not $noCache and $local and ref $self->{"refLocalStorage"}
not $noCache and $local
MC/DC75%3/4
not $noCache and $local and ref $self->{"refLocalStorage"} and $res = $self->{"refLocalStorage"}->get("conf")
not $noCache
$local
ref $self->{"refLocalStorage"}
$res = $self->{"refLocalStorage"}->get("conf")
Truth table80%4/5
not(A) and B and C and D
A= not $noCacheB= $localC= ref $self->{"refLocalStorage"}D= $res = $self->{"refLocalStorage"}->get("conf")
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | and $local | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | and ref( $self->{refLocalStorage} ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | and $res = $self->{refLocalStorage}->get('conf') ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 5 | $msg .= "Get configuration from cache without verification.\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | # Check cfgNum in conf backend | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | # Get conf in backend only if a newer configuration is available | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 17 | ▶ | $cfgNum ||= $self->lastCfg( { noCache => $noCache } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$cfgNum ||= $self->lastCfg({"noCache", $noCache})
MC/DC100%2/2
$cfgNum ||= $self->lastCfg({"noCache", $noCache})
$cfgNum
$self->lastCfg({"noCache", $noCache})
Truth table100%3/3
A ||= B
A= $cfgNumB= $self->lastCfg({"noCache", $noCache})
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 17 | ▶ | unless ($cfgNum) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 1 | $msg .= "Error: No configuration available in backend.\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 17 | my $r; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 17 | ▶ | unless ( ref( $self->{refLocalStorage} ) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 3 | $msg .= "Get remote configuration (localStorage unavailable).\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 3 | $r = $self->getDBConf( { cfgNum => $cfgNum } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 3 | ▶ | return undef unless ( $r->{cfgNum} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 3 | $self->setDefault( $r, $localPrm ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 3 | $self->setValuesFromEnv($r); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 3 | $self->compactConf($r); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 14 | ▶ | eval { $r = $self->{refLocalStorage}->get('conf') } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | if ( !$noCache ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 14 | ▶ | $msg .= "Warn: $@" if ($@); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 14 | ▶ | if ( ref($r) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition77%7/9
ref $r and $r->{"cfgNum"} and $cfgNum and $r->{"cfgNum"} == $cfgNum
ref $r and $r->{"cfgNum"} and $cfgNum
ref $r and $r->{"cfgNum"}
MC/DC50%2/4
ref $r and $r->{"cfgNum"} and $cfgNum and $r->{"cfgNum"} == $cfgNum
ref $r
$r->{"cfgNum"}
$cfgNum
$r->{"cfgNum"} == $cfgNum
Truth table60%3/5
A and B and C and D
A= ref $rB= $r->{"cfgNum"}C= $cfgNumD= $r->{"cfgNum"} == $cfgNum
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | and $r->{cfgNum} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | and $cfgNum | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | and $r->{cfgNum} == $cfgNum ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 1 | $msg .= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | "Configuration unchanged, get configuration from cache.\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 13 | my $r2 = $self->getDBConf( { cfgNum => $cfgNum } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 13 | ▶ | unless ( $r2->{cfgNum} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 1 | ▶ | $r = $self->{refLocalStorage}->get('conf') unless ($r); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 1 | ▶ | $msg .= | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | $r | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | ? "Error: Using previous cached configuration\n" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | : "Error: No configuration found in local cache\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 1 | ▶ | return undef unless ($r); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 12 | $r = $r2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | # Store configuration in cache | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | $self->setLocalConf($r) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | if ( $self->{refLocalStorage} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 13 | ▶ | and ( !$noCache or $noCache != 1 ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition77%7/9
$self->{"refLocalStorage"} and !$noCache || $noCache != 1 and not $raw
$self->{"refLocalStorage"} and !$noCache || $noCache != 1
not $noCache or $noCache != 1
MC/DC50%2/4
$self->{"refLocalStorage"} and !$noCache || $noCache != 1 and not $raw
$self->{"refLocalStorage"}
not $noCache
$noCache != 1
not $raw
Truth table50%3/6
A and not(B) or C and not(D)
A= $self->{"refLocalStorage"}B= not $noCacheC= $noCache != 1D= not $raw
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | and !$raw ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | # Return configuration hash | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 17 | $res = $r; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 22 | $self->setDefault( $res, $localPrm ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 22 | $self->setValuesFromEnv($res); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 22 | $self->compactConf($res); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | # Create cipher object and replace variable placeholder | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 22 | ▶ | unless ($raw) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 21 | $self->replacePlaceholders($res); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 21 | eval { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 21 | $res->{cipher} = Lemonldap::NG::Common::Crypto->new( $res->{key} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 21 | ▶ | if ($@) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | $msg .= "Bad key: $@. \n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 22 | return $res; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | ## @method hashRef setDefault(hashRef conf, hashRef localPrm) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | # Set default params | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | # @param $conf Lemonldap::NG configuration hashRef | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | # @param $localPrm Local parameters | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | # @return conf | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 25 | ▶ | sub setDefault { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setDefault: called CC=8 SCAR=20.9
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 25 | my ( $self, $conf, $localPrm ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 25 | ▶ | if ( defined $localPrm ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 1 | $self->{localPrm} = $localPrm; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 24 | $localPrm = $self->{localPrm}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 25 | my $defaultValues = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | Lemonldap::NG::Common::Conf::DefaultValues->defaultValues(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 25 | ▶ | if ( $localPrm and %$localPrm ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$localPrm and %$localPrm
MC/DC50%1/2
$localPrm and %$localPrm
$localPrm
%$localPrm
Truth table66%2/3
A and B
A= $localPrmB= %$localPrm
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 3 | foreach my $k ( keys %$localPrm ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 3 | $conf->{$k} = $localPrm->{$k}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 25 | foreach my $k ( keys %$defaultValues ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 9675 | ▶ | $conf->{$k} //= $defaultValues->{$k}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$conf->{$k} //= $defaultValues->{$k}
MC/DC0%0/2
$conf->{$k} //= $defaultValues->{$k}
$conf->{$k}
$defaultValues->{$k}
Truth table66%2/3
A //= B
A= $conf->{$k}B= $defaultValues->{$k}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | # Some parameters expect key name (example), not variable ($example) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 25 | ▶ | if ( defined $conf->{whatToTrace} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 25 | $conf->{whatToTrace} =~ s/^\$//; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 25 | return $conf; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 25 | ▶ | sub setValuesFromEnv { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setValuesFromEnv: called CC=2 SCAR=7.1
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 25 | my ( $self, $conf ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | $conf->{hashedSessionStore} = $ENV{LLNG_HASHED_SESSION_STORE} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 25 | ▶ | if $ENV{LLNG_HASHED_SESSION_STORE}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 25 | return $conf; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | ## @method hashRef getLocalConf(string section, string file, int loaddefault) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | # Get configuration from local file | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | # | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | # @param $section Optional section name (default DEFAULTSECTION) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | # @param $file Optional file name (default DEFAULTCONFFILE) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | # @param $loaddefault Optional load default section parameters (default 1) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | # @return Lemonldap::NG configuration | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 15 | ▶ | sub getLocalConf { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getLocalConf: called CC=27 SCAR=44.6
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 15 | my ( $self, $section, $file, $loaddefault ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 15 | my $r = {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 15 | ▶ | $section ||= DEFAULTSECTION; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$section ||= "all"
MC/DC100%1/1
$section ||= "all"
$section
Truth table100%2/2
A
A= $section
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | $file ||= | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | $self->{confFile} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | || $ENV{LLNG_DEFAULTCONFFILE} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 15 | ▶ | || DEFAULTCONFFILE; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%4/8
$file ||= $self->{"confFile"} || $ENV{"LLNG_DEFAULTCONFFILE"} || "/usr/local/lemonldap-ng/etc/lemonldap-ng.ini"
$self->{'confFile'} || $ENV{'LLNG_DEFAULTCONFFILE'} || '/usr/local/lemonldap-ng/etc/lemonldap-ng.ini'
$self->{"confFile"} or $ENV{"LLNG_DEFAULTCONFFILE"}
MC/DC0%0/3
$file ||= $self->{"confFile"} || $ENV{"LLNG_DEFAULTCONFFILE"} || "/usr/local/lemonldap-ng/etc/lemonldap-ng.ini"
$file
$self->{"confFile"}
$ENV{"LLNG_DEFAULTCONFFILE"}
Truth table0%0/4
A ||= B or C
A= $fileB= $self->{"confFile"}C= $ENV{"LLNG_DEFAULTCONFFILE"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 15 | ▶ | $loaddefault = 1 unless ( defined $loaddefault ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 15 | my $cfg; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | # First, search if this file has been parsed | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 15 | ▶ | unless ( $cfg = $iniObj->{$file} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | # If default configuration cannot be read | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | # - Error if configuration section is requested | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | # - Silent exit for other section requests | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 15 | ▶ | if ( open( my $fh, '<', $file ) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | # Parse ini file | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 15 | $cfg = Config::IniFiles->new( -file => $fh, -allowcontinue => 1 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 15 | close($fh); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | ▶ | if ( $section eq CONFSECTION ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | $msg .= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | "Cannot read $file to get configuration access parameters: $!\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | return $r; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | return $r; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 15 | ▶ | unless ( defined $cfg ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | $msg .= "Local config error: " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | . ( join "\n", @Config::IniFiles::errors ) . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | return $r; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | # Check if default section exists | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 15 | ▶ | unless ( $cfg->SectionExists(DEFAULTSECTION) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | $msg .= "Default section (" . DEFAULTSECTION . ") is missing. \n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | return $r; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | # Check if configuration section exists | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 15 | ▶ | if ( $section eq CONFSECTION and !$cfg->SectionExists(CONFSECTION) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$section eq "configuration" and not $cfg->SectionExists("configuration")
MC/DC0%0/2
$section eq "configuration" and not $cfg->SectionExists("configuration")
$section eq "configuration"
not $cfg->SectionExists("configuration")
Truth table66%2/3
A and not(B)
A= $section eq "configuration"B= not $cfg->SectionExists("configuration")
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | $msg .= "Configuration section (" . CONFSECTION . ") is missing.\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | return $r; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | # First load all default section parameters | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 15 | ▶ | if ($loaddefault) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 3 | foreach ( $cfg->Parameters(DEFAULTSECTION) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 15 | $r->{$_} = $cfg->val( DEFAULTSECTION, $_ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 15 | ▶ | if ( $_ eq "require" ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | foreach my $require ( split /[,\s]+/, $r->{$_} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | eval { require $require }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | ▶ | $msg .= "Error: $@" if ($@); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 15 | ▶ | if ( $r->{$_} =~ /^[{\[].*[}\]]$/ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$r->{$_} =~ /^[{\[].*[}\]]$/ or $r->{$_} =~ /^sub\s*{.*}$/
MC/DC0%0/2
$r->{$_} =~ /^[{\[].*[}\]]$/ or $r->{$_} =~ /^sub\s*{.*}$/
$r->{$_} =~ /^[{\[].*[}\]]$/
$r->{$_} =~ /^sub\s*{.*}$/
Truth table33%1/3
A or B
A= $r->{$_} =~ /^[{\[].*[}\]]$/B= $r->{$_} =~ /^sub\s*{.*}$/
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | || $r->{$_} =~ /^sub\s*{.*}$/ ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | eval "\$r->{$_} = $r->{$_}"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | ▶ | if ($@) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | $msg .= "Warn: error in file $file: $@.\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | return $r; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | # If we have an additional section to load | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 15 | ▶ | if ( $section ne DEFAULTSECTION and $cfg->SectionExists($section) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$section ne "all" and $cfg->SectionExists($section)
MC/DC50%1/2
$section ne "all" and $cfg->SectionExists($section)
$section ne "all"
$cfg->SectionExists($section)
Truth table66%2/3
A and B
A= $section ne "all"B= $cfg->SectionExists($section)
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | # Check if requested section exists | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | # Load section parameters | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 12 | foreach ( $cfg->Parameters($section) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 36 | $r->{$_} = $cfg->val( $section, $_ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | # Remove spaces before and after value (#1488) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 36 | $r->{$_} =~ s/^\s*(.+?)\s*/$1/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 36 | ▶ | if ( $r->{$_} =~ /^[{\[].*[}\]]$/ || $r->{$_} =~ /^sub\s*{.*}$/ ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$r->{$_} =~ /^[{\[].*[}\]]$/ or $r->{$_} =~ /^sub\s*{.*}$/
MC/DC50%1/2
$r->{$_} =~ /^[{\[].*[}\]]$/ or $r->{$_} =~ /^sub\s*{.*}$/
$r->{$_} =~ /^[{\[].*[}\]]$/
$r->{$_} =~ /^sub\s*{.*}$/
Truth table66%2/3
A or B
A= $r->{$_} =~ /^[{\[].*[}\]]$/B= $r->{$_} =~ /^sub\s*{.*}$/
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 9 | eval "\$r->{$_} = $r->{$_}"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 9 | ▶ | if ($@) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | $msg .= "Warn: error in file $file: $@.\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | return $r; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 15 | $self->replacePlaceholders($r); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 15 | return $r; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | ## @method void setLocalConf(hashRef conf) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | # Store $conf in the local cache. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | # @param $conf Lemonldap::NG configuration hashRef | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 12 | ▶ | sub setLocalConf { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setLocalConf: called CC=2 SCAR=7.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 12 | my ( $self, $conf ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 12 | eval { $self->{refLocalStorage}->set( "conf", $conf ) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 12 | ▶ | $msg .= "Warn: $@\n" if ($@); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | ## @method hashRef getDBConf(hashRef args) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | # Get configuration from remote storage system. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | # @param $args hashRef that must contains a key "cfgNum" (number of the wanted | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | # configuration) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | # @return Lemonldap::NG configuration hashRef | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 16 | ▶ | sub getDBConf { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getDBConf: called CC=6 SCAR=20.2
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 16 | my ( $self, $args ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 16 | my $cfgNum = $args->{cfgNum}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 16 | ▶ | return undef unless $cfgNum; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 15 | ▶ | if ( $cfgNum < 0 ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 0 | my @a = $self->available(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 0 | ▶ | $cfgNum = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | ( @a + $cfgNum > 0 ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | ? ( $a[ $#a + $cfgNum ] ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | : $a[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 15 | my $conf = $self->load($cfgNum); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 15 | ▶ | return undef if $conf == "-1"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | $msg .= "Get configuration $conf->{cfgNum}.\n" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 15 | ▶ | if ( defined $conf->{cfgNum} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 15 | return $conf; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 118 | ▶ | sub _launch { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_launch: called CC=5 SCAR=16.2
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 118 | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 118 | my $sub = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 118 | my @res; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 118 | eval { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 0 | ▶ | local $SIG{ALRM} = sub { die "TIMEOUT\n" }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 118 | eval { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 118 | ▶ | alarm( $self->{confTimeout} || 10 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'confTimeout'} || 10
MC/DC0%0/1
$self->{'confTimeout'} || 10
$self->{'confTimeout'}
Truth table50%1/2
A
A= $self->{'confTimeout'}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 118 | @res = &{ $self->{type} . "::$sub" }( $self, @_ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 118 | alarm 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 118 | ▶ | die $@ if $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 118 | ▶ | if ($@) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 14 | $msg .= $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 14 | print STDERR "MSG $msg\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 14 | return undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 104 | ▶ | return wantarray ? (@res) : $res[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | ## @method boolean prereq() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | # Call prereq() from the $self->{type} package. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | # @return True if succeed | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 27 | ▶ | sub prereq { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
prereq: called CC=1 SCAR=0.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 27 | return shift->_launch( 'prereq', @_ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | ## @method @ available() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | # Call available() from the $self->{type} package. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | # @return list of available configuration numbers | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 0 | ▶ | sub available { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
available: not called CC=1 SCAR=6.9
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 0 | return shift->_launch( 'available', @_ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | ## @method int lastCfg(hashRef args) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | # Call lastCfg() from the $self->{type} package. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | # | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | # When the backend call fails (returns undef/0) and a populated localStorage | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | # is available, returns the cfgNum of the cached configuration except if | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | # noCache is set. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | # | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | # @param $args Optional hashRef, recognized keys: noCache | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | # @return Number of the last configuration available, 0 on failure | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 33 | ▶ | sub lastCfg { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lastCfg: called CC=8 SCAR=21.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 33 | my ( $self, $args ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 33 | ▶ | $args ||= {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args ||= {}
MC/DC100%1/1
$args ||= {}
$args
Truth table100%2/2
A
A= $args
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 33 | my $r = $self->_launch('lastCfg'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 33 | ▶ | return $r if $r; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 13 | ▶ | if ( !$args->{noCache} and ref( $self->{refLocalStorage} ) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $args->{"noCache"} and ref $self->{"refLocalStorage"}
MC/DC100%2/2
not $args->{"noCache"} and ref $self->{"refLocalStorage"}
not $args->{"noCache"}
ref $self->{"refLocalStorage"}
Truth table100%3/3
not(A) and B
A= not $args->{"noCache"}B= ref $self->{"refLocalStorage"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 1 | my $cached; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 1 | eval { $cached = $self->{refLocalStorage}->get('conf') }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 1 | ▶ | $msg .= "Warn: $@\n" if $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 1 | ▶ | if ( ref($cached) and $cached->{cfgNum} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $cached and $cached->{"cfgNum"}
MC/DC0%0/2
ref $cached and $cached->{"cfgNum"}
ref $cached
$cached->{"cfgNum"}
Truth table33%1/3
A and B
A= ref $cachedB= $cached->{"cfgNum"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 1 | $msg .= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | "lastCfg failed, falling back to cached configuration " | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | . "(cfgNum=$cached->{cfgNum}).\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 1 | return $cached->{cfgNum}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 12 | return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | ## @method boolean lock() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | # Call lock() from the $self->{type} package. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | # @return True if succeed | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 0 | ▶ | sub lock { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lock: not called CC=1 SCAR=6.9
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 0 | return shift->_launch( 'lock', @_ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | ## @method boolean isLocked() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | # Call isLocked() from the $self->{type} package. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | # @return True if database is locked | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 0 | ▶ | sub isLocked { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
isLocked: not called CC=1 SCAR=6.9
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 0 | return shift->_launch( 'isLocked', @_ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | ## @method boolean unlock() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | # Call unlock() from the $self->{type} package. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | # @return True if succeed | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 0 | ▶ | sub unlock { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unlock: not called CC=1 SCAR=6.9
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 0 | return shift->_launch( 'unlock', @_ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | ## @method int store(hashRef conf) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | # Call store() from the $self->{type} package. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | # @param $conf Lemondlap configuration serialized | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | # @return Number of new configuration stored if succeed, 0 else. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 25 | ▶ | sub store { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
store: called CC=1 SCAR=0.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 25 | return shift->_launch( 'store', @_ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | ## @method load(int cfgNum, arrayRef fields) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | # Call load() from the $self->{type} package. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | # @return Lemonldap::NG Configuration hashRef if succeed, 0 else. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | 33 | ▶ | sub load { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
load: called CC=1 SCAR=0.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 33 | return shift->_launch( 'load', @_ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | ## @method boolean delete(int cfgNum) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | # Call delete() from the $self->{type} package. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | # @param $cfgNum Number of configuration to delete | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | # @return True if succeed | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | 0 | ▶ | sub delete { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
delete: not called CC=2 SCAR=17.9
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | 0 | my ( $self, $c ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 0 | my @a = $self->available(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 0 | ▶ | if ( grep( /^$c$/, @a ) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 0 | return $self->_launch( 'delete', $c ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | 0 | return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | 0 | ▶ | sub logError { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
logError: not called CC=1 SCAR=6.9
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | 0 | return shift->_launch( 'logError', @_ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 16080 | ▶ | sub _substPlaceHolders { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_substPlaceHolders: called CC=3 SCAR=11.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | 16080 | my ( $self, $string, $placeholder_config ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | 16080 | ▶ | return $string unless $string; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | 16080 | ▶ | while ( my ( $key, $value ) = each %$placeholder_config ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 817 | $string =~ s/%\Q$key\E:(.*?)%/$value->($1)/ge; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 16080 | return $string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | ## @method void replacePlaceholders(res: LLNG_Conf) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | # | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | # Recursively replace %SERVERENV:VariableName% by $ENV{VariableName} value | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | 47 | ▶ | sub replacePlaceholders { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
replacePlaceholders: called CC=5 SCAR=16.1
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | 47 | my ( $self, $conf ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 47 | my $placeholder_config = {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 47 | ▶ | if ( $self->{useServerEnv} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | 6 | ▶ | $placeholder_config->{SERVERENV} = sub { $ENV{ $_[0] } }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | 47 | ▶ | if ( my $moduleList = $self->{configPlaceHolderModules} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | 2 | for my $moduledef ( split( /[,\s]+/, $moduleList ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | 2 | ▶ | if ( my ( $prefix, $module ) = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | $moduledef =~ /(\w+)\s*=\s*([\w:]+)/ ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | 2 | eval "require $module"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | $placeholder_config->{$prefix} = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 2 | ▶ | sub { $module->replace( $self, $_[0] ) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | 47 | return $self->_replacePlaceholder_recurse( $conf, $placeholder_config ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | 677 | ▶ | sub _replacePlaceholder_recurse { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_replacePlaceholder_recurse: called CC=9 SCAR=22.1
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | 677 | my ( $self, $conf, $placeholder_config ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | 677 | ▶ | if ( ref $conf eq 'HASH' ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 654 | foreach my $oldkey ( keys %$conf ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | 9004 | my $key = $self->_substPlaceHolders( $oldkey, $placeholder_config ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | 9004 | ▶ | if ( $key ne $oldkey ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | 1 | $conf->{$key} = delete $conf->{$oldkey}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | 9004 | ▶ | next unless ( $conf->{$key} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 7618 | ▶ | if ( ref $conf->{$key} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | 630 | $self->_replacePlaceholder_recurse( $conf->{$key}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | $placeholder_config ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | 6988 | $conf->{$key} = $self->_substPlaceHolders( $conf->{$key}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | $placeholder_config ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | elsif ( ref $conf eq 'ARRAY' ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | 23 | ▶ | for ( my $i = 0 ; $i < @$conf ; $i++ ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 88 | ▶ | if ( ref $conf->[$i] ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | 0 | $self->_replacePlaceholder_recurse( $conf->[$i], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | $placeholder_config ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | 88 | $conf->[$i] = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | $self->_substPlaceHolders( $conf->[$i], $placeholder_config ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | 16 | 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | __END__ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||