Skip to content

Commit

Permalink
convert content use epp/heredoc instead of erb
Browse files Browse the repository at this point in the history
  • Loading branch information
b4ldr committed Jan 17, 2025
1 parent 6e17502 commit 95232a6
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 98 deletions.
11 changes: 10 additions & 1 deletion manifests/forward.pp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,18 @@
Pattern[/yes|no/] $forward_tls_upstream = 'no',
$config_file = $unbound::config_file,
) {
$content = @("CONTENT")
forward-zone:
${unbound::print_config('name', $zone)}
${unbound::print_config('forward-addr', $address)}
${unbound::print_config('forward-host', $host)}
${unbound::print_config('forward-first', $forward_first)}
${unbound::print_config('forward-ssl-upstream', $forward_ssl_upstream)}
${unbound::print_config('forward-tls-upstream', $forward_tls_upstream)}
| CONTENT
concat::fragment { "unbound-forward-${name}":
order => '20',
target => $config_file,
content => template('unbound/forward.erb'),
content => $content.unbound::clean_blank_lines(),
}
}
26 changes: 20 additions & 6 deletions manifests/localzone.pp
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,29 @@
# @param template_name Use a custom template.
#
define unbound::localzone (
Unbound::Local_zone_type $type,
String $zone = $name,
$config_file = $unbound::config_file,
Array[Unbound::Resource_record_type] $local_data = [],
String $template_name = 'unbound/local_zone.erb'
Unbound::Local_zone_type $type,
String $zone = $name,
Stdlib::Absolutepath $config_file = $unbound::config_file,
String $template_name = 'unbound/local_zone.erb',
Array[Unbound::Resource_record_type] $local_data = [],
) {
$records = $local_data.map |$record| {
$data = $record['data']
$_data = $record['type'] ? {
'TXT' => $data.slice(255).map |$i| { "\"${i.join}\"" }.join,
default => $data,
}
$record_txt = "${record['name']} ${record['ttl']} ${record['class']} ${record['type']} ${_data}".regsubst(/\s+/, ' ', 'G')
" local-data: '${record_txt}'"
}.join("\n")
$content = @("CONTENT")
server:
local-zone: "${zone}" ${type}
${records}
| CONTENT
concat::fragment { "unbound-localzone-${name}":
order => '06',
target => $config_file,
content => template($template_name),
content => $content,
}
}
15 changes: 14 additions & 1 deletion manifests/remote.pp
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,23 @@
$config_file = $unbound::config_file,
$control_setup_path = $unbound::control_setup_path,
) {
$_tls_config = @("CONFIG")
${unbound::print_config('server-key-file', $server_key_file)}
${unbound::print_config('server-cert-file', $server_cert_file)}
${unbound::print_config('control-key-file', $control_key_file)}
${unbound::print_config('control-cert-file', $control_cert_file)}
| CONFIG
$tls_config = $control_use_cert.bool2str($_tls_config, '')
$content = @("CONFIG")
${unbound::print_config('control-enable', $enable)}
${unbound::print_config('control-interface', $interface)}
${unbound::print_config('control-port', $port)}
${tls_config}
| CONFIG
concat::fragment { 'unbound-remote':
order => '10',
target => $config_file,
content => template('unbound/remote.erb'),
content => $content.unbound::clean_blank_lines(),
}

unless $control_setup_path.empty {
Expand Down
12 changes: 10 additions & 2 deletions manifests/stub.pp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# Controls 'stub-first' stub zone option.
# If true, a query that fails with the stub clause is attempted again
# without the stub clause.
# @param type
# @param type
# can be 'deny', 'refuse', 'static', 'transparent', 'typetransparent', 'redirect' or 'nodefault'.
# @param config_file Name of the unbound config file
#
Expand All @@ -37,10 +37,18 @@
) {
include unbound
$_config_file = pick($config_file, $unbound::config_file)
$content = @("CONFIG")
stub-zone:
${unbound::print_config('name', $name)}
${unbound::print_config('stub-addr', $address)}
${unbound::print_config('stub-host', $nameservers)}
${unbound::print_config('stub-first', $stub_first)}
${unbound::print_config('stub-no-cache', $no_cache)}
| CONFIG
concat::fragment { "unbound-stub-${name}":
order => '15',
target => $_config_file,
content => template('unbound/stub.erb'),
content => $content.unbound::clean_blank_lines,
}

if str2bool($insecure) == true {
Expand Down
41 changes: 24 additions & 17 deletions spec/defines/stub_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
it { is_expected.to contain_unbound__stub('lab.example.com') }

it {
expect(subject).to contain_concat__fragment('unbound-stub-lab.example.com').with(
content: <<~ZONE
expect(subject).to contain_concat__fragment('unbound-stub-lab.example.com').with_content(
<<~ZONE
stub-zone:
name: "lab.example.com"
stub-addr: ::1
stub-addr: "::1"
stub-first: no
stub-no-cache: no
ZONE
)
}
Expand All @@ -42,13 +44,15 @@
it { is_expected.to contain_unbound__stub('lab.example.com') }

it {
expect(subject).to contain_concat__fragment('unbound-stub-lab.example.com').with(
content: <<~ZONE
expect(subject).to contain_concat__fragment('unbound-stub-lab.example.com').with_content(
<<~ZONE
stub-zone:
name: "lab.example.com"
stub-addr: 10.0.0.10@10053
stub-host: ns1.example.com
stub-host: ns2.example.com
stub-addr: "10.0.0.10@10053"
stub-host: "ns1.example.com"
stub-host: "ns2.example.com"
stub-first: no
stub-no-cache: no
ZONE
)
}
Expand All @@ -66,11 +70,12 @@
it { is_expected.to contain_unbound__stub('lab.example.com') }

it {
expect(subject).to contain_concat__fragment('unbound-stub-lab.example.com').with(
content: <<~ZONE
expect(subject).to contain_concat__fragment('unbound-stub-lab.example.com').with_content(
<<~ZONE
stub-zone:
name: "lab.example.com"
stub-addr: ::1
stub-addr: "::1"
stub-first: no
stub-no-cache: yes
ZONE
)
Expand All @@ -89,12 +94,13 @@
it { is_expected.to contain_unbound__stub('lab.example.com') }

it {
expect(subject).to contain_concat__fragment('unbound-stub-lab.example.com').with(
content: <<~ZONE
expect(subject).to contain_concat__fragment('unbound-stub-lab.example.com').with_content(
<<~ZONE
stub-zone:
name: "lab.example.com"
stub-addr: ::1
stub-addr: "::1"
stub-first: yes
stub-no-cache: no
ZONE
)
}
Expand All @@ -112,11 +118,12 @@
it { is_expected.to contain_unbound__stub('lab.example.com') }

it {
expect(subject).to contain_concat__fragment('unbound-stub-lab.example.com').with(
content: <<~ZONE
expect(subject).to contain_concat__fragment('unbound-stub-lab.example.com').with_content(
<<~ZONE
stub-zone:
name: "lab.example.com"
stub-addr: ::1
stub-addr: "::1"
stub-first: no
stub-no-cache: yes
ZONE
)
Expand Down
17 changes: 0 additions & 17 deletions templates/forward.erb

This file was deleted.

15 changes: 0 additions & 15 deletions templates/local_zone.erb

This file was deleted.

25 changes: 0 additions & 25 deletions templates/remote.erb

This file was deleted.

14 changes: 0 additions & 14 deletions templates/stub.erb

This file was deleted.

0 comments on commit 95232a6

Please sign in to comment.