Skip to content

Commit

Permalink
Merge pull request voxpupuli#546 from b4ldr/master
Browse files Browse the repository at this point in the history
allow listen_ip and ipv6_listen_ip to contain a String or Array
  • Loading branch information
jfryman committed Feb 5, 2015
2 parents 0ca64ef + 5d89abc commit 830350f
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 33 deletions.
8 changes: 6 additions & 2 deletions manifests/resource/mailhost.pp
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,16 @@
}
validate_re($ensure, '^(present|absent)$',
"${ensure} is not supported for ensure. Allowed values are 'present' and 'absent'.")
validate_string($listen_ip)
if !(is_array($listen_ip) or is_string($listen_ip)) {
fail('$listen_ip must be a string or array.')
}
if ($listen_options != undef) {
validate_string($listen_options)
}
validate_bool($ipv6_enable)
validate_string($ipv6_listen_ip)
if !(is_array($ipv6_listen_ip) or is_string($ipv6_listen_ip)) {
fail('$ipv6_listen_ip must be a string or array.')
}
if !is_integer($ipv6_listen_port) {
fail('$ipv6_listen_port must be an integer.')
}
Expand Down
8 changes: 6 additions & 2 deletions manifests/resource/vhost.pp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,9 @@

validate_re($ensure, '^(present|absent)$',
"${ensure} is not supported for ensure. Allowed values are 'present' and 'absent'.")
validate_string($listen_ip)
if !(is_array($listen_ip) or is_string($listen_ip)) {
fail('$listen_ip must be a string or array.')
}
if !is_integer($listen_port) {
fail('$listen_port must be an integer.')
}
Expand All @@ -245,7 +247,9 @@
validate_array($location_allow)
validate_array($location_deny)
validate_bool($ipv6_enable)
validate_string($ipv6_listen_ip)
if !(is_array($ipv6_listen_ip) or is_string($ipv6_listen_ip)) {
fail('$ipv6_listen_ip must be a string or array.')
}
if !is_integer($ipv6_listen_port) {
fail('$ipv6_listen_port must be an integer.')
}
Expand Down
15 changes: 8 additions & 7 deletions spec/defines/resource_mailhost_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,37 +209,37 @@
:title => 'should set the IPv4 SSL listen port',
:attr => 'ssl_port',
:value => '45',
:match => ' listen 45;',
:match => ' listen *:45;',
},
{
:title => 'should enable IPv6',
:attr => 'ipv6_enable',
:value => true,
:match => ' listen [::]:80 default ipv6only=on;',
:match => ' listen [::]:587 default ipv6only=on;',
},
{
:title => 'should not enable IPv6',
:attr => 'ipv6_enable',
:value => false,
:notmatch => / listen \[::\]:80 default ipv6only=on;/,
:notmatch => / listen \[::\]:587 default ipv6only=on;/,
},
{
:title => 'should set the IPv6 listen IP',
:attr => 'ipv6_listen_ip',
:value => '2001:0db8:85a3:0000:0000:8a2e:0370:7334',
:match => ' listen [2001:0db8:85a3:0000:0000:8a2e:0370:7334]:80 default ipv6only=on;',
:match => ' listen [2001:0db8:85a3:0000:0000:8a2e:0370:7334]:587 default ipv6only=on;',
},
{
:title => 'should set the IPv6 listen port',
:attr => 'ipv6_listen_port',
:title => 'should set the IPv6 ssl port',
:attr => 'ssl_port',
:value => 45,
:match => ' listen [::]:45 default ipv6only=on;',
},
{
:title => 'should set the IPv6 listen options',
:attr => 'ipv6_listen_options',
:value => 'spdy',
:match => ' listen [::]:80 spdy;',
:match => ' listen [::]:587 spdy;',
},
{
:title => 'should set servername(s)',
Expand Down Expand Up @@ -281,6 +281,7 @@
context "when #{param[:attr]} is #{param[:value]}" do
let :default_params do {
:listen_port => 25,
:ssl_port => 587,
:ipv6_enable => true,
:ssl => true,
:ssl_cert => 'dummy.crt',
Expand Down
6 changes: 0 additions & 6 deletions spec/defines/resource_vhost_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
:value => false,
:notmatch => %r|
^
\s+listen\s+\*:80;\n
\s+server_name\s+www\.rspec\.example\.com;\n
\s+return\s+301\s+http://rspec\.example\.com\$request_uri;
|x,
Expand All @@ -62,7 +61,6 @@
:value => true,
:match => %r|
^
\s+listen\s+\*:80;\n
\s+server_name\s+www\.rspec\.example\.com;\n
\s+return\s+301\s+http://rspec\.example\.com\$request_uri;
|x,
Expand Down Expand Up @@ -274,7 +272,6 @@
:value => false,
:notmatch => %r|
^
\s+listen\s+\*:443\s+ssl;\n
\s+server_name\s+www\.rspec\.example\.com;\n
\s+return\s+301\s+https://rspec\.example\.com\$request_uri;
|x,
Expand Down Expand Up @@ -339,7 +336,6 @@
:value => false,
:notmatch => %r|
^
\s+listen\s+\*:443\s+ssl;\n
\s+server_name\s+www\.rspec\.example\.com;\n
\s+return\s+301\s+https://rspec\.example\.com\$request_uri;
|x,
Expand All @@ -350,7 +346,6 @@
:value => true,
:match => %r|
^
\s+listen\s+\*:443\s+ssl;\n
\s+server_name\s+www\.rspec\.example\.com;\n
\s+return\s+301\s+https://rspec\.example\.com\$request_uri;
|x,
Expand Down Expand Up @@ -595,7 +590,6 @@
:value => false,
:notmatch => %r|
^
\s+listen\s+\*:443\s+ssl;\n
\s+server_name\s+www\.rspec\.example\.com;\n
\s+return\s+301\s+https://rspec\.example\.com\$request_uri;
|x,
Expand Down
20 changes: 16 additions & 4 deletions templates/mailhost/mailhost.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@

server {
<%- if @listen_ip.is_a?(Array) then -%>
<%- @listen_ip.each do |ip| -%>
listen <%= ip %>:<%= @listen_port %><% if @listen_options %> <%= @listen_options %><% end %>;
<%- end -%>
<%- else -%>
listen <%= @listen_ip %>:<%= @listen_port %><% if @listen_options %> <%= @listen_options %><% end %>;
<% # check to see if ipv6 support exists in the kernel before applying %>
<% if @ipv6_enable && (defined? @ipaddress6) %>
listen [<%= @ipv6_listen_ip %>]:<%= @ipv6_listen_port %><% if @ipv6_listen_options %> <%= @ipv6_listen_options %><% end %>;
<% end %>
<%- end -%>
<%# check to see if ipv6 support exists in the kernel before applying -%>
<%- if @ipv6_enable && (defined? @ipaddress6) -%>
<%- if @ipv6_listen_ip.is_a?(Array) then -%>
<%- @ipv6_listen_ip.each do |ipv6| -%>
listen [<%= ipv6 %>]:<%= @ipv6_listen_port %> <% if @ipv6_listen_options %><%= @ipv6_listen_options %><% end %>;
<%- end -%>
<%- else -%>
listen [<%= @ipv6_listen_ip %>]:<%= @ipv6_listen_port %> <% if @ipv6_listen_options %><%= @ipv6_listen_options %><% end %>;
<%- end -%>
<%- end -%>
server_name <%= @server_name.join(" ") %>;
protocol <%= @protocol %>;
xclient <%= @xclient %>;
Expand Down
22 changes: 17 additions & 5 deletions templates/mailhost/mailhost_ssl.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@

server {
listen <%= @ssl_port %>;
<% # check to see if ipv6 support exists in the kernel before applying %>
<% if @ipv6_enable && (defined? @ipaddress6) %>
listen [<%= @ipv6_listen_ip %>]:<%= @ipv6_listen_port %> <% if @ipv6_listen_options %><%= @ipv6_listen_options %><% end %>;
<% end %>
<%- if @listen_ip.is_a?(Array) then -%>
<%- @listen_ip.each do |ip| -%>
listen <%= ip %>:<%= @ssl_port %>;
<%- end -%>
<%- else -%>
listen <%= @listen_ip %>:<%= @ssl_port %>;
<%- end -%>
<%# check to see if ipv6 support exists in the kernel before applying -%>
<%- if @ipv6_enable && (defined? @ipaddress6) -%>
<%- if @ipv6_listen_ip.is_a?(Array) then -%>
<%- @ipv6_listen_ip.each do |ipv6| -%>
listen [<%= ipv6 %>]:<%= @ssl_port %><% if @ipv6_listen_options %> <%= @ipv6_listen_options %><% end %>;
<%- end -%>
<%- else -%>
listen [<%= @ipv6_listen_ip %>]:<%= @ssl_port %><% if @ipv6_listen_options %> <%= @ipv6_listen_options %><% end %>;
<%- end -%>
<%- end -%>
server_name <%= @server_name.join(" ") %>;
protocol <%= @protocol %>;
xclient <%= @xclient %>;
Expand Down
38 changes: 33 additions & 5 deletions templates/vhost/vhost_header.erb
Original file line number Diff line number Diff line change
@@ -1,20 +1,48 @@
<% if @rewrite_www_to_non_www -%>
server {
listen <%= @listen_ip %>:<%= @listen_port %>;
<%- if @listen_ip.is_a?(Array) then -%>
<%- @listen_ip.each do |ip| -%>
listen <%= ip %>:<%= @listen_port %><% if @listen_options %> <%= @listen_options %><% end %>;
<%- end -%>
<%- else -%>
listen <%= @listen_ip %>:<%= @listen_port %><% if @listen_options %> <%= @listen_options %><% end %>;
<%- end -%>
<%# check to see if ipv6 support exists in the kernel before applying -%>
<%- if @ipv6_enable && (defined? @ipaddress6) -%>
<%- if @ipv6_listen_ip.is_a?(Array) then -%>
<%- @ipv6_listen_ip.each do |ipv6| -%>
listen [<%= ipv6 %>]:<%= @ipv6_listen_port %> <% if @ipv6_listen_options %><%= @ipv6_listen_options %><% end %>;
<%- end -%>
<%- else -%>
listen [<%= @ipv6_listen_ip %>]:<%= @ipv6_listen_port %> <% if @ipv6_listen_options %><%= @ipv6_listen_options %><% end %>;
<%- end -%>
<%- end -%>
server_name www.<%= @server_name[0].gsub(/^www\./, '') %>;
return 301 http://<%= @server_name[0].gsub(/^www\./, '') %>$request_uri;
}

<% end -%>
server {
listen <%= @listen_ip %>:<%= @listen_port %><% if @listen_options %> <%= @listen_options %><% end %>;
<%- if @listen_ip.is_a?(Array) then -%>
<%- @listen_ip.each do |ip| -%>
listen <%= ip %>:<%= @listen_port %><% if @listen_options %> <%= @listen_options %><% end %>;
<%- end -%>
<%- else -%>
listen <%= @listen_ip %>:<%= @listen_port %><% if @listen_options %> <%= @listen_options %><% end %>;
<%- end -%>
<%# check to see if ipv6 support exists in the kernel before applying -%>
<% if @ipv6_enable && (defined? @ipaddress6) -%>
<%- if @ipv6_enable && (defined? @ipaddress6) -%>
<%- if @ipv6_listen_ip.is_a?(Array) then -%>
<%- @ipv6_listen_ip.each do |ipv6| -%>
listen [<%= ipv6 %>]:<%= @ipv6_listen_port %> <% if @ipv6_listen_options %><%= @ipv6_listen_options %><% end %>;
<%- end -%>
<%- else -%>
listen [<%= @ipv6_listen_ip %>]:<%= @ipv6_listen_port %> <% if @ipv6_listen_options %><%= @ipv6_listen_options %><% end %>;
<% end -%>
<%- end -%>
<%- end -%>
server_name <%= @rewrite_www_to_non_www ? @server_name[0].gsub(/^www\./, '') : @server_name.join(" ") %>;
<%- if instance_variables.any? { |iv| iv.to_s.include? 'auth_basic' } -%>
<% if defined? @auth_basic -%>
<%- if defined? @auth_basic -%>
auth_basic "<%= @auth_basic %>";
<%- end -%>
<%- if defined? @auth_basic_user_file -%>
Expand Down
33 changes: 31 additions & 2 deletions templates/vhost/vhost_ssl_header.erb
Original file line number Diff line number Diff line change
@@ -1,15 +1,44 @@
<% if @rewrite_www_to_non_www -%>
server {
listen <%= @listen_ip %>:<%= @ssl_port %> ssl;
<%- if @listen_ip.is_a?(Array) then -%>
<%- @listen_ip.each do |ip| -%>
listen <%= ip %>:<%= @ssl_port %> <% if @ssl_listen_option %>ssl<% end %><% if @spdy == 'on' %> spdy<% end %><% if @listen_options %> <%= @listen_options %><% end %>;
<%- end -%>
<%- else -%>
listen <%= @listen_ip %>:<%= @ssl_port %> <% if @ssl_listen_option %>ssl<% end %><% if @spdy == 'on' %> spdy<% end %><% if @listen_options %> <%= @listen_options %><% end %>;
<%- end -%>
<%# check to see if ipv6 support exists in the kernel before applying -%>
<%- if @ipv6_enable && (defined? @ipaddress6) -%>
<%- if @ipv6_listen_ip.is_a?(Array) then -%>
<%- @ipv6_listen_ip.each do |ipv6| -%>
listen [<%= ipv6 %>]:<%= @ssl_port %> ssl<% if @spdy == 'on' %> spdy<% end %><% if @ipv6_listen_options %> <%= @ipv6_listen_options %><% end %>;
<%- end -%>
<%- else -%>
listen [<%= @ipv6_listen_ip %>]:<%= @ssl_port %> ssl<% if @spdy == 'on' %> spdy<% end %><% if @ipv6_listen_options %> <%= @ipv6_listen_options %><% end %>;
<%- end -%>
<%- end -%>
server_name www.<%= @server_name[0].gsub(/^www\./, '') %>;
return 301 https://<%= @server_name[0].gsub(/^www\./, '') %>$request_uri;
}

<% end -%>
server {
<%- if @listen_ip.is_a?(Array) then -%>
<%- @listen_ip.each do |ip| -%>
listen <%= ip %>:<%= @ssl_port %> <% if @ssl_listen_option %>ssl<% end %><% if @spdy == 'on' %> spdy<% end %><% if @listen_options %> <%= @listen_options %><% end %>;
<%- end -%>
<%- else -%>
listen <%= @listen_ip %>:<%= @ssl_port %> <% if @ssl_listen_option %>ssl<% end %><% if @spdy == 'on' %> spdy<% end %><% if @listen_options %> <%= @listen_options %><% end %>;
<%- end -%>
<%# check to see if ipv6 support exists in the kernel before applying -%>
<%- if @ipv6_enable && (defined? @ipaddress6) -%>
listen [<%= @ipv6_listen_ip %>]:<%= @ssl_port %> ssl<% if @spdy == 'on' %> spdy<% end %><% if @ipv6_listen_options %> <%= @ipv6_listen_options %><% end %>;
<%- if @ipv6_listen_ip.is_a?(Array) then -%>
<%- @ipv6_listen_ip.each do |ipv6| -%>
listen [<%= ipv6 %>]:<%= @ssl_port %> ssl<% if @spdy == 'on' %> spdy<% end %><% if @ipv6_listen_options %> <%= @ipv6_listen_options %><% end %>;
<%- end -%>
<%- else -%>
listen [<%= @ipv6_listen_ip %>]:<%= @ssl_port %> ssl<% if @spdy == 'on' %> spdy<% end %><% if @ipv6_listen_options %> <%= @ipv6_listen_options %><% end %>;
<%- end -%>
<%- end -%>
server_name <%= @rewrite_www_to_non_www ? @server_name[0].gsub(/^www\./, '') : @server_name.join(" ") %>;

Expand Down

0 comments on commit 830350f

Please sign in to comment.