Skip to content

Commit 77d3e6c

Browse files
authored
Merge pull request #2252 from ekohl/better-vhost-data-types
Better data types on apache::vhost parameters
2 parents 1186e90 + 8c51550 commit 77d3e6c

File tree

8 files changed

+47
-75
lines changed

8 files changed

+47
-75
lines changed

manifests/vhost.pp

Lines changed: 30 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1800,7 +1800,7 @@
18001800
Variant[Boolean,String] $access_log_syslog = false,
18011801
Variant[Boolean,String] $access_log_format = false,
18021802
Variant[Boolean,String] $access_log_env_var = false,
1803-
Optional[Array] $access_logs = undef,
1803+
Optional[Array[Hash]] $access_logs = undef,
18041804
Boolean $use_servername_for_filenames = false,
18051805
Boolean $use_port_for_filenames = false,
18061806
Optional[Variant[Array[Hash],Hash,String]] $aliases = undef,
@@ -1853,13 +1853,13 @@
18531853
Optional[Variant[Array[String],String]] $redirectmatch_status = undef,
18541854
Optional[Variant[Array[String],String]] $redirectmatch_regexp = undef,
18551855
Optional[Variant[Array[String],String]] $redirectmatch_dest = undef,
1856-
Optional[String] $headers = undef,
1857-
Optional[Array[String]] $request_headers = undef,
1858-
Optional[Array[String]] $filters = undef,
1859-
Optional[Array] $rewrites = undef,
1860-
Optional[String] $rewrite_base = undef,
1861-
Optional[Variant[Array[String],String]] $rewrite_rule = undef,
1862-
Optional[Variant[Array[String],String]] $rewrite_cond = undef,
1856+
Array[String[1]] $headers = [],
1857+
Array[String[1]] $request_headers = [],
1858+
Array[String[1]] $filters = [],
1859+
Array[Hash] $rewrites = [],
1860+
Optional[String[1]] $rewrite_base = undef,
1861+
Optional[String[1]] $rewrite_rule = undef,
1862+
Array[String[1]] $rewrite_cond = [],
18631863
Boolean $rewrite_inherit = false,
18641864
Variant[Array[String],String] $setenv = [],
18651865
Variant[Array[String],String] $setenvif = [],
@@ -1954,11 +1954,11 @@
19541954
Optional[String] $add_default_charset = undef,
19551955
Boolean $modsec_disable_vhost = false,
19561956
Optional[Variant[Hash, Array]] $modsec_disable_ids = undef,
1957-
Optional[Array[String]] $modsec_disable_ips = undef,
1957+
Array[String[1]] $modsec_disable_ips = [],
19581958
Optional[Variant[Hash, Array]] $modsec_disable_msgs = undef,
19591959
Optional[Variant[Hash, Array]] $modsec_disable_tags = undef,
19601960
Optional[String] $modsec_body_limit = undef,
1961-
Optional[Array[Hash]] $jk_mounts = undef,
1961+
Array[Hash] $jk_mounts = [],
19621962
Boolean $auth_kerb = false,
19631963
Enum['on', 'off'] $krb_method_negotiate = 'on',
19641964
Enum['on', 'off'] $krb_method_k5passwd = 'on',
@@ -1997,13 +1997,6 @@
19971997

19981998
$apache_name = $apache::apache_name
19991999

2000-
if $rewrites {
2001-
unless empty($rewrites) {
2002-
$rewrites_flattened = delete_undef_values(flatten([$rewrites]))
2003-
assert_type(Array[Hash], $rewrites_flattened)
2004-
}
2005-
}
2006-
20072000
# Input validation begins
20082001

20092002
if $access_log_file and $access_log_pipe {
@@ -2141,6 +2134,8 @@
21412134
}]
21422135
} elsif $access_logs {
21432136
$_access_logs = $access_logs
2137+
} else {
2138+
$_access_logs = []
21442139
}
21452140

21462141
if $error_log_file {
@@ -2225,13 +2220,6 @@
22252220
}
22262221
}
22272222

2228-
# Load mod_rewrite if needed and not yet loaded
2229-
if $rewrites or $rewrite_cond {
2230-
if ! defined(Class['apache::mod::rewrite']) {
2231-
include apache::mod::rewrite
2232-
}
2233-
}
2234-
22352223
# Load mod_alias if needed and not yet loaded
22362224
if ($scriptalias or $scriptaliases != [])
22372225
or ($aliases and $aliases != [])
@@ -2259,20 +2247,6 @@
22592247
}
22602248
}
22612249

