Skip to content

Commit 95232a6

Browse files
committed
convert content use epp/heredoc instead of erb
1 parent 6e17502 commit 95232a6

File tree

9 files changed

+78
-98
lines changed

9 files changed

+78
-98
lines changed

manifests/forward.pp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,18 @@
2828
Pattern[/yes|no/] $forward_tls_upstream = 'no',
2929
$config_file = $unbound::config_file,
3030
) {
31+
$content = @("CONTENT")
32+
forward-zone:
33+
${unbound::print_config('name', $zone)}
34+
${unbound::print_config('forward-addr', $address)}
35+
${unbound::print_config('forward-host', $host)}
36+
${unbound::print_config('forward-first', $forward_first)}
37+
${unbound::print_config('forward-ssl-upstream', $forward_ssl_upstream)}
38+
${unbound::print_config('forward-tls-upstream', $forward_tls_upstream)}
39+
| CONTENT
3140
concat::fragment { "unbound-forward-${name}":
3241
order => '20',
3342
target => $config_file,
34-
content => template('unbound/forward.erb'),
43+
content => $content.unbound::clean_blank_lines(),
3544
}
3645
}

manifests/localzone.pp

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,29 @@
2626
# @param template_name Use a custom template.
2727
#
2828
define unbound::localzone (
29-
Unbound::Local_zone_type $type,
30-
String $zone = $name,
31-
$config_file = $unbound::config_file,
32-
Array[Unbound::Resource_record_type] $local_data = [],
33-
String $template_name = 'unbound/local_zone.erb'
29+
Unbound::Local_zone_type $type,
30+
String $zone = $name,
31+
Stdlib::Absolutepath $config_file = $unbound::config_file,
32+
String $template_name = 'unbound/local_zone.erb',
33+
Array[Unbound::Resource_record_type] $local_data = [],
3434
) {
35+
$records = $local_data.map |$record| {
36+
$data = $record['data']
37+
$_data = $record['type'] ? {
38+
'TXT' => $data.slice(255).map |$i| { "\"${i.join}\"" }.join,
39+
default => $data,
40+
}
41+
$record_txt = "${record['name']} ${record['ttl']} ${record['class']} ${record['type']} ${_data}".regsubst(/\s+/, ' ', 'G')
42+
" local-data: '${record_txt}'"
43+
}.join("\n")
44+
$content = @("CONTENT")
45+
server:
46+
local-zone: "${zone}" ${type}
47+
${records}
48+
| CONTENT
3549
concat::fragment { "unbound-localzone-${name}":
3650
order => '06',
3751
target => $config_file,
38-
content => template($template_name),
52+
content => $content,
3953
}
4054
}

