Skip to content

Commit 8c17d93

Browse files
committed
Allow custom userdir directives
`UserDir` can be various forms of strings (see https://httpd.apache.org/docs/2.4/howto/public_html.html) whereas `Directory` must be an absolute path. This allows UserDir to be specified separately. The unit test showing multiple values for `$path` seems to be incorrect according to https://httpd.apache.org/docs/2.4/mod/core.html#directory
1 parent 337e8b0 commit 8c17d93

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

REFERENCE.md

+9
Original file line numberDiff line numberDiff line change
@@ -6669,6 +6669,7 @@ The following parameters are available in the `apache::mod::userdir` class:
66696669

66706670
* [`home`](#home)
66716671
* [`dir`](#dir)
6672+
* [`userdir`](#userdir)
66726673
* [`disable_root`](#disable_root)
66736674
* [`apache_version`](#apache_version)
66746675
* [`path`](#path)
@@ -6693,6 +6694,14 @@ Data type: `Any`
66936694

66946695
Default value: ``undef``
66956696

6697+
##### <a name="userdir"></a>`userdir`
6698+
6699+
Data type: `Any`
6700+
6701+
Directory out of which per-user content is loaded. It may be any valid `UserDir` directive values.
6702+
6703+
Default value: The value of `$path`
6704+
66966705
##### <a name="disable_root"></a>`disable_root`
66976706

66986707
Data type: `Any`

manifests/mod/userdir.pp

+10-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
#
77
# @param dir
88
# *Deprecated* Path from user's home directory to public directory.
9-
#
9+
#
10+
# @param userdir
11+
# Path or directory name to be used as the UserDir.
12+
#
1013
# @param disable_root
1114
# Toggles whether to allow use of root directory.
1215
#
@@ -33,6 +36,7 @@
3336
class apache::mod::userdir (
3437
$home = undef,
3538
$dir = undef,
39+
$userdir = undef,
3640
$disable_root = true,
3741
$apache_version = undef,
3842
$path = '/home/*/public_html',
@@ -59,6 +63,11 @@
5963
$_path = $path
6064
}
6165

66+
$_userdir = $userdir ? {
67+
undef => $_path,
68+
default => $userdir,
69+
}
70+
6271
::apache::mod { 'userdir': }
6372

6473
# Template uses $home, $dir, $disable_root, $_apache_version

spec/classes/mod/userdir_spec.rb

+14-3
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,23 @@
3939
context 'with path set to something' do
4040
let :params do
4141
{
42-
path: 'public_html /usr/web http://www.example.com/',
42+
path: '/home/*/*/public_html',
4343
}
4444
end
4545

46-
it { is_expected.to contain_file('userdir.conf').with_content(%r{^\s*UserDir\s+public_html /usr/web http://www\.example\.com/$}) }
47-
it { is_expected.to contain_file('userdir.conf').with_content(%r{^\s*\<Directory\s+\"public_html /usr/web http://www\.example\.com/\"\>$}) }
46+
it { is_expected.to contain_file('userdir.conf').with_content(%r{^\s*UserDir\s+/home/\*/\*/public_html$}) }
47+
it { is_expected.to contain_file('userdir.conf').with_content(%r{^\s*\<Directory\s+\"/home/\*/\*/public_html\"\>$}) }
48+
end
49+
context 'with userdir set to something' do
50+
let :params do
51+
{
52+
path: '/home/*/*/public_html',
53+
userdir: 'public_html',
54+
}
55+
end
56+
57+
it { is_expected.to contain_file('userdir.conf').with_content(%r{^\s*UserDir\s+public_html$}) }
58+
it { is_expected.to contain_file('userdir.conf').with_content(%r{^\s*\<Directory\s+\"/home/\*/\*/public_html\"\>$}) }
4859
end
4960
context 'with unmanaged_path set to true' do
5061
let :params do

templates/mod/userdir.conf.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<% if @disable_root -%>
33
UserDir disabled root
44
<% end -%>
5-
UserDir <%= @_path %>
5+
UserDir <%= @_userdir %>
66

77
<%- if ! @unmanaged_path -%>
88
<Directory "<%= @_path %>">

0 commit comments

Comments
 (0)