Commit | Line | Data |
21baaef0 |
1 | package Promulger::Config; |
9bfd7b60 |
2 | use strict; |
3 | use warnings; |
4 | |
5 | use Config::General; |
21baaef0 |
6 | |
7 | my $config; |
9bfd7b60 |
8 | |
0b07d53c |
9 | my @NECESSARY = qw/aliases list_home/; |
10 | |
9bfd7b60 |
11 | sub load_config { |
12 | my ($class, $config_file) = @_; |
13 | $config = { Config::General->new($config_file)->getall }; |
14 | $config->{config_file} = $config_file; |
0b07d53c |
15 | |
16 | $class->validate_config($config); |
17 | |
21baaef0 |
18 | return $config; |
19 | }; |
20 | |
9bfd7b60 |
21 | sub config { |
22 | die "No configuration loaded" unless $config; |
23 | return $config; |
24 | } |
25 | |
0b07d53c |
26 | sub validate_config { |
27 | my ($class, $config) = @_; |
28 | for my $nec (@NECESSARY) { |
29 | die "Required key '${nec}' missing in " . $config->{config_file} |
30 | unless $config->{$nec}; |
31 | } |
32 | |
33 | die "cannot read aliases file " . $config->{aliases} |
34 | unless -r $config->{aliases}; |
35 | die "cannot write to list home " . $config->{list_home} |
36 | unless -w $config->{list_home}; |
37 | } |
38 | |
21baaef0 |
39 | 'http://reductivelabs.com/products/puppet/'; |