| 1 |
Custom configuration placeholder |
| 2 |
================================ |
| 3 |
|
| 4 |
.. versionadded:: 2.23.0 |
| 5 |
|
| 6 |
LemonLDAP::NG optionally supports the ``%SERVERENV:VariableName%`` syntax to read configuration values from the environment. |
| 7 |
|
| 8 |
You may also define additional placeholder syntaxes by creating your own Perl module |
| 9 |
|
| 10 |
Enable and configure your module |
| 11 |
-------------------------------- |
| 12 |
|
| 13 |
Edit the ``[configuration]`` section in ``lemonldap-ng.ini`` |
| 14 |
|
| 15 |
.. code:: ini |
| 16 |
|
| 17 |
[configuration] |
| 18 |
|
| 19 |
configPlaceHolderModules=SECRET=Lemonldap::NG::Common::Conf::SecretPlaceholder |
| 20 |
; optionally configure the module here |
| 21 |
; secretPlaceholderConfig=my_config |
| 22 |
|
| 23 |
|
| 24 |
This configuration will call ``Lemonldap::NG::Common::Conf::SecretPlaceholder`` everytime |
| 25 |
``%SECRET:MyVariable%`` is encountered in the configuration. |
| 26 |
|
| 27 |
You can define multiple modules by separating them with a comma: |
| 28 |
|
| 29 |
.. code:: ini |
| 30 |
|
| 31 |
[configuration] |
| 32 |
|
| 33 |
; this will dispatch %SECRET:xx%, %DNS:yy% and %VAULT:zz% to each |
| 34 |
; declared module |
| 35 |
configPlaceHolderModules=SECRET=My::Secret, DNS=My::DNS, VAULT=My::Vault |
| 36 |
|
| 37 |
Write your custom module |
| 38 |
------------------------ |
| 39 |
|
| 40 |
Here is an example of a Perl module that implements a configuration placeholder: |
| 41 |
|
| 42 |
.. code:: perl |
| 43 |
|
| 44 |
# Must be stored in Lemonldap/NG/Common/Conf/SecretPlaceholder.pm |
| 45 |
package Lemonldap::NG::Common::Conf::SecretPlaceholder; |
| 46 |
|
| 47 |
use strict; |
| 48 |
|
| 49 |
# You must define a replace function |
| 50 |
sub replace { |
| 51 |
# The function takes: |
| 52 |
# * current module name |
| 53 |
# * current configuration hash |
| 54 |
# * variable name to look up |
| 55 |
my ( $class, $conf, $variable ) = @_; |
| 56 |
|
| 57 |
# You can read configuration options (vault server IP, etc) |
| 58 |
# from the ini-file configuration here |
| 59 |
my $placeholder_config = $conf->{secretPlaceholderConfig}; |
| 60 |
|
| 61 |
# Obtain and return the value to be used in actual configuration |
| 62 |
my $value = implement_this($variable); |
| 63 |
|
| 64 |
return $value; |
| 65 |
} |
| 66 |
1; |
| 67 |
|