Skip to content

Commit b29a0e5

Browse files
committed
convert content use epp/heredoc instead of erb
1 parent 8383c92 commit b29a0e5

File tree

11 files changed

+101
-101
lines changed

11 files changed

+101
-101
lines changed

REFERENCE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2358,7 +2358,7 @@ Custom type Unbound::Local_zone_type.
23582358

23592359
##### <a name="-unbound--localzone--config_file"></a>`config_file`
23602360

2361-
Data type: `Any`
2361+
Data type: `Stdlib::Absolutepath`
23622362

23632363
name of configuration file.
23642364

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.extlib::remove_blank_lines(),
3544
}
3645
}

manifests/localzone.pp

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,34 @@
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+
# Loop through the local_data hash and create ablock of local-data strings with the correctly formated
36+
# local-data lines which are ued in the final content block below.
37+
# local-data: 'api.test.com 15 300 IN A 192.0.2.1
38+
$records = $local_data.map |$record| {
39+
$data = $record['data']
40+
$_data = $record['type'] ? {
41+
'TXT' => $data.unbound::split_txt(),
42+
default => $data,
43+
}
44+
$record_txt = "${record['name']} ${record['ttl']} ${record['class']} ${record['type']} ${_data}".regsubst(
45+
/\s+/, ' ', 'G'
46+
) # Remove multiple spaces
47+
" local-data: '${record_txt}'"
48+
}.join("\n")
49+
$content = @("CONTENT")
50+
server:
51+
local-zone: "${zone}" ${type}
52+
${records}
53+
| CONTENT
3554
concat::fragment { "unbound-localzone-${name}":
3655
order => '06',
3756
target => $config_file,
38-
content => template($template_name),
57+
content => $content,
3958
}
4059
}

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.extlib::remove_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.extlib::remove_blank_lines(),
4452
}
4553

4654
if str2bool($insecure) == true {

spec/classes/init_spec.rb

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,14 @@
829829

830830
it do
831831
expect(subject).to contain_concat__fragment('unbound-stub-example-stub.com').with_content(
832-
%r{^stub-zone:\n name: "example-stub.com"\n stub-addr: 10.0.0.1\n stub-addr: 10.0.0.2}
832+
%r{
833+
^stub-zone:
834+
\s+name:\s"example-stub.com"
835+
\s+stub-addr:\s"10.0.0.1"
836+
\s+stub-addr:\s"10.0.0.2"
837+
\s+stub-first:\sno
838+
\s+stub-no-cache:\sno
839+
}x
833840
)
834841
end
835842
end
@@ -843,7 +850,15 @@
843850

844851
it do
845852
expect(subject).to contain_concat__fragment('unbound-forward-example-forward.com').with_content(
846-
%r{^forward-zone:\n name: "example-forward.com"\n forward-addr: 10.0.0.1\n forward-addr: 10.0.0.2\n forward-first: yes\n forward-ssl-upstream: yes}
853+
%r{
854+
^forward-zone:
855+
\s+name:\s"example-forward.com"
856+
\s+forward-addr:\s"10.0.0.1"
857+
\s+forward-addr:\s"10.0.0.2"
858+
\s+forward-first:\s"yes"
859+
\s+forward-ssl-upstream:\s"yes"
860+
\s+forward-tls-upstream:\s"no"
861+
}x
847862
)
848863
end
849864
end

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)