Skip to content

Commit

Permalink
conf_d: merge the unbound_conf_d and conf_d params
Browse files Browse the repository at this point in the history
AFAICT the intention of theses two parameters is the same so lets merge
them

fixes voxpupuli#342
  • Loading branch information
b4ldr committed Nov 21, 2024
1 parent 737a023 commit 762cd27
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 39 deletions.
15 changes: 3 additions & 12 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ The following parameters are available in the `unbound` class:
* [`username`](#-unbound--username)
* [`package_name`](#-unbound--package_name)
* [`package_ensure`](#-unbound--package_ensure)
* [`purge_unbound_conf_d`](#-unbound--purge_unbound_conf_d)
* [`purge_conf_d`](#-unbound--purge_conf_d)
* [`root_hints_url`](#-unbound--root_hints_url)
* [`runtime_dir`](#-unbound--runtime_dir)
* [`auto_trust_anchor_file`](#-unbound--auto_trust_anchor_file)
Expand Down Expand Up @@ -244,7 +244,6 @@ The following parameters are available in the `unbound` class:
* [`redis_server_host`](#-unbound--redis_server_host)
* [`redis_server_port`](#-unbound--redis_server_port)
* [`redis_timeout`](#-unbound--redis_timeout)
* [`unbound_conf_d`](#-unbound--unbound_conf_d)
* [`hints_file`](#-unbound--hints_file)
* [`update_root_hints`](#-unbound--update_root_hints)
* [`hints_file_content`](#-unbound--hints_file_content)
Expand Down Expand Up @@ -1571,11 +1570,11 @@ the ensure value for the packages

Default value: `'installed'`

##### <a name="-unbound--purge_unbound_conf_d"></a>`purge_unbound_conf_d`
##### <a name="-unbound--purge_conf_d"></a>`purge_conf_d`

Data type: `Boolean`

if true all unmanaged files in $unbound_conf_d will be purged
if true purge all unmanaged files in conf_d folder

Default value: `false`

Expand Down Expand Up @@ -1867,14 +1866,6 @@ see https://nlnetlabs.nl/documentation/unbound/unbound.conf/

Default value: `100`

##### <a name="-unbound--unbound_conf_d"></a>`unbound_conf_d`

Data type: `Stdlib::Absolutepath`

similar to conf_d, will be merged with conf_d version in future

Default value: `"${confdir}/unbound.conf.d"`

##### <a name="-unbound--hints_file"></a>`hints_file`

Data type: `Unbound::Hints_file`
Expand Down
3 changes: 2 additions & 1 deletion data/os/Debian.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
unbound::pidfile: '/run/unbound.pid'
unbound::runtime_dir: '/var/lib/unbound'
unbound::purge_unbound_conf_d: true
unbound::conf_d: "/etc/unbound/unbound.conf.d"
unbound::purge_conf_d: true
17 changes: 7 additions & 10 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
# @param username see https://nlnetlabs.nl/documentation/unbound/unbound.conf/
# @param package_name The package(s) to install to get unbound
# @param package_ensure the ensure value for the packages
# @param purge_unbound_conf_d if true all unmanaged files in $unbound_conf_d will be purged
# @param purge_conf_d if true purge all unmanaged files in conf_d folder
# @param root_hints_url the url to download the root hints file
# @param runtime_dir the runtime directory used
# @param auto_trust_anchor_file see https://nlnetlabs.nl/documentation/unbound/unbound.conf/
Expand Down Expand Up @@ -203,7 +203,6 @@
# @param redis_server_host see https://nlnetlabs.nl/documentation/unbound/unbound.conf/
# @param redis_server_port see https://nlnetlabs.nl/documentation/unbound/unbound.conf/
# @param redis_timeout see https://nlnetlabs.nl/documentation/unbound/unbound.conf/
# @param unbound_conf_d similar to conf_d, will be merged with conf_d version in future
# @param hints_file the root hints file to use
# @param update_root_hints f we should update the root hints file
# @param hints_file_content the contents of the root hints file
Expand Down Expand Up @@ -377,7 +376,7 @@
# OpenBSD sets this to an empty string
Variant[String,Array] $package_name = 'unbound',
String[1] $package_ensure = 'installed',
Boolean $purge_unbound_conf_d = false,
Boolean $purge_conf_d = false,
String[1] $root_hints_url = 'https://www.internic.net/domain/named.root',
Stdlib::Absolutepath $runtime_dir = $confdir,
Stdlib::Absolutepath $auto_trust_anchor_file = "${runtime_dir}/root.key",
Expand Down Expand Up @@ -414,14 +413,13 @@
String[1] $redis_server_host = '127.0.0.1',
Integer[1,65536] $redis_server_port = 6379,
Integer[1] $redis_timeout = 100,
Stdlib::Absolutepath $unbound_conf_d = "${confdir}/unbound.conf.d",
Unbound::Hints_file $hints_file = "${confdir}/root.hints",
Enum['absent','present','unmanaged'] $update_root_hints = fact('systemd') ? { true => 'present', default => 'unmanaged' },
Optional[String[1]] $hints_file_content = undef,
Hash[String[1], Unbound::Rpz] $rpzs = {},
Optional[String[1]] $unbound_version = $facts['unbound_version'],
) {
$_base_dirs = [$confdir, $conf_d, $keys_d, $runtime_dir]
$_base_dirs = [$confdir, $keys_d, $runtime_dir]
$_piddir = if $pidfile { dirname($pidfile) } else { undef }
if $_piddir and !($_piddir in ['/run', '/var/run']) {
$dirs = unique($_base_dirs + [$_piddir])
Expand Down Expand Up @@ -541,12 +539,11 @@
}

# purge unmanaged files in configuration directory
file { $unbound_conf_d:
file { $conf_d:
ensure => 'directory',
owner => 'root',
group => '0',
purge => $purge_unbound_conf_d,
recurse => $purge_unbound_conf_d,
owner => $owner,
purge => $purge_conf_d,
recurse => $purge_conf_d,
}

concat { $config_file:
Expand Down
39 changes: 23 additions & 16 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@
context "on #{os}" do
let(:facts) { facts.merge(concat_basedir: '/dne') }
let(:package) { 'unbound' }
let(:conf_file) { "#{conf_dir}/unbound.conf" }
let(:conf_d_dir) { "#{conf_dir}/conf.d" }
let(:unbound_conf_d) { "#{conf_dir}/unbound.conf.d" }
let(:keys_d_dir) { "#{conf_dir}/keys.d" }
let(:hints_file) { "#{conf_dir}/root.hints" }

pidfile = nil

Expand All @@ -23,33 +18,47 @@
pidfile = '/run/unbound.pid'
let(:service) { 'unbound' }
let(:conf_dir) { '/etc/unbound' }
let(:purge_unbound_conf_d) { true }
let(:purge_conf_d) { true }
let(:control_path) { '/usr/sbin/unbound-control' }
when 'OpenBSD'
pidfile = '/var/run/unbound.pid'
let(:service) { 'unbound' }
let(:conf_dir) { '/var/unbound/etc' }
let(:purge_unbound_conf_d) { false }
let(:purge_conf_d) { false }
let(:control_path) { '/usr/sbin/unbound-control' }
when 'FreeBSD'
pidfile = '/usr/local/etc/unbound/unbound.pid'
let(:service) { 'unbound' }
let(:conf_dir) { '/usr/local/etc/unbound' }
let(:purge_unbound_conf_d) { false }
let(:purge_conf_d) { false }
let(:control_path) { '/usr/local/sbin/unbound-control' }
when 'Darwin'
pidfile = '/var/run/unbound.pid'
let(:service) { 'org.macports.unbound' }
let(:conf_dir) { '/opt/local//etc/unbound' }
let(:purge_unbound_conf_d) { false }
let(:purge_conf_d) { false }
else
pidfile = '/var/run/unbound/unbound.pid'
let(:service) { 'unbound' }
let(:conf_dir) { '/etc/unbound' }
let(:purge_unbound_conf_d) { false }
let(:purge_conf_d) { false }
let(:control_path) { '/usr/sbin/unbound-control' }
end

if facts[:os]['family'] == 'Archlinux'
let(:owner) { 'root' }
else
let(:owner) { 'unbound' }
end
if facts[:os]['family'] == 'Debian'
let(:conf_d_dir) { "#{conf_dir}/unbound.conf.d" }
else
let(:conf_d_dir) { "#{conf_dir}/conf.d" }
end
let(:conf_file) { "#{conf_dir}/unbound.conf" }
let(:keys_d_dir) { "#{conf_dir}/keys.d" }
let(:hints_file) { "#{conf_dir}/root.hints" }

context 'with default params' do
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('unbound') }
Expand All @@ -58,7 +67,6 @@
it { is_expected.to contain_service(service) }
it { is_expected.to contain_concat(conf_file) }
it { is_expected.to contain_file(conf_dir) }
it { is_expected.to contain_file(conf_d_dir) }
it { is_expected.to contain_file(keys_d_dir) }
it { is_expected.to contain_file(hints_file) }

Expand All @@ -67,12 +75,11 @@
end

it do
expect(subject).to contain_file(unbound_conf_d).with(
expect(subject).to contain_file(conf_d_dir).with(
'ensure' => 'directory',
'owner' => 'root',
'group' => '0',
'purge' => purge_unbound_conf_d,
'recurse' => purge_unbound_conf_d
'owner' => owner,
'purge' => purge_conf_d,
'recurse' => purge_conf_d
)
end

Expand Down

0 comments on commit 762cd27

Please sign in to comment.