Skip to content

Commit e006276

Browse files
committed
Add custom view options support
1 parent 20d6009 commit e006276

5 files changed

Lines changed: 95 additions & 0 deletions

File tree

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,30 @@ bind::views:
263263

264264
The defined types `bind::zone::primary` and `bind::zone::secondary` can be used to add zones to this view.
265265

266+
Global options that are not modeled as dedicated class parameters can be
267+
set with `custom_options`.
268+
269+
```puppet
270+
class { 'bind':
271+
custom_options => {
272+
'minimal-responses' => 'no-auth-recursive',
273+
},
274+
}
275+
```
276+
277+
The `bind::view` defined type supports the same pattern for per-view options:
278+
279+
```puppet
280+
bind::view { 'internal':
281+
match_clients => [ 'localnets', ],
282+
allow_query => [ 'localnets', ],
283+
allow_recursion => [ 'localnets', ],
284+
custom_options => {
285+
'minimal-responses' => true,
286+
},
287+
}
288+
```
289+
266290
## Reference
267291

268292
See [REFERENCE.md](https://github.com/smoeding/puppet-bind/blob/master/REFERENCE.md)

REFERENCE.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1997,6 +1997,7 @@ The following parameters are available in the `bind::view` defined type:
19971997
* [`view`](#-bind--view--view)
19981998
* [`order`](#-bind--view--order)
19991999
* [`response_policies`](#-bind--view--response_policies)
2000+
* [`custom_options`](#-bind--view--custom_options)
20002001

20012002
##### <a name="-bind--view--match_clients"></a>`match_clients`
20022003

@@ -2156,6 +2157,19 @@ An array of response policy zones.
21562157

21572158
Default value: `[]`
21582159

2160+
##### <a name="-bind--view--custom_options"></a>`custom_options`
2161+
2162+
Data type: `Hash[String,Data]`
2163+
2164+
Additional config options that are not implemented as parameters of this
2165+
defined type can be set by a hash of custom options. Each key of the hash
2166+
will be added to the view block of the configuration. For string or numeric
2167+
values the value will be added as a normal option value. If the value is a
2168+
hash or an array it will be included as an additional block enclosed in
2169+
braces.
2170+
2171+
Default value: `{}`
2172+
21592173
### <a name="bind--zone--forward"></a>`bind::zone::forward`
21602174

21612175
Manage a forward zone
@@ -3392,3 +3406,4 @@ Alias of `Enum['critical', 'error', 'warning', 'notice', 'info', 'debug', 'dynam
33923406
Type to match allowed values for the zone class
33933407

33943408
Alias of `Enum['IN', 'HS', 'CH']`
3409+

manifests/view.pp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@
7575
# @param response_policies
7676
# An array of response policy zones.
7777
#
78+
# @param custom_options
79+
# Additional config options that are not implemented as parameters of this
80+
# defined type can be set by a hash of custom options. Each key of the hash
81+
# will be added to the view block of the configuration. For string or numeric
82+
# values the value will be added as a normal option value. If the value is a
83+
# hash or an array it will be included as an additional block enclosed in
84+
# braces.
85+
#
7886
#
7987
define bind::view (
8088
Array[String] $match_clients = ['any',],
@@ -93,6 +101,7 @@
93101
String $view = $name,
94102
String $order = '10',
95103
Array[String] $response_policies = [],
104+
Hash[String,Data] $custom_options = {},
96105
Optional[Boolean] $localhost_forward_enable = undef,
97106
Optional[Boolean] $localhost_reverse_enable = undef,
98107
) {
@@ -120,6 +129,7 @@
120129
'allow_query_cache_on' => $allow_query_cache_on,
121130
'allow_transfer' => $allow_transfer,
122131
'response_policies' => $response_policies,
132+
'custom_options' => bind::gencfg($custom_options, 2),
123133
}
124134

125135
concat::fragment { "named.conf.views-${view}-00":

spec/defines/view_spec.rb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,48 @@
205205
}
206206
end
207207

208+
context 'with custom_options => { "minimal-responses" => true }' do
209+
let(:params) do
210+
{ custom_options: { 'minimal-responses' => true } }
211+
end
212+
213+
it {
214+
is_expected.to contain_concat__fragment('named.conf.views-internal-00')
215+
.with_target('named.conf.views')
216+
.with_content("\nview \"internal\" {\n match-clients {\n any;\n };\n\n allow-query {\n any;\n };\n\n recursion yes;\n\n minimal-responses yes;\n")
217+
.with_order('10')
218+
219+
is_expected.to contain_concat__fragment('named.conf.views-internal-99')
220+
.with_content('};')
221+
}
222+
end
223+
224+
context 'with custom_options => { "minimal-responses" => "no-auth-recursive" }' do
225+
let(:params) do
226+
{ custom_options: { 'minimal-responses' => 'no-auth-recursive' } }
227+
end
228+
229+
it {
230+
is_expected.to contain_concat__fragment('named.conf.views-internal-00')
231+
.with_target('named.conf.views')
232+
.with_content("\nview \"internal\" {\n match-clients {\n any;\n };\n\n allow-query {\n any;\n };\n\n recursion yes;\n\n minimal-responses no-auth-recursive;\n")
233+
.with_order('10')
234+
}
235+
end
236+
237+
context 'with custom_options => { "sortlist" => ["localnets", "localhost"] }' do
238+
let(:params) do
239+
{ custom_options: { 'sortlist' => ['localnets', 'localhost'] } }
240+
end
241+
242+
it {
243+
is_expected.to contain_concat__fragment('named.conf.views-internal-00')
244+
.with_target('named.conf.views')
245+
.with_content("\nview \"internal\" {\n match-clients {\n any;\n };\n\n allow-query {\n any;\n };\n\n recursion yes;\n\n sortlist {\n localnets;\n localhost;\n };\n")
246+
.with_order('10')
247+
}
248+
end
249+
208250
context 'with root_hints_enable => true' do
209251
let(:params) do
210252
{ root_hints_enable: true }

templates/view.epp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,7 @@ view "<%= $view -%>" {
8383
<% } -%>
8484
};
8585
<% } -%>
86+
<% unless empty($custom_options) { -%>
87+
88+
<%= $custom_options -%>
89+
<% } -%>

0 commit comments

Comments
 (0)