From: Chris Nehren Date: Sun, 4 Sep 2011 05:13:13 +0000 (-0400) Subject: sanity checking for the config file X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0b07d53c38311c65891cd1f705e918d0083ffea7;p=p5sagit%2FPromulger.git sanity checking for the config file --- diff --git a/lib/Promulger/Config.pm b/lib/Promulger/Config.pm index 28fec99..47ffee7 100644 --- a/lib/Promulger/Config.pm +++ b/lib/Promulger/Config.pm @@ -6,10 +6,15 @@ use Config::General; my $config; +my @NECESSARY = qw/aliases list_home/; + sub load_config { my ($class, $config_file) = @_; $config = { Config::General->new($config_file)->getall }; $config->{config_file} = $config_file; + + $class->validate_config($config); + return $config; }; @@ -18,4 +23,17 @@ sub config { return $config; } +sub validate_config { + my ($class, $config) = @_; + for my $nec (@NECESSARY) { + die "Required key '${nec}' missing in " . $config->{config_file} + unless $config->{$nec}; + } + + die "cannot read aliases file " . $config->{aliases} + unless -r $config->{aliases}; + die "cannot write to list home " . $config->{list_home} + unless -w $config->{list_home}; +} + 'http://reductivelabs.com/products/puppet/';