Aldebaran has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks, as I continue my headlong assault at friarhood, I'm trying to write up a meditation about Path::Tiny, which I'm re-writing my previous scripts with and writing new code with. The task before me is to bundle up my template and get in online, without publishing any sensitive data. I have no perfect divorce of content and data, but I have confined the stuff I don't want all over the net to one hash in config2.pm . 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.
Can you "use" a lexical variable? What follow are the driver script, output and then utils2.pm, where redact() is to reside.
#!/usr/bin/perl -w use strict; use 5.010; use lib "template_stuff"; use utils1; use utils2; use utf8; use open qw/:std :utf8/; use Path::Tiny; my $current = Path::Tiny->cwd; say "current is $current"; my $return = redact("config2"); __END__ current is /home/bob/1.scripts/pages/1.qy temp dir is /tmp/backup_DEtSio scratch_file is /tmp/backup_DEtSio/batch_01/1.manifest.txt parent is /tmp/backup_DEtSio/batch_01 /tmp/backup_DEtSio $VAR1 = { 'my_sftp' => { 'username' => '', 'password' => '', 'domain' => '' }, 'my_github' => { 'password' => '', 'email' => '' } };
package utils2; require Exporter; use utils1; our @ISA = qw(Exporter); our @EXPORT = qw( redact); sub redact{ use strict; use warnings; use 5.010; use Path::Tiny; my $file = shift; #use $file; resulted in error use config2; my $sub_hash = "my_github"; my $email = $config{$sub_hash}->{'email'}; my $password = $config{$sub_hash}->{'password'}; my $tempdir = Path::Tiny->tempdir('backup_XXXXXX'); say "temp dir is $tempdir"; my $scratch_file = $tempdir->child('batch_01', '1.manifest.txt')->touc +hpath; say "scratch_file is $scratch_file"; my $parent = $scratch_file->parent; say "parent is $parent"; chdir $tempdir unless $tempdir->subsumes(Path::Tiny->cwd); system("pwd"); use Data::Dumper; print Dumper \%config; my $b = "dummy"; return $b; } 1;
Obviously, I edited out the values with the delete key, and I'd like them to simply show "redacted". There are some bad ideas chasing some good ones here. Eventually, I'd like to have an entire directory tree populated in the temp dir and then compressed by some means to a single file. If I'm going to port to windows, what is a good choice for compression software? Thanks for your comment.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: redacting from config hash
by haukex (Archbishop) on Jul 31, 2018 at 05:52 UTC | |
by soonix (Chancellor) on Jul 31, 2018 at 10:44 UTC | |
by Aldebaran (Curate) on Aug 01, 2018 at 01:53 UTC | |
by haukex (Archbishop) on Aug 01, 2018 at 09:16 UTC | |
by Aldebaran (Curate) on Aug 02, 2018 at 23:09 UTC | |
by hippo (Archbishop) on Aug 03, 2018 at 08:34 UTC | |
| |
by haukex (Archbishop) on Aug 03, 2018 at 08:36 UTC | |
| |
by soonix (Chancellor) on Aug 01, 2018 at 12:53 UTC | |
by Aldebaran (Curate) on Aug 02, 2018 at 07:02 UTC |