The first thing I intend to do is to make a copy of config2.pm in a temporary directory without the values in the hash.
I would actually suggest going the other way around - removing sensitive data is more brittle than not including it in the first place. One common approach is to package a template configuration file with dummy values as placeholders along with everything else, and then have the actual configuration file reside only locally, for example in the user's home directory, or on *NIXish machines in /etc. That way, when you bundle up your application, you won't accidentally package up your sensitive data as well. Or at the very least, keep a config2.pm.templ template file for packaging, and make sure not to package up your actual config2.pm.
Can you "use" a lexical variable?
If you mean accessing a my variable in config2.pm that's loaded via use config2;? No, at least not without a little bit of trickery, which is why typically package variables (our) are used for that kind of thing.
what is a good choice for compression software?
I'd suggest ZIP, it's a common cross-platform format. As for support in Perl, there's the core modules IO::Compress::Zip and IO::Uncompress::Unzip, and the CPAN module Archive::Zip.
Having said all that, here's one way to produce a template file for the example data you showed. I'm using do to load it, which means that you must trust the contents of this file as it will be executed.
Input (config2.pm):
$CONFIG = { my_github => { email => "me\@example.com", password => "PaSsWoRd" }, my_sftp => { domain => "example.com", password => "PaSsWoRd", username => "sftpuser" } };
Code:
use warnings; use strict; use Data::Dumper; my $file = '/path/to/config2.pm'; my $templ = '/path/to/config2.pm.templ'; our $CONFIG; if (not my $return = do $file) { die "couldn't parse $file: $@" if $@; die "couldn't do $file: $!" unless defined $return; die "couldn't run $file" unless $return; } for my $hash (values %$CONFIG) { for my $val (values %$hash) { $val = 'redacted'; } } open my $fh, '>', $templ or die "$templ: $!"; print {$fh} Data::Dumper->new([$CONFIG],['$CONFIG']) ->Useqq(1)->Sortkeys(1)->Quotekeys(0)->Dump; close $fh;
Output (config2.pm.templ):
$CONFIG = { my_github => { email => "redacted", password => "redacted" }, my_sftp => { domain => "redacted", password => "redacted", username => "redacted" } };
In reply to Re: redacting from config hash
by haukex
in thread redacting from config hash
by Aldebaran
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |