Skip to content

Commit

Permalink
Handle dport internally always as an array
Browse files Browse the repository at this point in the history
  • Loading branch information
nbarrientos committed Dec 9, 2020
1 parent 467ea4e commit 6793d28
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
10 changes: 5 additions & 5 deletions spec/defines/simplerule_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
it { is_expected.to compile }
it {
is_expected.to contain_nftables__rule('default_out-my_big_rule').with(
content: 'udp dport 333 ip6 daddr 2001:1458::/32 counter accept comment "this is my rule"',
content: 'udp dport {333} ip6 daddr 2001:1458::/32 counter accept comment "this is my rule"',
order: '50',
)
}
Expand All @@ -63,7 +63,7 @@
it { is_expected.to compile }
it {
is_expected.to contain_nftables__rule('default_in-my_default_rule_name').with(
content: 'tcp dport 333-334 accept',
content: 'tcp dport {333-334} accept',
)
}
end
Expand Down Expand Up @@ -95,7 +95,7 @@
it { is_expected.to compile }
it {
is_expected.to contain_nftables__rule('default_in-my_default_rule_name').with(
content: 'ip version 4 tcp dport 333 accept',
content: 'ip version 4 tcp dport {333} accept',
)
}
end
Expand All @@ -111,7 +111,7 @@
it { is_expected.to compile }
it {
is_expected.to contain_nftables__rule('default_in-my_default_rule_name').with(
content: 'ip version 6 udp dport 33 accept',
content: 'ip version 6 udp dport {33} accept',
)
}
end
Expand All @@ -128,7 +128,7 @@
it { is_expected.to compile }
it {
is_expected.to contain_nftables__rule('default_in-my_default_rule_name').with(
content: 'tcp dport 33 ip daddr 192.168.0.1/24 accept',
content: 'tcp dport {33} ip daddr 192.168.0.1/24 accept',
)
}
end
Expand Down
6 changes: 1 addition & 5 deletions templates/simplerule.epp
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@
$_dst_hosts = undef
} -%>
<%- if $proto and $dport {
if $dport =~ Array {
$_dst_port = "${_proto} dport {${dport.join(', ')}}"
} else {
$_dst_port = "${_proto} dport $dport"
}
$_dst_port = "${_proto} dport {${Array($dport, true).join(', ')}}"
} else {
$_dst_port = undef
} -%>
Expand Down

0 comments on commit 6793d28

Please sign in to comment.