Skip to content

Commit ddb63b7

Browse files
author
Joshua Hoblitt
committed
reorder inheritance chain and refactor pureftpd::config_ldap
1 parent 5230121 commit ddb63b7

File tree

6 files changed

+260
-119
lines changed

6 files changed

+260
-119
lines changed

manifests/config_ldap.pp

+31-9
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,37 @@
103103
# 5Ub-Z3r0
104104
#
105105
class pureftpd::config_ldap (
106-
$ldap_port = '389',
107-
$ldap_usetls = false,
108-
$ldap_server,
109-
$ldap_basedn,
110-
$ldap_binddn = '',
111-
$ldap_bindpw = '',
112-
$ldap_filter,
113-
$ldap_authmethod
114-
) {
106+
$ldapport = undef,
107+
$ldapbinddn = undef,
108+
$ldapbindpw = undef,
109+
$ldapbasedn = undef,
110+
$ldapfilter = undef,
111+
$ldaphomedir = undef,
112+
$ldapversion = undef,
113+
$ldapdefaultuid = undef,
114+
$ldapforcedefaultuid = undef,
115+
$ldapdefaultgid = undef,
116+
$ldapforcedefaultgid = undef,
117+
$ldapusetls = undef,
118+
$ldapauthmethod = undef,
119+
) inherits pureftpd::params {
120+
121+
# the complete list of options is defined in pure-ftpd/src/log_ldap_p.h
122+
$ldap_conf_options = [
123+
'LDAPPort',
124+
'LDAPBindDN',
125+
'LDAPBindPW',
126+
'LDAPBaseDN',
127+
'LDAPFilter',
128+
'LDAPHomeDir',
129+
'LDAPVersion',
130+
'LDAPDefaultUID',
131+
'LDAPForceDefaultUID',
132+
'LDAPDefaultGID',
133+
'LDAPForceDefaultGID',
134+
'LDAPUseTLS',
135+
'LDAPAuthMethod',
136+
]
115137

116138
file { $pureftpd::params::ldap_conf_path:
117139
ensure => file,

manifests/init.pp

+6-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
# == Class: pureftpd
22
#
3-
# This class installs the pure-ftpd server, and ensures that it is running
3+
# This class installs, configures, and enables the pure-ftpd server
44
#
55
# === Parameters
66
#
77
# [*use_selinux*]
8-
# Optional, defaults to false.
9-
# Manages whether or not to enable the selinux extensions.
10-
#
11-
# == Actions
12-
#
13-
# - Installs pure-ftpd
14-
# - Ensure that the pure-ftpd service is up and running
8+
# Optional, defaults to false.
9+
# Manages whether or not to enable the selinux extensions.
1510
#
1611
# === Authors
1712
#
@@ -20,7 +15,9 @@
2015
class pureftpd (
2116
$use_selinux=false
2217
) {
23-
include pureftpd::install, pureftpd::config, pureftpd::service
18+
include pureftpd::config, pureftpd::service
19+
20+
class{ 'pureftpd::install': use_selinux => $use_selinux }
2421

2522
Class[ 'pureftpd::install' ] ->
2623
Class[ 'pureftpd::config' ] ->

manifests/install.pp

+16-6
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,27 @@
44
#
55
# === Parameters
66
#
7-
# === Actions
8-
#
9-
# - if the os family is RedHat, fetch and install the EPEL release file
10-
# - Install the pure-ftpd server on the system
7+
# [*use_selinux*]
8+
# Optional, defaults to false.
9+
# Manages whether or not to enable the selinux extensions.
1110
#
1211
# === Authors
1312
#
1413
# 5Ub-Z3r0
14+
# Joshua Hoblitt <[email protected]>
1515
#
16-
class pureftpd::install inherits pureftpd::params {
17-
package { $pureftpd::params::package_name:
16+
17+
class pureftpd::install (
18+
$use_selinux = false,
19+
) inherits pureftpd::params {
20+
21+
if ($use_selinux) {
22+
$package_name = $pureftpd::params::package_name_selinux
23+
} else {
24+
$package_name = $pureftpd::params::package_name
25+
}
26+
27+
package { $package_name:
1828
ensure => present,
1929
}
2030
}

manifests/params.pp

+8-22
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,18 @@
22
#
33
# This class manages common server parameters for the pure-ftpd server
44
#
5-
# === Parameters
6-
#
7-
# [*config_dir*]
8-
# The storage area for the config files.
9-
#
10-
# [*package_name*]
11-
# The name of the pure-ftpd package.
12-
#
13-
# [*service_name*]
14-
# The name of the pure-ftpd service
15-
#
16-
# === TODO
17-
#
18-
# - Add debian support for the module
19-
#
205
# === Authors
216
#
227
# 5Ub-Z3r0
8+
# Joshua Hoblitt <[email protected]>
239
#
24-
class pureftpd::params inherits pureftpd {
10+
11+
class pureftpd::params {
2512
case $::osfamily {
26-
'RedHat':{
27-
$package_name = $pureftpd::use_selinux ?{
28-
true => ['pure-ftpd', 'pure-ftpd-selinux'],
29-
default => 'pure-ftpd'
30-
}
13+
'RedHat': {
14+
$package_name = 'pure-ftpd'
15+
$package_name_selinux = ['pure-ftpd', 'pure-ftpd-selinux']
16+
3117
$config_dir = '/etc/pure-ftpd'
3218
$service_name = 'pure-ftpd'
3319

@@ -44,7 +30,7 @@
4430
$pgsql_conf_path = "${config_dir}/pureftpd-pgsql.conf"
4531
}
4632
default:{
47-
fail ("The module is not available for ${::os_family}")
33+
fail("Module ${module_name} is not supported on ${::operatingsystem}")
4834
}
4935
}
5036
}

spec/classes/config_ldap_spec.rb

+193
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
require 'spec_helper'
2+
3+
describe 'pureftpd::config_ldap' do
4+
let(:facts) {{ :osfamily=> 'RedHat' }}
5+
6+
describe 'with no params' do
7+
it do
8+
should contain_class('pureftpd::config_ldap')
9+
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \
10+
.with_ensure('file').with_content('')
11+
end
12+
end
13+
14+
describe 'with ldapport' do
15+
let(:params) {{ :ldapport => '389' }}
16+
it do
17+
should contain_class('pureftpd::config_ldap')
18+
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \
19+
.with_ensure('file') \
20+
.with_content(/^LDAPPort 389/)
21+
end
22+
end
23+
24+
describe 'with ldapbinddn' do
25+
let(:params) {{ :ldapbinddn => 'cn=Manager,dc=c9x,dc=org' }}
26+
it do
27+
should contain_class('pureftpd::config_ldap')
28+
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \
29+
.with_ensure('file') \
30+
.with_content(/^LDAPBindDN cn=Manager,dc=c9x,dc=org/)
31+
end
32+
end
33+
34+
describe 'with ldapbindpw' do
35+
let(:params) {{ :ldapbindpw => 'r00tPaSsw0rD' }}
36+
it do
37+
should contain_class('pureftpd::config_ldap')
38+
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \
39+
.with_ensure('file') \
40+
.with_content(/^LDAPBindPW r00tPaSsw0rD/)
41+
end
42+
end
43+
44+
describe 'with ldapbasedn' do
45+
let(:params) {{ :ldapbasedn => 'cn=Users,dc=c9x,dc=org' }}
46+
it do
47+
should contain_class('pureftpd::config_ldap')
48+
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \
49+
.with_ensure('file') \
50+
.with_content(/^LDAPBaseDN cn=Users,dc=c9x,dc=org/)
51+
end
52+
end
53+
54+
describe 'with ldapfilter' do
55+
let(:params) {{ :ldapfilter => '(&(objectClass=posixAccount)(uid=\L))' }}
56+
it do
57+
should contain_class('pureftpd::config_ldap')
58+
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \
59+
.with_ensure('file') \
60+
.with_content(Regexp.new(Regexp.quote('LDAPFilter (&(objectClass=posixAccount)(uid=\L))')))
61+
end
62+
end
63+
64+
describe 'with ldaphomedir' do
65+
let(:params) {{ :ldaphomedir => 'homeDirectory' }}
66+
it do
67+
should contain_class('pureftpd::config_ldap')
68+
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \
69+
.with_ensure('file') \
70+
.with_content(/^LDAPHomeDir homeDirectory/)
71+
end
72+
end
73+
74+
describe 'with ldapversion' do
75+
let(:params) {{ :ldapversion => '3' }}
76+
it do
77+
should contain_class('pureftpd::config_ldap')
78+
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \
79+
.with_ensure('file') \
80+
.with_content(/^LDAPVersion 3/)
81+
end
82+
end
83+
84+
describe 'with ldapdefaultuid' do
85+
let(:params) {{ :ldapdefaultuid => '100' }}
86+
it do
87+
should contain_class('pureftpd::config_ldap')
88+
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \
89+
.with_ensure('file') \
90+
.with_content(/^LDAPDefaultUID 100/)
91+
end
92+
end
93+
94+
describe 'with ldapforcedefaultuid' do
95+
let(:params) {{ :ldapforcedefaultuid => 'False' }}
96+
it do
97+
should contain_class('pureftpd::config_ldap')
98+
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \
99+
.with_ensure('file') \
100+
.with_content(/^LDAPForceDefaultUID False/)
101+
end
102+
end
103+
104+
describe 'with ldapdefaultgid' do
105+
let(:params) {{ :ldapdefaultgid => '100' }}
106+
it do
107+
should contain_class('pureftpd::config_ldap')
108+
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \
109+
.with_ensure('file') \
110+
.with_content(/^LDAPDefaultGID 100/)
111+
end
112+
end
113+
114+
describe 'with ldapdefaultgid' do
115+
let(:params) {{ :ldapdefaultgid => '100' }}
116+
it do
117+
should contain_class('pureftpd::config_ldap')
118+
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \
119+
.with_ensure('file') \
120+
.with_content(/^LDAPDefaultGID 100/)
121+
end
122+
end
123+
124+
describe 'with ldapforcedefaultgid' do
125+
let(:params) {{ :ldapforcedefaultgid => 'False' }}
126+
it do
127+
should contain_class('pureftpd::config_ldap')
128+
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \
129+
.with_ensure('file') \
130+
.with_content(/^LDAPForceDefaultGID False/)
131+
end
132+
end
133+
134+
describe 'with ldapusetls' do
135+
let(:params) {{ :ldapusetls => 'False' }}
136+
it do
137+
should contain_class('pureftpd::config_ldap')
138+
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \
139+
.with_ensure('file') \
140+
.with_content(/^LDAPUseTLS False/)
141+
end
142+
end
143+
144+
describe 'with ldapauthmethod' do
145+
let(:params) {{ :ldapauthmethod => 'PASSWORD' }}
146+
it do
147+
should contain_class('pureftpd::config_ldap')
148+
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \
149+
.with_ensure('file') \
150+
.with_content(/^LDAPAuthMethod PASSWORD/)
151+
end
152+
end
153+
154+
describe 'with everything' do
155+
let(:params) {{
156+
:ldapauthmethod => 'PASSWORD',
157+
:ldapport => '389',
158+
:ldapbinddn => 'cn=Manager,dc=c9x,dc=org',
159+
:ldapbindpw => 'r00tPaSsw0rD',
160+
:ldapbasedn => 'cn=Users,dc=c9x,dc=org',
161+
:ldapfilter => '(&(objectClass=posixAccount)(uid=\L))',
162+
:ldaphomedir => 'homeDirectory',
163+
:ldapversion => '3',
164+
:ldapdefaultuid => '100',
165+
:ldapforcedefaultuid => 'False',
166+
:ldapdefaultgid => '100',
167+
:ldapdefaultgid => '100',
168+
:ldapforcedefaultgid => 'False',
169+
:ldapusetls => 'False',
170+
:ldapauthmethod => 'PASSWORD',
171+
}}
172+
it do
173+
should contain_class('pureftpd::config_ldap')
174+
should contain_file('/etc/pure-ftpd/pureftpd-ldap.conf') \
175+
.with_ensure('file') \
176+
.with_content(/^LDAPPort 389/) \
177+
.with_content(/^LDAPBindDN cn=Manager,dc=c9x,dc=org/) \
178+
.with_content(/^LDAPBindPW r00tPaSsw0rD/) \
179+
.with_content(/^LDAPBaseDN cn=Users,dc=c9x,dc=org/) \
180+
.with_content(Regexp.new(Regexp.quote('LDAPFilter (&(objectClass=posixAccount)(uid=\L))'))) \
181+
.with_content(/^LDAPHomeDir homeDirectory/) \
182+
.with_content(/^LDAPVersion 3/) \
183+
.with_content(/^LDAPDefaultUID 100/) \
184+
.with_content(/^LDAPForceDefaultUID False/) \
185+
.with_content(/^LDAPDefaultGID 100/) \
186+
.with_content(/^LDAPDefaultGID 100/) \
187+
.with_content(/^LDAPForceDefaultGID False/) \
188+
.with_content(/^LDAPUseTLS False/) \
189+
.with_content(/^LDAPAuthMethod PASSWORD/) \
190+
.with_content(/^LDAPAuthMethod PASSWORD/)
191+
end
192+
end
193+
end

0 commit comments

Comments
 (0)