Skip to content

Commit

Permalink
Use an ip range instead of looping
Browse files Browse the repository at this point in the history
  • Loading branch information
jovandeginste committed Apr 26, 2018
1 parent 882e722 commit b1f2625
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 14 deletions.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,18 +273,16 @@ and you will also see 'puppet' in the service list when you issue ```firewall-cm
port => [{'port' => '4321', 'protocol' => 'udp'}, {'protocol' => 'rdp'}],
```

The `port` parameter can also take a range of ports separated by a colon, for example:
The `port` parameter can also take a range of ports separated by a colon or a dash (colons are replaced by dashes), for example:

```puppet
port => [ {'port' => '8000:8002', 'protocol' => 'tcp']} ]
```

will produce;
will produce:

```xml
<port protocol="tcp" port="8000" />
<port protocol="tcp" port="8001" />
<port protocol="tcp" port="8002" />
<port protocol="tcp" port="8000-8002" />
```

* `module`: (Optional) An array of strings specifying netfilter kernel helper modules associated with this service
Expand Down
8 changes: 2 additions & 6 deletions spec/fixtures/services/custom_service_port_range.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@
<short>myservice</short>
<description>My multi port service</description>

<port protocol="tcp" port="8000" />
<port protocol="tcp" port="8001" />
<port protocol="tcp" port="8002" />
<port protocol="udp" port="8000" />
<port protocol="udp" port="8001" />
<port protocol="udp" port="8002" />
<port protocol="tcp" port="8000-8002" />
<port protocol="udp" port="8000-8002" />

<module name="nf_conntrack_netbios_ns" />

Expand Down
4 changes: 1 addition & 3 deletions templates/service.xml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@

<%- if @port -%>
<%- @port.each do |i| -%>
<%- range = sprintf('%s',i['port']).split(/:/).map { |p| p.to_i } -%>
<%- (range[0]..range[1] || range[0]).each do |p| -%>
<%- p = sprintf('%s',i['port']).sub(/:/, '-') -%>
<port<% if i['protocol'] -%> protocol="<%= i['protocol'] %>"<% end -%> port="<%= p %>" />
<%- end -%>
<%- end -%>

<%- end -%>
Expand Down

0 comments on commit b1f2625

Please sign in to comment.