Projet

Général

Profil

Révision 3a52fb41

ID3a52fb41aeb0adc8ad5680ea88bc2b8d4ccfc173
Parent fb65734d
Enfant 316bc3f8

Ajouté par Nacho Barrientos il y a plus de 4 ans

Richer dport

Voir les différences:

manifests/simplerule.pp
16 16
    $action = 'accept',
17 17
  Optional[String]
18 18
    $comment = undef,
19
  Optional[Integer[1, 65535]]
19
  Optional[Variant[Array[Stdlib::Port, 1], Stdlib::Port, Pattern[/\d+-\d+/]]]
20 20
    $dport  = undef,
21 21
  Optional[Enum['tcp', 'udp']]
22 22
    $proto  = undef,
23 23
){
24 24

  
25
  if $dport and !$proto {
26
    fail('Specifying a transport protocol via $proto is mandatory when passing a port')
27
  }
28

  
25 29
  if $ensure == 'present' {
26 30
    nftables::rule{"${chain}-${rulename}":
27 31
      content => epp('nftables/simplerule.epp',
spec/defines/simplerule_spec.rb
14 14
        it {
15 15
          is_expected.to contain_nftables__rule('default_in-my_default_rule_name').with(
16 16
            content: 'accept',
17
            order: 50,
17
            order: '50',
18 18
          )
19 19
        }
20 20
      end
......
35 35
        it {
36 36
          is_expected.to contain_nftables__rule('default_out-my_big_rule').with(
37 37
            content: 'udp dport 333 comment "this is my rule" accept',
38
            order: 50,
38
            order: '50',
39
          )
40
        }
41
      end
42

  
43
      describe 'port range' do
44
        let(:params) do
45
          {
46
            dport: '333-334',
47
            proto: 'tcp',
48
          }
49
        end
50

  
51
        it { is_expected.to compile }
52
        it {
53
          is_expected.to contain_nftables__rule('default_in-my_default_rule_name').with(
54
            content: 'tcp dport 333-334 accept',
55
          )
56
        }
57
      end
58

  
59
      describe 'port array' do
60
        let(:params) do
61
          {
62
            dport: [333, 335],
63
            proto: 'tcp',
64
          }
65
        end
66

  
67
        it { is_expected.to compile }
68
        it {
69
          is_expected.to contain_nftables__rule('default_in-my_default_rule_name').with(
70
            content: 'tcp dport {333, 335} accept',
39 71
          )
40 72
        }
41 73
      end
templates/simplerule.epp
1 1
<%- | String                  $action,
2 2
      Optional[String]        $comment,
3
      Optional[Integer]       $dport,
3
      Optional[Variant[Array[Stdlib::Port, 1], Stdlib::Port, String]] $dport,
4 4
      Optional[String]        $proto,
5 5
| -%>
6
<%- if $proto and $dport  {
7
  $_destination = "${proto} dport ${dport}"
6
<%- if $proto and $dport {
7
  if $dport =~ Array {
8
    $_destination = "${proto} dport {${dport.join(', ')}}"
9
  } else {
10
    $_destination = "${proto} dport $dport"
11
  }
8 12
} else {
9 13
  $_destination = undef
10 14
} -%>
......
13 17
} else {
14 18
  $_comment = undef
15 19
} -%>
16
<%= strip([$_destination, $_comment, $action].join(' ')) -%>
20
<%= regsubst(strip([$_destination, $_comment, $action].join(' ')), '\s+', ' ', 'G') -%>

Formats disponibles : Unified diff