From 6d15dbec3a82abb4b4e5470caa69fb26409d447a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Fri, 17 May 2024 07:19:46 -1000 Subject: [PATCH] Simplify type checking The typing system allows us to build more straightforward type checking, while here replace some conditional constructs to non-conditional ones as we usualy do nowadays. --- templates/mod/_require.epp | 8 ++++---- templates/mod/geoip.conf.epp | 6 +----- templates/mod/negotiation.conf.epp | 14 ++------------ templates/mod/pagespeed.conf.epp | 2 +- templates/mod/proxy.conf.epp | 6 +----- templates/mod/reqtimeout.conf.epp | 6 +----- templates/mod/ssl.conf.epp | 2 +- 7 files changed, 11 insertions(+), 33 deletions(-) diff --git a/templates/mod/_require.epp b/templates/mod/_require.epp index 577e679a0c..4e12043b8e 100644 --- a/templates/mod/_require.epp +++ b/templates/mod/_require.epp @@ -1,12 +1,12 @@ -<% if type($requires, 'generalized') == String { -%> +<% if $requires =~ String { -%> <%- if !($requires.downcase in ['', 'unmanaged']) { -%> Require <%= $requires %> <%- } -%> -<% }elsif String(type($requires, 'generalized')).index('Array') == 0 { -%> +<% } elsif $requires =~ Array { -%> <%- $requires.each |$req| { -%> Require <%= $req %> <%- } -%> -<% }elsif String(type($requires, 'generalized')).index('Hash') == 0 { -%> +<% } elsif $requires =~ Hash { -%> <%- if $requires['enforce'] and $requires['enforce'].downcase in ['all', 'none', 'any'] { -%> <%- $enforce_str = "Require${requires['enforce'].capitalize}>\n" -%> <%- $enforce_open = " <${enforce_str}" -%> @@ -20,7 +20,7 @@ <%- $enforce_close = '' -%> <%- $indentation = '' -%> <%- } -%> - <%- if $requires['requires'] and String(type($requires['requires'], 'generalized')).index('Array') == 0 { -%> + <%- if $requires['requires'] and $requires['requires'] =~ Array { -%> <%# %><%= $enforce_open -%> <%- $requires['requires'].each |$req| { -%> <%# %> <%= $indentation -%>Require <%= $req %> diff --git a/templates/mod/geoip.conf.epp b/templates/mod/geoip.conf.epp index 309e2170f5..c1efd706a1 100644 --- a/templates/mod/geoip.conf.epp +++ b/templates/mod/geoip.conf.epp @@ -1,12 +1,8 @@ GeoIPEnable <%= apache::bool2httpd($enable) %> <%- if $db_file and !($db_file in [ false, 'false', '' ]) { -%> - <%- if String(type($db_file, 'generalized')).index('Array') == 0 { -%> - <%- Array($db_file).each |$file| { -%> + <%- [$db_file].flatten.each |$file| { -%> GeoIPDBFile <%= $file %> <%= $flag %> - <%- } -%> - <%- } else { -%> -GeoIPDBFile <%= $db_file %> <%= $flag %> <%- } -%> <%- } -%> GeoIPOutput <%= $output %> diff --git a/templates/mod/negotiation.conf.epp b/templates/mod/negotiation.conf.epp index 5183e2b8fb..df7cabd9b1 100644 --- a/templates/mod/negotiation.conf.epp +++ b/templates/mod/negotiation.conf.epp @@ -1,12 +1,2 @@ -<% if String(type($language_priority, 'generalized')).index('Array') == 0 { -%> - <%- $language_priority_updated = $language_priority.join(' ') -%> -<% } else { -%> - <%- $language_priority_updated = $language_priority -%> -<% } -%> -<% if String(type($force_language_priority, 'generalized')).index('Array') == 0 { -%> - <%- $force_language_priority_updated = $force_language_priority.join(' ') -%> -<% } else { -%> - <%- $force_language_priority_updated = $force_language_priority -%> -<% } -%> -LanguagePriority <%= $language_priority_updated %> -ForceLanguagePriority <%= $force_language_priority_updated %> +LanguagePriority <%= [$language_priority].flatten.join(' ') %> +ForceLanguagePriority <%= [$force_language_priority].flatten.join(' ') %> diff --git a/templates/mod/pagespeed.conf.epp b/templates/mod/pagespeed.conf.epp index 840a8eeaab..081758a52b 100644 --- a/templates/mod/pagespeed.conf.epp +++ b/templates/mod/pagespeed.conf.epp @@ -78,7 +78,7 @@ ModPagespeedMessageBufferSize <%= $message_buffer_size %> SetHandler mod_pagespeed_message -<% if String(type($additional_configuration, 'generalized')).index('Array') == 0 { -%> +<% if $additional_configuration =~ Array { -%> <%= $additional_configuration.join("\n") %> <% } else { -%> <% $additional_configuration.each |$key, $value| { -%> diff --git a/templates/mod/proxy.conf.epp b/templates/mod/proxy.conf.epp index b9aca2e969..3fad4efa24 100644 --- a/templates/mod/proxy.conf.epp +++ b/templates/mod/proxy.conf.epp @@ -10,11 +10,7 @@ <% if $proxy_requests != 'Off' or ( $allow_from and ! $allow_from.empty ) { -%> - <%- if String(type($allow_from, 'generalized')).index('Array') == 0 { -%> - Require ip <%= $allow_from.join(" ") %> - <%- } else { -%> - Require ip <%= $allow_from %> - <%- } -%> + Require ip <%= [$allow_from].flatten.join(' ') %> <% } -%> diff --git a/templates/mod/reqtimeout.conf.epp b/templates/mod/reqtimeout.conf.epp index a62b4b69ad..633e9db0fa 100644 --- a/templates/mod/reqtimeout.conf.epp +++ b/templates/mod/reqtimeout.conf.epp @@ -1,8 +1,4 @@ -<% if type($timeouts, 'generalized') == String { -%> -RequestReadTimeout <%= $timeouts -%> -<% } else { -%> - <%- $timeouts.each |$timeout| { -%> +<%- [$timeouts].flatten.each |$timeout| { -%> RequestReadTimeout <%= $timeout %> - <%- } -%> <% } -%> diff --git a/templates/mod/ssl.conf.epp b/templates/mod/ssl.conf.epp index 39c2f82703..2aa1b885ce 100644 --- a/templates/mod/ssl.conf.epp +++ b/templates/mod/ssl.conf.epp @@ -33,7 +33,7 @@ SSLStaplingReturnResponderErrors <%= apache::bool2httpd($ssl_stapling_return_errors) %> <%- } -%> SSLStaplingCache "shmcb:<%= $_stapling_cache %>" - <%- if String(type($ssl_cipher, 'generalized')).index('Hash') == 0 { -%> + <%- if $ssl_cipher =~ Hash { -%> <%- $ssl_cipher.map |$protocol, $cipher| { -%> SSLCipherSuite <%= $protocol %> <%= $cipher %> <%- } -%>