From 6793d28675445d3b6d3785c4f1d1f9a12edf6b78 Mon Sep 17 00:00:00 2001 From: Nacho Barrientos Date: Wed, 9 Dec 2020 12:15:16 +0100 Subject: [PATCH] Handle dport internally always as an array --- spec/defines/simplerule_spec.rb | 10 +++++----- templates/simplerule.epp | 6 +----- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/spec/defines/simplerule_spec.rb b/spec/defines/simplerule_spec.rb index 685e7f39..b848ed90 100644 --- a/spec/defines/simplerule_spec.rb +++ b/spec/defines/simplerule_spec.rb @@ -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', ) } @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/templates/simplerule.epp b/templates/simplerule.epp index 9692b918..03584925 100644 --- a/templates/simplerule.epp +++ b/templates/simplerule.epp @@ -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 } -%>