Advanced-Config
view release on metacpan or search on metacpan
lib/Advanced/Config/Examples.pm view on Meta::CPAN
my $cfg = Advanced::config->new ("complex.cfg")->load_config();
=item BREAKING YOUR CONFIG FILE INTO SECTIONS (section.cfg)
abc = lmn # Has no section, so considered in section "main".
user = me
pwd = nope!
[ host 1 ]
abc = xyz
pwd = password1
[host 2]
abc=abc
pwd = password2
[ HOST 3 ]
abc = 123
pwd = password3
[ HOST 2 ]
efg = repeat # Section "host 2" has 3 tags in it. "abc", "efg" & "pwd".
[ Host 4 ]
user = you
Please note that section names are case insensitive and the tag abc's value
depends on what section of the config file you are currently looking at. This
way you may repeat tags between sections and know that each section is
lib/Advanced/Config/Examples.pm view on Meta::CPAN
To load it into memory do:
my $cfg = Advanced::config->new ("product-1.cfg",
{ "assign => "::", "comment" => ";", "source" => "include" }
)->load_config();
=item ENCRYPTING/DECRYPTING CONFIG FILES
Sometimes you need to protect sensitive information inside your config files.
Such as the user names and passwords that your application requires to run.
This module allows this at the individual tag/value pair level. Not at the
file level!
The 1st example shows tags whose values are pending the encryption process.
While the 2nd example shows what happens after it's been encrypted. You can
have config files that have both pending and encrypted tags in it. As well
as tags whose values are never encrypted. It is controlled by having the
appropriate label in the comment after the tag/value pair.
# Waiting to encrypt these values ...
my_username_1 = "anonymous" # ENCRYPT
my_password_1 = "This is too much fun!" # ENCRYPT me ...
# They've already been encypted!
my_username_2 = '4aka54D3eZ4aea5' # DECRYPT
my_password_2 = '^M^Mn1\pmeaq>n\q?Z[x537z3A' # DECRYPT me ...
# This value will never be encrytped/decrypted ...
dummy = "Just some strange value that is always in clear text."
The encrypted value is automatically decrypted for you when the config file
is loaded into memory. So it's already in clear text when C<get_value()> is
called. See L<Advanced::Config::Options> for more details on the options
used to control the encrypt/decrypt process. See C<encrypt_config_file()> in
L<Advanced::Config> for how to encrypt the contents of the config file itself.
lib/Advanced/Config/Options.pm view on Meta::CPAN
export tag = value # Optional unix type shell script prefix.
set tag = value # Optional windows type batch file prefix.
These prefixes allow you to easily use shell/batch files as config files if
they contain no logic.
B<hide_lbl> - Defaults to "B<HIDE>". Tells this module that this tag's value
contains sensitive information. So when fish logging is turned on, this module
will never write it to these logs. If the parser thinks a tag's name suggests
it's a password, it will assume that you put this label in the comment. This
is what triggers the sensitive/mask arguments and return values that some
methods use.
B<encrypt_lbl> - Defaults to "B<ENCRYPT>". Tells this module that you are
waiting for this tag's value to be encrypted in the config file. It assumes
the value is still in clear text. When present it assumes the value is
sensitive as well.
B<decrypt_lbl> - Defaults to "B<DECRYPT>". Tells this module that this value
has already been encrypted and needs to be decrypted before it is used. When
lib/Advanced/Config/Options.pm view on Meta::CPAN
{
DBUG_ENTER_FUNC ();
# ---------------------------------------------------------------------
# Make sure no hash value is undef !!!
# ---------------------------------------------------------------------
# You can only add to this list, you can't remove anything from it!
# See should_we_hide_sensitive_data () on how this list is used.
DBUG_PRINT ("INFO", "Initializing the tag patterns to hide from fish ...");
push ( @hide_from_fish, "password" );
push ( @hide_from_fish, "pass" );
push ( @hide_from_fish, "pwd" );
# ---------------------------------------------------------------------
DBUG_PRINT ("INFO", "Initializing the READ options global hash ...");
# Should always be set in the constructor ...
$default_read_opts{tag_case} = 0; # Case sensitive tags.
# The generic options ...
lib/Advanced/Config/Options.pm view on Meta::CPAN
# ==============================================================
=item make_it_sensitive ( @patterns )
Add these pattern(s) to the internal list of patterns that this module considers
sensitive. Should any tag contain this pattern, that tag's value will be
masked when written to this module's internal logs. Leading/trailing spaces
will be ignored in the pattern. Wild cards are not honored.
The 3 default patterns are password, pass, and pwd.
This pattern affects all L<Advanced::Config> objects loaded into memory. Not
just the current one.
=cut
sub make_it_sensitive
{
DBUG_ENTER_FUNC ( @_ );
my @tags = @_;
t/config/28-sensitive.cfg view on Meta::CPAN
# to the tests being performed for these test cases.
# --------------------------------------------------------------------------
00_has_decryption = 06_decode_y 30_decode_y
00_has_variables = 08_pig_n 09_cow_y 10_sheep_y 11_hen_y 12_rooster_y 13_cat_y 16_indirect_y 19_indirect_y 22_indirect_n 23_decode_y 25_indirect_y 26_indirect_y 27_indirect_n
encrypted-m = So what?
01_tom_n = one
02_dick_n = two
03_harry_n = three
04_password_y = four
05_hidden_y = five # HIDE
06_decode_y = 'g`ey}hhub`Q&"' # DECRYPT
07_encode_y = seven # ENCRYPT
08_pig_n = ${01_tom_n}
09_cow_y = ${04_password_y}-b
10_sheep_y = ${05_hidden_y}-b
11_hen_y = ${06_decode_y}-b
12_rooster_y = ${07_encode_y}-b
13_cat_y = ${01_tom_n} ${04_password_y} ${02_dick_n}
14_bird_n = 15_eagle_y
15_eagle_y = majestic # HIDE
16_indirect_y = ${!14_bird_n}-bird
17_dog_y = 18_wolf_n # HIDE
18_wolf_n = it's a wild dog
19_indirect_y = ${!17_dog_y}-!
20_bear_n = 21_black_n
21_black_n = It's black
22_indirect_n = ${!20_bear_n}?
23_decode_y = ${19_indirect_y} ${06_decode_y} ${22_indirect_n} ${19_indirect_y}
t/config/28-sensitive.cfg view on Meta::CPAN
30_decode_y = 'Qi\0n Lrd|Wco
&"' # DECRYPT
[ section 01 ]
00_has_decryption = ignored, not used
00_has_variables = ignored, not used
encrypted-01 = So now what?
01_tom_n = one 01
02_dick_n = two 01
03_harry_n = three 01
04_password_y = four 01
05_hidden_y = five 01 # HIDE
06_decode_y = 'g`ey}hhu?-
&"' # DECRYPT
07_encode_y = seven 01 # ENCRYPT
08_pig_n = ${01_tom_n}-1
09_cow_y = ${04_password_y}-1
10_sheep_y = ${05_hidden_y}-1
11_hen_y = ${06_decode_y}-1
12_rooster_y = ${07_encode_y}-1
13_cat_y = ${01_tom_n} ${04_password_y} ${02_dick_n}
14_bird_n = 15_eagle_y
15_eagle_y = majestic # HIDE
16_indirect_y = ${!14_bird_n}-bird
17_dog_y = 18_wolf_n # HIDE
18_wolf_n = it's a wild dog
19_indirect_y = ${!17_dog_y}-!
20_bear_n = 21_black_n
21_black_n = It's black
22_indirect_n = ${!20_bear_n}?
23_decode_y = ${19_indirect_y} ${06_decode_y} ${22_indirect_n} ${19_indirect_y}
t/config/28-sensitive.cfg view on Meta::CPAN
25_indirect_y = ${!24_help_n}-:)
26_indirect_y = ${!06_decode_y}
27_indirect_n = ${!01_tom_n} # No such var!
28_zork_y = sensitive
29_pork_n = not-sensitive
30_decode_y = 'Qi\0n ]ujbJ/<Q&"' # DECRYPT
# Everything in this section is sensitive due to the sections's name!
# So it ignores the "hint" in the tag's name for this section!
[ section password ]
00_has_decryption = ignored, not used
00_has_variables = ignored, not used
encrypted-password = Now what?
01_tom_n = one p
02_dick_n = two p
03_harry_n = three p
04_password_y = four p
05_hidden_y = five p # HIDE
06_decode_y = 'g`ey}hhu}uugvg{Qs' # DECRYPT
07_encode_y = seven p # ENCRYPT
08_pig_n = ${01_tom_n}-p
09_cow_y = ${04_password_y}-p
10_sheep_y = ${05_hidden_y}-p
11_hen_y = ${06_decode_y}-p
12_rooster_y = ${07_encode_y}-p
13_cat_y = ${01_tom_n} ${04_password_y} ${02_dick_n}
14_bird_n = 15_eagle_y
15_eagle_y = majestic # HIDE
16_indirect_y = ${!14_bird_n}-bird
17_dog_y = 18_wolf_n # HIDE
18_wolf_n = it's a wild dog
19_indirect_y = ${!17_dog_y}-!
20_bear_n = 21_black_n
21_black_n = It's black
22_indirect_n = ${!20_bear_n}?
23_decode_y = ${19_indirect_y} ${06_decode_y} ${22_indirect_n} ${19_indirect_y}
( run in 0.524 second using v1.01-cache-2.11-cpan-49f99fa48dc )