Skip to content

Commit

Permalink
rules::out:dns: refactor for better readability
Browse files Browse the repository at this point in the history
  • Loading branch information
bastelfreak committed Dec 19, 2023
1 parent ee2d38a commit 195af59
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 27 deletions.
4 changes: 2 additions & 2 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -913,11 +913,11 @@ The following parameters are available in the `nftables::rules::out::dns` class:

##### <a name="-nftables--rules--out--dns--dns_server"></a>`dns_server`

Data type: `Optional[Variant[String,Array[String,1]]]`
Data type: `Array[Stdlib::IP::Address]`

specify dns_server name

Default value: `undef`
Default value: `[]`

### <a name="nftables--rules--out--hkp"></a>`nftables::rules::out::hkp`

Expand Down
35 changes: 10 additions & 25 deletions manifests/rules/out/dns.pp
Original file line number Diff line number Diff line change
@@ -1,34 +1,19 @@
# @summary manage out dns
# @param dns_server specify dns_server name
class nftables::rules::out::dns (
Optional[Variant[String,Array[String,1]]] $dns_server = undef,
Array[Stdlib::IP::Address] $dns_server = [],
) {
if $dns_server {
any2array($dns_server).each |$index,$dns| {
nftables::rule {
"default_out-dnsudp-${index}":
unless emtpy($dns_servers) {

Check warning on line 6 in manifests/rules/out/dns.pp

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

top-scope variable being used without an explicit namespace (check: variable_scope)
$dns_servers.each |$index,$dns| {

Check warning on line 7 in manifests/rules/out/dns.pp

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

top-scope variable being used without an explicit namespace (check: variable_scope)
$content = $dns ? {
Stdlib::IP::Address::V6 => "ip6 daddr ${dns}",
Stdlib::IP::Address::V4 => "ip daddr ${dns}",
}
if $dns =~ /:/ {
Nftables::Rule["default_out-dnsudp-${index}"] {
content => "ip6 daddr ${dns} udp dport 53 accept",
}
} else {
Nftables::Rule["default_out-dnsudp-${index}"] {
content => "ip daddr ${dns} udp dport 53 accept",
}
nftables::rule { "default_out-dnstcp-${index}":
content => "${content} tcp dport 53 accept",
}

nftables::rule {
"default_out-dnstcp-${index}":
}
if $dns =~ /:/ {
Nftables::Rule["default_out-dnstcp-${index}"] {
content => "ip6 daddr ${dns} tcp dport 53 accept",
}
} else {
Nftables::Rule["default_out-dnstcp-${index}"] {
content => "ip daddr ${dns} tcp dport 53 accept",
}
nftables::rule { "default_out-dnsudp-${index}":
content => "${content} udp dport 53 accept",
}
}
} else {
Expand Down
File renamed without changes.

0 comments on commit 195af59

Please sign in to comment.