Skip to content

Commit 35c6c6a

Browse files
committed
Tighten apache::vhost::directories parameter
This tightens the data type to a simple array of hashes (as the parameter documentation suggests). This allows the logic to be simpler. Because of this, it is now fairly easy to include the correct modules if needed. Some options are implemented but there are more which could be automatically included.
1 parent da6977c commit 35c6c6a

File tree

3 files changed

+37
-28
lines changed

3 files changed

+37
-28
lines changed

manifests/vhost.pp

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -428,12 +428,14 @@
428428
# krb_method_negotiate => 'on',
429429
# krb_auth_realms => ['EXAMPLE.ORG'],
430430
# krb_local_user_mapping => 'on',
431-
# directories => {
432-
# path => '/var/www/html',
433-
# auth_name => 'Kerberos Login',
434-
# auth_type => 'Kerberos',
435-
# auth_require => 'valid-user',
436-
# },
431+
# directories => [
432+
# {
433+
# path => '/var/www/html',
434+
# auth_name => 'Kerberos Login',
435+
# auth_type => 'Kerberos',
436+
# auth_require => 'valid-user',
437+
# },
438+
# ],
437439
# }
438440
# ```
439441
#
@@ -1163,9 +1165,12 @@
11631165
# suphp_addhandler => 'x-httpd-php',
11641166
# suphp_engine => 'on',
11651167
# suphp_configpath => '/etc/php5/apache2',
1166-
# directories => { path => '/home/appuser/myphpapp',
1167-
# 'suphp' => { user => 'myappuser', group => 'myappgroup' },
1168-
# }
1168+
# directories => [
1169+
# {
1170+
# 'path' => '/home/appuser/myphpapp',
1171+
# 'suphp' => { user => 'myappuser', group => 'myappgroup' },
1172+
# },
1173+
# ],
11691174
# }
11701175
# ```
11711176
#
@@ -1180,9 +1185,12 @@
11801185
# suphp_addhandler => 'x-httpd-php',
11811186
# suphp_engine => 'on',
11821187
# suphp_configpath => '/etc/php5/apache2',
1183-
# directories => { path => '/home/appuser/myphpapp',
1184-
# 'suphp' => { user => 'myappuser', group => 'myappgroup' },
1185-
# }
1188+
# directories => [
1189+
# {
1190+
# 'path' => '/home/appuser/myphpapp',
1191+
# 'suphp' => { user => 'myappuser', group => 'myappgroup' },
1192+
# },
1193+
# ],
11861194
# }
11871195
# ```
11881196
#
@@ -1197,9 +1205,12 @@
11971205
# suphp_addhandler => 'x-httpd-php',
11981206
# suphp_engine => 'on',
11991207
# suphp_configpath => '/etc/php5/apache2',
1200-
# directories => { path => '/home/appuser/myphpapp',
1201-
# 'suphp' => { user => 'myappuser', group => 'myappgroup' },
1202-
# }
1208+
# directories => [
1209+
# {
1210+
# 'path' => '/home/appuser/myphpapp',
1211+
# 'suphp' => { user => 'myappuser', group => 'myappgroup' },
1212+
# },
1213+
# ],
12031214
# }
12041215
# ```
12051216
#
@@ -1407,10 +1418,12 @@
14071418
# ``` puppet
14081419
# apache::vhost { 'sample.example.net':
14091420
# docroot => '/path/to/directory',
1410-
# directories => {
1411-
# path => '/path/to/directory',
1412-
# headers => 'Set X-Robots-Tag "noindex, noarchive, nosnippet"',
1413-
# },
1421+
# directories => [
1422+
# {
1423+
# path => '/path/to/directory',
1424+
# headers => 'Set X-Robots-Tag "noindex, noarchive, nosnippet"',
1425+
# },
1426+
# ],
14141427
# }
14151428
# ```
14161429
#
@@ -1457,7 +1470,6 @@
14571470
# @param gssapi
14581471
# Specfies mod_auth_gssapi parameters for particular directories in a virtual host directory
14591472
# ```puppet
1460-
# include apache::mod::auth_gssapi
14611473
# apache::vhost { 'sample.example.net':
14621474
# docroot => '/path/to/directory',
14631475
# directories => [
@@ -1804,7 +1816,7 @@
18041816
Boolean $use_servername_for_filenames = false,
18051817
Boolean $use_port_for_filenames = false,
18061818
Array[Hash[String[1], String[1]]] $aliases = [],
1807-
Optional[Variant[Hash, Array[Variant[Array,Hash]]]] $directories = undef,
1819+
Optional[Array[Hash]] $directories = undef,
18081820
Boolean $error_log = true,
18091821
Optional[String] $error_log_file = undef,
18101822
Optional[String] $error_log_pipe = undef,
@@ -2353,7 +2365,7 @@
23532365
# - $apache_version
23542366
# - $suphp_engine
23552367
# - $shibboleth_enabled
2356-
if $_directories and ! empty($_directories) {
2368+
if $_directories and ! empty($_directories) and $ensure == 'present' {
23572369
concat::fragment { "${name}-directories":
23582370
target => "${priority_real}${filename}.conf",
23592371
order => 60,

spec/acceptance/vhost_spec.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ class { 'apache': }
327327
class { 'apache': }
328328
329329
if versioncmp($apache_version, '2.4') >= 0 {
330-
$_files_match_directory = { 'path' => 'private.html$', 'provider' => 'filesmatch', 'require' => 'all denied' }
330+
$_files_match_directory = [{ 'path' => 'private.html$', 'provider' => 'filesmatch', 'require' => 'all denied' }]
331331
} else {
332332
$_files_match_directory = [
333333
{ 'path' => 'private.html$', 'provider' => 'filesmatch', 'deny' => 'from all' },
@@ -338,8 +338,7 @@ class { 'apache': }
338338
$_directories = [
339339
{ 'path' => '/var/www/files', },
340340
{ 'path' => '/foo/', 'provider' => 'location', 'directoryindex' => 'notindex.html', },
341-
$_files_match_directory,
342-
]
341+
] + $_files_match_directory
343342
344343
apache::vhost { 'files.example.net':
345344
docroot => '/var/www/files',

templates/vhost/_directories.erb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
<% if @_directories and ! @_directories.empty? -%>
21

32
<%- scope.setvar('_template_scope', {}) -%>
43
## Directories, there should at least be a declaration for <%= @docroot %>
5-
<%- [@_directories].flatten.compact.each do |directory| -%>
4+
<%- @_directories.each do |directory| -%>
65
<%- if scope.function_versioncmp([@apache_version, '2.4']) >= 0 -%>
76
<%- if directory['allow'] and ! [ false, 'false', '' ].include?(directory['allow']) -%>
87
<%- scope.function_warning(["Apache::Vhost: Using allow is deprecated in your Apache version"]) -%>
@@ -520,4 +519,3 @@
520519
</<%= provider %>>
521520
<%- end -%>
522521
<%- end -%>
523-
<%- end -%>

0 commit comments

Comments
 (0)