Skip to content

Commit

Permalink
Further expand generic 'cache' entry
Browse files Browse the repository at this point in the history
  • Loading branch information
tgreenx committed Nov 13, 2023
1 parent efb6118 commit 08f88cd
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/Zonemaster/Engine/Profile.pm
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use Data::Dumper;
use Net::IP::XS;
use Log::Any qw( $log );
use YAML::XS qw();
use Scalar::Util qw( looks_like_number );

$YAML::XS::Boolean = "JSON::PP";

Expand All @@ -28,16 +29,25 @@ my %profile_properties_details = (
my @allowed_keys = ( 'redis' );
foreach my $cache_database ( keys %{$_[0]} ) {
if ( not grep( /^$cache_database$/, @allowed_keys ) ) {
die "Property cache keys have " . scalar @allowed_keys . " possible values : " . join(", ", @allowed_keys);
die "Property cache keys have " . scalar @allowed_keys . " possible values: " . join(", ", @allowed_keys);
}

if ( not scalar keys %{ $_[0]->{$cache_database} } ) {
die "Property cache.$cache_database has no items";
}
else {
my @allowed_subkeys;
if ( $cache_database eq 'redis' ) {
@allowed_subkeys = ( 'server', 'expire' );
}

foreach my $key ( keys %{ $_[0]->{$cache_database} } ) {
if ( not grep( /^$key$/, @allowed_subkeys ) ) {
die "Property cache.$cache_database subkeys have " . scalar @allowed_subkeys . " possible values: " . join(", ", @allowed_subkeys);
}

die "Property cache.$cache_database.$key has a NULL or empty item" if not $_[0]->{$cache_database}->{$key};
die "Property cache.$cache_database.$key has a negative value" if ( $key eq 'expire' and scalar $_[0]->{$cache_database}->{$key} < 0 ) ;
die "Property cache.$cache_database.$key has a negative value" if ( looks_like_number( $_[0]->{$cache_database}->{$key} ) and $_[0]->{$cache_database}->{$key} < 0 ) ;
}
}
}
Expand Down

0 comments on commit 08f88cd

Please sign in to comment.