Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use an ip range instead of looping #176

Merged
merged 1 commit into from
Jan 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,18 +282,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 @@ -8,10 +8,8 @@
<%- if @port -%>
<%- @port.each do |i| -%>
<%- if i['port'] and i['port'] != '' -%>
<%- 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 -%>
<%- else -%>
<port protocol="<%= i['protocol'] %>" port="" />
<%- end -%>
Expand Down