manifests/remote.pp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,23 @@
5050
$config_file = $unbound::config_file,
5151
$control_setup_path = $unbound::control_setup_path,
5252
) {
53+
$_tls_config = @("CONFIG")
54+
${unbound::print_config('server-key-file', $server_key_file)}
55+
${unbound::print_config('server-cert-file', $server_cert_file)}
56+
${unbound::print_config('control-key-file', $control_key_file)}
57+
${unbound::print_config('control-cert-file', $control_cert_file)}
58+
| CONFIG
59+
$tls_config = $control_use_cert.bool2str($_tls_config, '')
60+
$content = @("CONFIG")
61+
${unbound::print_config('control-enable', $enable)}
62+
${unbound::print_config('control-interface', $interface)}
63+
${unbound::print_config('control-port', $port)}
64+
${tls_config}
65+
| CONFIG
5366
concat::fragment { 'unbound-remote':
5467
order => '10',
5568
target => $config_file,
56-
content => template('unbound/remote.erb'),
69+
content => $content.unbound::clean_blank_lines(),
5770
}
5871

5972
unless $control_setup_path.empty {

manifests/stub.pp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# Controls 'stub-first' stub zone option.
2121
# If true, a query that fails with the stub clause is attempted again
2222
# without the stub clause.
23-
# @param type
23+
# @param type
2424
# can be 'deny', 'refuse', 'static', 'transparent', 'typetransparent', 'redirect' or 'nodefault'.
2525
# @param config_file Name of the unbound config file
2626
#
@@ -37,10 +37,18 @@
3737
) {
3838
include unbound
3939
$_config_file = pick($config_file, $unbound::config_file)
40+
$content = @("CONFIG")
41+
stub-zone:
42+
${unbound::print_config('name', $name)}
43+
${unbound::print_config('stub-addr', $address)}
44+
${unbound::print_config('stub-host', $nameservers)}
45+
${unbound::print_config('stub-first', $stub_first)}
46+
${unbound::print_config('stub-no-cache', $no_cache)}
47+
| CONFIG
4048
concat::fragment { "unbound-stub-${name}":
4149
order => '15',
4250
target => $_config_file,
43-
content => template('unbound/stub.erb'),
51+
content => $content.unbound::clean_blank_lines,
4452
}
4553

4654
if str2bool($insecure) == true {

spec/defines/stub_spec.rb

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@
2020
it { is_expected.to contain_unbound__stub('lab.example.com') }
2121

2222
it {
23-
expect(subject).to contain_concat__fragment('unbound-stub-lab.example.com').with(
24-
content: <<~ZONE
23+
expect(subject).to contain_concat__fragment('unbound-stub-lab.example.com').with_content(
24+
<<~ZONE
2525
stub-zone:
2626
name: "lab.example.com"
27-
stub-addr: ::1
27+
stub-addr: "::1"
28+
stub-first: no
29+
stub-no-cache: no
2830
ZONE
2931
)
3032
}
@@ -42,13 +44,15 @@
4244
it { is_expected.to contain_unbound__stub('lab.example.com') }
4345

4446
it {
45-
expect(subject).to contain_concat__fragment('unbound-stub-lab.example.com').with(
46-
content: <<~ZONE
47+
expect(subject).to contain_concat__fragment('unbound-stub-lab.example.com').with_content(
48+
<<~ZONE
4749
stub-zone:
4850
name: "lab.example.com"
49-
stub-addr: 10.0.0.10@10053
50-
stub-host: ns1.example.com
51-
stub-host: ns2.example.com
51+
stub-addr: "10.0.0.10@10053"
52+
stub-host: "ns1.example.com"
53+
stub-host: "ns2.example.com"
54+
stub-first: no
55+
stub-no-cache: no
5256
ZONE
5357
)
5458
}
@@ -66,11 +70,12 @@
6670
it { is_expected.to contain_unbound__stub('lab.example.com') }
6771

6872
it {
69-
expect(subject).to contain_concat__fragment('unbound-stub-lab.example.com').with(
70-
content: <<~ZONE
73+
expect(subject).to contain_concat__fragment('unbound-stub-lab.example.com').with_content(
74+
<<~ZONE
7175
stub-zone:
7276
name: "lab.example.com"
73-
stub-addr: ::1
77+
stub-addr: "::1"
78+
stub-first: no
7479
stub-no-cache: yes
7580
ZONE
7681
)
@@ -89,12 +94,13 @@
8994
it { is_expected.to contain_unbound__stub('lab.example.com') }
9095

9196
it {
92-
expect(subject).to contain_concat__fragment('unbound-stub-lab.example.com').with(
93-
content: <<~ZONE
97+
expect(subject).to contain_concat__fragment('unbound-stub-lab.example.com').with_content(
98+
<<~ZONE
9499
stub-zone:
95100
name: "lab.example.com"
96-
stub-addr: ::1
101+
stub-addr: "::1"
97102
stub-first: yes
103+
stub-no-cache: no
98104
ZONE
99105
)
100106
}
@@ -112,11 +118,12 @@
112118
it { is_expected.to contain_unbound__stub('lab.example.com') }
113119

114120
it {
115-
expect(subject).to contain_concat__fragment('unbound-stub-lab.example.com').with(
116-
content: <<~ZONE
121+
expect(subject).to contain_concat__fragment('unbound-stub-lab.example.com').with_content(
122+
<<~ZONE
117123
stub-zone:
118124
name: "lab.example.com"
119-
stub-addr: ::1
125+
stub-addr: "::1"
126+
stub-first: no
120127
stub-no-cache: yes
121128
ZONE
122129
)

templates/forward.erb

Lines changed: 0 additions & 17 deletions
This file was deleted.

templates/local_zone.erb

Lines changed: 0 additions & 15 deletions
This file was deleted.

templates/remote.erb

Lines changed: 0 additions & 25 deletions
This file was deleted.

templates/stub.erb

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)