2262-
# Check if mod_headers is required to process $headers/$request_headers
2263-
if $headers or $request_headers {
2264-
if ! defined(Class['apache::mod::headers']) {
2265-
include apache::mod::headers
2266-
}
2267-
}
2268-
2269-
# Check if mod_filter is required to process $filters
2270-
if $filters {
2271-
if ! defined(Class['apache::mod::filter']) {
2272-
include apache::mod::filter
2273-
}
2274-
}
2275-
22762250
# Check if mod_env is required and not yet loaded.
22772251
# create an expression to simplify the conditional check
22782252
$use_env_mod = $setenv and ! empty($setenv)
@@ -2487,13 +2461,12 @@
24872461
}
24882462

24892463
# Template uses:
2490-
# - $access_log
2464+
# - $_access_logs
24912465
# - $_access_log_env_var
24922466
# - $access_log_destination
24932467
# - $_access_log_format
24942468
# - $_access_log_env_var
2495-
# - $access_logs
2496-
if $access_log or $access_logs {
2469+
if !empty($_access_logs) {
24972470
concat::fragment { "${name}-access_log":
24982471
target => "${priority_real}${filename}.conf",
24992472
order => 100,
@@ -2534,7 +2507,9 @@
25342507

25352508
# Template uses:
25362509
# - $headers
2537-
if $headers and ! empty($headers) {
2510+
if ! empty($headers) and $ensure == 'present' {
2511+
include apache::mod::headers
2512+
25382513
concat::fragment { "${name}-header":
25392514
target => "${priority_real}${filename}.conf",
25402515
order => 140,
@@ -2544,7 +2519,9 @@
25442519

25452520
# Template uses:
25462521
# - $request_headers
2547-
if $request_headers and ! empty($request_headers) {
2522+
if ! empty($request_headers) and $ensure == 'present' {
2523+
include apache::mod::headers
2524+
25482525
concat::fragment { "${name}-requestheader":
25492526
target => "${priority_real}${filename}.conf",
25502527
order => 150,
@@ -2613,7 +2590,9 @@
26132590
# - $rewrite_rule
26142591
# - $rewrite_cond
26152592
# - $rewrite_map
2616-
if $rewrites or $rewrite_rule {
2593+
if (! empty($rewrites) or $rewrite_rule) and $ensure == 'present' {
2594+
include apache::mod::rewrite
2595+
26172596
concat::fragment { "${name}-rewrite":
26182597
target => "${priority_real}${filename}.conf",
26192598
order => 190,
@@ -2899,7 +2878,7 @@
28992878
# - $modsec_disable_tags
29002879
# - $modsec_body_limit
29012880
# - $modsec_audit_log_destination
2902-
if $modsec_disable_vhost or $modsec_disable_ids or $modsec_disable_ips or $modsec_disable_msgs or $modsec_disable_tags or $modsec_audit_log_destination {
2881+
if $modsec_disable_vhost or $modsec_disable_ids or !empty($modsec_disable_ips) or $modsec_disable_msgs or $modsec_disable_tags or $modsec_audit_log_destination {
29032882
concat::fragment { "${name}-security":
29042883
target => "${priority_real}${filename}.conf",
29052884
order => 320,
@@ -2909,7 +2888,9 @@
29092888

29102889
# Template uses:
29112890
# - $filters
2912-
if $filters and ! empty($filters) {
2891+
if ! empty($filters) and $ensure == 'present' {
2892+
include apache::mod::filter
2893+
29132894
concat::fragment { "${name}-filters":
29142895
target => "${priority_real}${filename}.conf",
29152896
order => 330,
@@ -2919,7 +2900,9 @@
29192900

29202901
# Template uses:
29212902
# - $jk_mounts
2922-
if $jk_mounts and ! empty($jk_mounts) {
2903+
if !empty($jk_mounts) and $ensure == 'present' {
2904+
include apache::mod::jk
2905+
29232906
concat::fragment { "${name}-jk_mounts":
29242907
target => "${priority_real}${filename}.conf",
29252908
order => 340,

spec/defines/vhost_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@
385385
'redirectmatch_status' => ['404'],
386386
'redirectmatch_regexp' => ['\.git$'],
387387
'redirectmatch_dest' => ['http://www.example.com'],
388-
'headers' => 'Set X-Robots-Tag "noindex, noarchive, nosnippet"',
388+
'headers' => ['Set X-Robots-Tag "noindex, noarchive, nosnippet"'],
389389
'request_headers' => ['append MirrorID "mirror 12"'],
390390
'rewrites' => [
391391
{
@@ -403,7 +403,7 @@
403403
],
404404
'rewrite_base' => '/',
405405
'rewrite_rule' => '^index\.html$ welcome.html',
406-
'rewrite_cond' => '%{HTTP_USER_AGENT} ^MSIE',
406+
'rewrite_cond' => ['%{HTTP_USER_AGENT} ^MSIE'],
407407
'rewrite_inherit' => true,
408408
'setenv' => ['FOO=/bin/true'],
409409
'setenvif' => 'Request_URI "\.gif$" object_is_image=gif',

templates/vhost/_filters.erb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
<% if @filters and ! @filters.empty? -%>
1+
<% unless @filters.empty? -%>
22

33
## Filter module rules
44
## as per http://httpd.apache.org/docs/2.2/mod/mod_filter.html
5-
<%- Array(@filters).each do |filter| -%>
6-
<%- if filter != '' -%>
5+
<%- @filters.each do |filter| -%>
76
<%= filter %>
8-
<%- end -%>
97
<%- end -%>
108
<% end -%>

templates/vhost/_header.erb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
<% if @headers and ! @headers.empty? -%>
1+
<% unless @headers.empty? -%>
22

33
## Header rules
4-
## as per http://httpd.apache.org/docs/2.2/mod/mod_headers.html#header
5-
<%- Array(@headers).each do |header_statement| -%>
6-
<%- if header_statement != '' -%>
4+
## as per http://httpd.apache.org/docs/2.4/mod/mod_headers.html#header
5+
<%- @headers.each do |header_statement| -%>
76
Header <%= header_statement %>
8-
<%- end -%>
97
<%- end -%>
108
<% end -%>

templates/vhost/_jk_mounts.erb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
<% if @jk_mounts and not @jk_mounts.empty? -%>
1+
<% unless @jk_mounts.empty? -%>
22

33
<%- @jk_mounts.each do |jk| -%>
4-
<%- if jk.is_a?(Hash) -%>
5-
<%- if jk.has_key?('mount') and jk.has_key?('worker') -%>
4+
<%- if jk.has_key?('mount') and jk.has_key?('worker') -%>
65
JkMount <%= jk['mount'] %> <%= jk['worker'] %>
7-
<%- elsif jk.has_key?('unmount') and jk.has_key?('worker') -%>
6+
<%- elsif jk.has_key?('unmount') and jk.has_key?('worker') -%>
87
JkUnMount <%= jk['unmount'] %> <%= jk['worker'] %>
9-
<%- end -%>
108
<%- end -%>
119
<%- end -%>
1210
<% end -%>

templates/vhost/_requestheader.erb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
<% if @request_headers and ! @request_headers.empty? -%>
1+
<% unless @request_headers.empty? -%>
22

33
## Request header rules
4-
## as per http://httpd.apache.org/docs/2.2/mod/mod_headers.html#requestheader
5-
<%- Array(@request_headers).each do |request_statement| -%>
6-
<%- if request_statement != '' -%>
4+
## as per http://httpd.apache.org/docs/2.4/mod/mod_headers.html#requestheader
5+
<%- @request_headers.each do |request_statement| -%>
76
RequestHeader <%= request_statement %>
8-
<%- end -%>
97
<%- end -%>
108
<% end -%>

templates/vhost/_rewrite.erb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
RewriteBase <%= @rewrite_base %>
99
<%- end -%>
1010

11-
<%- [@rewrites].flatten.compact.each do |rewrite_details| -%>
11+
<%- @rewrites.each do |rewrite_details| -%>
1212
<%- if rewrite_details['comment'] -%>
1313
#<%= rewrite_details['comment'] %>
1414
<%- end -%>
@@ -44,10 +44,8 @@
4444
<%- if @rewrite_base -%>
4545
RewriteBase <%= @rewrite_base %>
4646
<%- end -%>
47-
<%- if @rewrite_cond -%>
48-
<%- Array(@rewrite_cond).each do |cond| -%>
47+
<%- @rewrite_cond.each do |cond| -%>
4948
RewriteCond <%= cond %>
50-
<%- end -%>
5149
<%- end -%>
5250
RewriteRule <%= @rewrite_rule %>
5351
<%- end -%>

templates/vhost/_security.erb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414
</LocationMatch>
1515
<% end -%>
1616
<% end -%>
17-
<% ips = Array(@modsec_disable_ips).join(',') %>
18-
<% if ips != '' %>
19-
SecRule REMOTE_ADDR "<%= ips %>" "nolog,allow,id:1234123455"
17+
<% unless @modsec_disable_ips.empty? %>
18+
SecRule REMOTE_ADDR "<%= @modsec_disable_ips.join(',') %>" "nolog,allow,id:1234123455"
2019
SecAction "phase:2,pass,nolog,id:1234123456"
2120
<% end -%>
2221
<% if @_modsec_disable_msgs.is_a?(Hash) -%>

0 commit comments

Comments
 (0)