Skip to content

Commit

Permalink
Simplify type checking
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
smortex authored and Ramesh7 committed Jun 6, 2024
1 parent 7c48bce commit 6d15dbe
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 33 deletions.
8 changes: 4 additions & 4 deletions templates/mod/_require.epp
Original file line number Diff line number Diff line change
@@ -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}" -%>
Expand All @@ -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 %>
Expand Down
6 changes: 1 addition & 5 deletions templates/mod/geoip.conf.epp
Original file line number Diff line number Diff line change
@@ -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 %>
Expand Down
14 changes: 2 additions & 12 deletions templates/mod/negotiation.conf.epp
Original file line number Diff line number Diff line change
@@ -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(' ') %>
2 changes: 1 addition & 1 deletion templates/mod/pagespeed.conf.epp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ ModPagespeedMessageBufferSize <%= $message_buffer_size %>
SetHandler mod_pagespeed_message
</Location>

<% if String(type($additional_configuration, 'generalized')).index('Array') == 0 { -%>
<% if $additional_configuration =~ Array { -%>
<%= $additional_configuration.join("\n") %>
<% } else { -%>
<% $additional_configuration.each |$key, $value| { -%>
Expand Down
6 changes: 1 addition & 5 deletions templates/mod/proxy.conf.epp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@

<% if $proxy_requests != 'Off' or ( $allow_from and ! $allow_from.empty ) { -%>
<Proxy *>
<%- 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(' ') %>
</Proxy>
<% } -%>

Expand Down
6 changes: 1 addition & 5 deletions templates/mod/reqtimeout.conf.epp
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
<% if type($timeouts, 'generalized') == String { -%>
RequestReadTimeout <%= $timeouts -%>
<% } else { -%>
<%- $timeouts.each |$timeout| { -%>
<%- [$timeouts].flatten.each |$timeout| { -%>
RequestReadTimeout <%= $timeout %>
<%- } -%>
<% } -%>

2 changes: 1 addition & 1 deletion templates/mod/ssl.conf.epp
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>
<%- } -%>
Expand Down

0 comments on commit 6d15dbe

Please sign in to comment.