Skip to content

Commit 80a0520

Browse files
yakatzbastelfreak
andcommitted
Add scripts with server
Add tests Co-Authored-By: Tim Meusel <[email protected]>
1 parent b8b8035 commit 80a0520

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

manifests/server.pp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
# @param remote_cert_tls Enable or disable use of remote-cert-tls for the session. Generally used with client configuration
9696
# @param nobind Whether or not to bind to a specific port number.#
9797
# @param secret A pre-shared static key.
98+
# @param scripts Hash of scripts to copy with this instance.
9899
# @param custom_options Hash of additional options to append to the configuration file.
99100
#
100101
# @example install
@@ -218,6 +219,7 @@
218219
Boolean $remote_cert_tls = false,
219220
Boolean $nobind = false,
220221
Optional[String] $secret = undef,
222+
Hash[String, Hash] $scripts = {},
221223
Hash $custom_options = {},
222224
) {
223225

@@ -294,6 +296,12 @@
294296
mode => '0750',
295297
notify => $lnotify,
296298
}
299+
file {
300+
[ "${etc_directory}/openvpn/${name}/scripts", ]:
301+
ensure => directory,
302+
mode => '0750',
303+
recurse => true,
304+
}
297305
if $shared_ca {
298306
ensure_resource(file, "${etc_directory}/openvpn/${ca_name}", {
299307
ensure => directory,
@@ -432,6 +440,12 @@
432440
notify => $lnotify,
433441
}
434442

443+
$scripts.each |String $scriptname, Hash $properties| {
444+
file { "${etc_directory}/openvpn/${name}/scripts/${scriptname}":
445+
* => $properties,
446+
}
447+
}
448+
435449
if $ldap_enabled == true {
436450
file {
437451
"${etc_directory}/openvpn/${name}/auth/ldap.conf":

spec/defines/openvpn_server_spec.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,25 @@
614614
it { is_expected.to contain_file('/etc/openvpn/test_server/keys/pre-shared.secret').with(ensure: 'absent') }
615615
end
616616

617+
context 'when pushing scripts' do
618+
let(:params) do
619+
{
620+
'country' => 'CO',
621+
'province' => 'ST',
622+
'city' => 'Some City',
623+
'organization' => 'example.org',
624+
'email' => '[email protected]',
625+
'scripts' => {
626+
'add-tap-to-bridge.sh' => {
627+
'ensure' => 'present'
628+
}
629+
}
630+
}
631+
end
632+
633+
it { is_expected.to contain_file('/etc/openvpn/test_server/scripts/add-tap-to-bridge.sh').with(ensure: 'present') }
634+
end
635+
617636
case facts[:os]['family']
618637
when %r{FreeBSD}
619638
context 'when FreeBSD based machine' do
@@ -662,6 +681,10 @@
662681
is_expected.to contain_file('/etc/openvpn/test_server/auth').
663682
with(ensure: 'directory', mode: '0750', recurse: true, group: 'nogroup')
664683
}
684+
it {
685+
is_expected.to contain_file('/etc/openvpn/test_server/scripts').
686+
with(ensure: 'directory', mode: '0750', recurse: true, group: 'nogroup')
687+
}
665688

666689
# VPN server config file itself
667690

@@ -698,6 +721,10 @@
698721
is_expected.to contain_file('/etc/openvpn/test_server/auth').
699722
with(ensure: 'directory', mode: '0750', recurse: true, group: 'nogroup')
700723
}
724+
it {
725+
is_expected.to contain_file('/etc/openvpn/test_server/scripts').
726+
with(ensure: 'directory', mode: '0750', recurse: true, group: 'nogroup')
727+
}
701728

702729
# VPN server config file itself
703730

@@ -902,6 +929,10 @@
902929
is_expected.to contain_file('/etc/openvpn/test_server/auth').
903930
with(ensure: 'directory', mode: '0750', recurse: true, group: 'nobody')
904931
}
932+
it {
933+
is_expected.to contain_file('/etc/openvpn/test_server/scripts').
934+
with(ensure: 'directory', mode: '0750', recurse: true, group: 'nobody')
935+
}
905936

906937
# VPN server config file itself
907938

0 commit comments

Comments
 (0)