Skip to content

Commit ec74a8e

Browse files
committed
Add support for setting UserDir in Virtual Hosts
We can only set this setting at the VirtualHost level by relying on the `custom_fragment` parameter, which does not scale when we want to enable UserDir for a single VHost because we have to manually disable it on all other VHosts. With this change, one can ensure UserDir is active only on specific VHost with something like: ``` Apache::Vhost { userdir => 'disabled', } apache::vhost { 'example.com': # [...] userdir => 'enabled', } ``` A specific `userdir` parameter avoid clashes that would prevent this technique to be effective with `custom_fragment`.
1 parent 58d3cb6 commit ec74a8e

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

manifests/vhost.pp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1995,6 +1995,7 @@
19951995
Boolean $auth_oidc = false,
19961996
Optional[Apache::OIDCSettings] $oidc_settings = undef,
19971997
Optional[Variant[Boolean,String]] $mdomain = undef,
1998+
Optional[Variant[String[1],Array[String[1]]]] $userdir = undef,
19981999
) {
19992000
# The base class must be included first because it is used by parameter defaults
20002001
if ! defined(Class['apache']) {
@@ -2854,6 +2855,18 @@
28542855
include apache::mod::md
28552856
}
28562857

2858+
# Template uses:
2859+
# - $userdir
2860+
if $userdir {
2861+
include apache::mod::userdir
2862+
2863+
concat::fragment { "${name}-userdir":
2864+
target => "${priority_real}${filename}.conf",
2865+
order => 300,
2866+
content => template('apache/vhost/_userdir.erb'),
2867+
}
2868+
}
2869+
28572870
# Template uses:
28582871
# - $passenger_enabled
28592872
# - $passenger_start_timeout

spec/defines/vhost_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@
496496
'ClientSecret' => 'aae053a9-4abf-4824-8956-e94b2af335c8',
497497
'CryptoPassphrase' => '4ad1bb46-9979-450e-ae58-c696967df3cd' },
498498
'mdomain' => 'example.com example.net auto',
499+
'userdir' => 'disabled',
499500
}
500501
end
501502

@@ -2472,6 +2473,20 @@
24722473
)
24732474
}
24742475
end
2476+
2477+
context 'userdir' do
2478+
let :params do
2479+
default_params.merge(
2480+
'userdir' => [
2481+
'disabled',
2482+
'enabled bob',
2483+
],
2484+
)
2485+
2486+
it { is_expected.to contain_concat__fragment('rspec.example.com-apache-userdir').with(content: %r{^\s+UserDir disabled$}) }
2487+
it { is_expected.to contain_concat__fragment('rspec.example.com-apache-userdir').with(content: %r{^\s+UUserDir enabled bob$}) }
2488+
end
2489+
end
24752490
end
24762491
end
24772492
end

templates/vhost/_userdir.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<%- [@userdir].flatten.each do |userdir| -%>
2+
UserDir <%= userdir %>
3+
<%- end -%>

0 commit comments

Comments
 (0)