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

Allow arrays to be specified as values in location_cfg_* parameters #201

Closed
wants to merge 1 commit into from
Closed
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
64 changes: 38 additions & 26 deletions spec/defines/resource_location_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@
{
:title => 'should contain ordered prepended directives',
:attr => 'location_cfg_prepend',
:value => { 'test1' => 'test value 1', 'test2' => 'test value 2', 'allow' => 'test value 3' },
:value => { 'test1' => 'test value 1', 'test2' => ['test value 2a', 'test value 2b'], 'allow' => 'test value 3' },
:match => [
' allow test value 3;',
' test1 test value 1;',
' test2 test value 2;',
' allow test value 3;',
' test1 test value 1;',
' test2 test value 2a;',
' test2 test value 2b;',
],
},
{
Expand Down Expand Up @@ -90,10 +91,11 @@
{
:title => 'should contain ordered appended directives',
:attr => 'location_cfg_append',
:value => { 'test1' => 'test value 1', 'test2' => 'test value 2', 'allow' => 'test value 3' },
:value => { 'test1' => ['test value 1a', 'test value 1b'], 'test2' => 'test value 2', 'allow' => 'test value 3' },
:match => [
' allow test value 3;',
' test1 test value 1;',
' test1 test value 1a;',
' test1 test value 1b;',
' test2 test value 2;',
],
},
Expand Down Expand Up @@ -157,10 +159,11 @@
{
:title => 'should contain ordered prepended directives',
:attr => 'location_cfg_prepend',
:value => { 'test1' => 'test value 1', 'test2' => 'test value 2', 'allow' => 'test value 3' },
:value => { 'test1' => ['test value 1a', 'test value 1b'], 'test2' => 'test value 2', 'allow' => 'test value 3' },
:match => [
' allow test value 3;',
' test1 test value 1;',
' test1 test value 1a;',
' test1 test value 1b;',
' test2 test value 2;',
],
},
Expand All @@ -173,9 +176,11 @@
{
:title => 'should contain ordered appended directives',
:attr => 'location_cfg_append',
:value => { 'test1' => 'test value 1', 'test2' => 'test value 2', 'allow' => 'test value 3' },
:value => { 'test1' => 'test value 1', 'test2' => 'test value 2', 'allow' => ['test value 3a', 'test value 3b', 'test value 3c'] },
:match => [
' allow test value 3;',
' allow test value 3a;',
' allow test value 3b;',
' allow test value 3c;',
' test1 test value 1;',
' test2 test value 2;',
],
Expand Down Expand Up @@ -208,20 +213,22 @@
{
:title => 'should contain ordered prepended directives',
:attr => 'location_cfg_prepend',
:value => { 'test1' => 'test value 1', 'test2' => 'test value 2', 'allow' => 'test value 3' },
:value => { 'test1' => 'test value 1', 'test2' => ['test value 2a', 'test value 2b'], 'allow' => 'test value 3' },
:match => [
' allow test value 3;',
' test1 test value 1;',
' test2 test value 2;',
' test2 test value 2a;',
' test2 test value 2b;',
],
},
{
:title => 'should contain ordered appended directives',
:attr => 'location_cfg_append',
:value => { 'test1' => 'test value 1', 'test2' => 'test value 2', 'allow' => 'test value 3' },
:value => { 'test1' => ['test value 1a', 'test value 1b'], 'test2' => 'test value 2', 'allow' => 'test value 3' },
:match => [
' allow test value 3;',
' test1 test value 1;',
' test1 test value 1a;',
' test1 test value 1b;',
' test2 test value 2;',
],
},
Expand Down Expand Up @@ -253,11 +260,12 @@
{
:title => 'should contain ordered prepended directives',
:attr => 'location_cfg_prepend',
:value => { 'test1' => 'test value 1', 'test2' => 'test value 2', 'allow' => 'test value 3' },
:value => { 'test1' => ['test value 1a', 'test value 1b'], 'test2' => 'test value 2', 'allow' => 'test value 3' },
:match => [
' allow test value 3;',
' test1 test value 1;',
' test2 test value 2;',
' allow test value 3;',
' test1 test value 1a;',
' test1 test value 1b;',
' test2 test value 2;',
],
},
{
Expand Down Expand Up @@ -299,11 +307,12 @@
{
:title => 'should contain ordered appended directives',
:attr => 'location_cfg_append',
:value => { 'test1' => 'test value 1', 'test2' => 'test value 2', 'allow' => 'test value 3' },
:value => { 'test1' => 'test value 1', 'test2' => ['test value 2a', 'test value 2b'], 'allow' => 'test value 3' },
:match => [
' allow test value 3;',
' test1 test value 1;',
' test2 test value 2;',
' test2 test value 2a;',
' test2 test value 2b;',
],
},
].each do |param|
Expand Down Expand Up @@ -346,11 +355,12 @@
{
:title => 'should contain ordered prepended directives',
:attr => 'location_cfg_prepend',
:value => { 'test1' => 'test value 1', 'test2' => 'test value 2', 'allow' => 'test value 3' },
:value => { 'test1' => 'test value 1', 'test2' => ['test value 2a', 'test value 2b'], 'allow' => 'test value 3' },
:match => [
' allow test value 3;',
' test1 test value 1;',
' test2 test value 2;',
' test2 test value 2a;',
' test2 test value 2b;',
],
},
{
Expand Down Expand Up @@ -386,10 +396,11 @@
{
:title => 'should contain ordered appended directives',
:attr => 'location_cfg_append',
:value => { 'test1' => 'test value 1', 'test2' => 'test value 2', 'allow' => 'test value 3' },
:value => { 'test1' => ['test value 1a', 'test value 1b'], 'test2' => 'test value 2', 'allow' => 'test value 3' },
:match => [
' allow test value 3;',
' test1 test value 1;',
' test1 test value 1a;',
' test1 test value 1b;',
' test2 test value 2;',
],
},
Expand Down Expand Up @@ -441,10 +452,11 @@
{
:title => 'should contain ordered config directives',
:attr => 'location_custom_cfg',
:value => { 'test1' => 'test value 1', 'test2' => 'test value 2', 'allow' => 'test value 3' },
:value => { 'test1' => ['test value 1a', 'test value 1b'], 'test2' => 'test value 2', 'allow' => 'test value 3' },
:match => [
' allow test value 3;',
' test1 test value 1;',
' test1 test value 1a;',
' test1 test value 1b;',
' test2 test value 2;',
],
},
Expand Down
43 changes: 39 additions & 4 deletions spec/defines/resource_vhost_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,11 @@
{
:title => 'should contain ordered prepended directives',
:attr => 'vhost_cfg_prepend',
:value => { 'test1' => 'test value 1', 'test2' => 'test value 2', 'allow' => 'test value 3' },
:value => { 'test1' => ['test value 1a', 'test value 1b'], 'test2' => 'test value 2', 'allow' => 'test value 3' },
:match => [
' allow test value 3;',
' test1 test value 1;',
' test1 test value 1a;',
' test1 test value 1b;',
' test2 test value 2;',
],
},
Expand Down Expand Up @@ -218,11 +219,12 @@
{
:title => 'should contain ordered appended directives',
:attr => 'vhost_cfg_append',
:value => { 'test1' => 'test value 1', 'test2' => 'test value 2', 'allow' => 'test value 3' },
:value => { 'test1' => 'test value 1', 'test2' => ['test value 2a', 'test value 2b'], 'allow' => 'test value 3' },
:match => [
' allow test value 3;',
' test1 test value 1;',
' test2 test value 2;',
' test2 test value 2a;',
' test2 test value 2b;',
],
},
{
Expand Down Expand Up @@ -383,6 +385,28 @@
:value => '/path/to/error.log',
:match => ' error_log /path/to/error.log;',
},
{
:title => 'should contain ordered prepend directives',
:attr => 'vhost_cfg_prepend',
:value => { 'test1' => 'test value 1', 'test2' => ['test value 2a', 'test value 2b'], 'allow' => 'test value 3' },
:match => [
' allow test value 3;',
' test1 test value 1;',
' test2 test value 2a;',
' test2 test value 2b;',
]
},
{
:title => 'should contain ordered ssl prepend directives',
:attr => 'vhost_cfg_ssl_prepend',
:value => { 'test1' => 'test value 1', 'test2' => ['test value 2a', 'test value 2b'], 'allow' => 'test value 3' },
:match => [
' allow test value 3;',
' test1 test value 1;',
' test2 test value 2a;',
' test2 test value 2b;',
]
},
{
:title => 'should set root',
:attr => 'use_default_location',
Expand Down Expand Up @@ -436,6 +460,17 @@
' test2 test value 2;',
]
},
{
:title => 'should contain ordered ssl appended directives',
:attr => 'vhost_cfg_ssl_append',
:value => { 'test1' => 'test value 1', 'test2' => ['test value 2a', 'test value 2b'], 'allow' => 'test value 3' },
:match => [
' allow test value 3;',
' test1 test value 1;',
' test2 test value 2a;',
' test2 test value 2b;',
]
},
{
:title => 'should contain www to non-www rewrite',
:attr => 'rewrite_www_to_non_www',
Expand Down
8 changes: 4 additions & 4 deletions templates/vhost/vhost_footer.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ include <%= file %>;
<%# exists) to be first in the output order. The hash keys also need to be -%>
<%# sorted so that the ordering is stable. -%>
<% if @vhost_cfg_append -%><% @vhost_cfg_append.sort_by{ |k, v| k.to_s == 'allow' ? '' : k.to_s }.each do |key,value| -%>
<%= key %> <%= value %>;
<% end -%>
<% end -%>
}
<% Array(value).each do |sub| -%>
<%= key %> <%= sub %>;
<% end %>
<% end -%><% end -%>
<% if @rewrite_www_to_non_www -%>
server {
listen <%= @listen_ip %>:<%= @listen_port %>;
Expand Down
4 changes: 3 additions & 1 deletion templates/vhost/vhost_header.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ server {
<%# exists) to be first in the output order. The hash keys also need to be -%>
<%# sorted so that the ordering is stable. -%>
<% if @vhost_cfg_prepend -%><% @vhost_cfg_prepend.sort_by{ |k, v| k.to_s == 'allow' ? '' : k.to_s }.each do |key,value| -%>
<%= key %> <%= value %>;
<% Array(value).each do |sub| -%>
<%= key %> <%= sub %>;
<% end %>
<% end -%><% end -%>
<% if @root -%>
root <%= @root %>;
Expand Down
8 changes: 6 additions & 2 deletions templates/vhost/vhost_location_alias.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
location <%= @location %> {
<% if @location_cfg_prepend -%><% @location_cfg_prepend.sort_by {|k,v| k}.each do |key,value| -%>
<%= key %> <%= value %>;
<% Array(value).each do |sub| -%>
<%= key %> <%= sub %>;
<% end %>
<% end -%><% end -%>
alias <%= @location_alias %>;
<% if @location_cfg_append -%><% @location_cfg_append.sort_by {|k,v| k}.each do |key,value| -%>
<%= key %> <%= value %>;
<% Array(value).each do |sub| -%>
<%= key %> <%= sub %>;
<% end %>
<% end -%><% end -%>
}

8 changes: 6 additions & 2 deletions templates/vhost/vhost_location_directory.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
<%= value %>
<% end -%><% end -%>
<% if @location_cfg_prepend -%><% @location_cfg_prepend.sort_by {|k,v| k}.each do |key,value| -%>
<%= key %> <%= value %>;
<% Array(value).each do |sub| -%>
<%= key %> <%= sub %>;
<% end %>
<% end -%><% end -%>
<% if defined? @www_root -%>
root <%= @www_root %>;
Expand All @@ -33,7 +35,9 @@
auth_basic_user_file <%= @auth_basic_user_file %>;
<% end -%>
<% if @location_cfg_append -%><% @location_cfg_append.sort_by {|k,v| k}.each do |key,value| -%>
<%= key %> <%= value %>;
<% Array(value).each do |sub| -%>
<%= key %> <%= sub %>;
<% end %>
<% end -%><% end -%>
<% if @location_custom_cfg_append -%><% @location_custom_cfg_append.each do |value| -%>
<%= value %>
Expand Down
4 changes: 3 additions & 1 deletion templates/vhost/vhost_location_empty.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
location <%= @location %> {
<% if @location_custom_cfg -%><% @location_custom_cfg.sort_by {|k,v| k}.each do |key,value| -%>
<%= key %> <%= value %>;
<% Array(value).each do |sub| -%>
<%= key %> <%= sub %>;
<% end %>
<% end -%><% end -%>
}

8 changes: 6 additions & 2 deletions templates/vhost/vhost_location_fastcgi.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
location <%= @location %> {
<% if @location_cfg_prepend -%><% @location_cfg_prepend.sort_by {|k,v| k}.each do |key,value| -%>
<%= key %> <%= value %>;
<% Array(value).each do |sub| -%>
<%= key %> <%= sub %>;
<% end %>
<% end -%><% end -%>
<% if @location_custom_cfg_prepend -%><% @location_custom_cfg_prepend.each do |value| -%>
<%= value %>
Expand All @@ -20,7 +22,9 @@
fastcgi_param SCRIPT_FILENAME <%= @fastcgi_script %>;
<% end -%>
<% if @location_cfg_append -%><% @location_cfg_append.sort_by {|k,v| k}.each do |key,value| -%>
<%= key %> <%= value %>;
<% Array(value).each do |sub| -%>
<%= key %> <%= sub %>;
<% end %>
<% end -%><% end -%>
<% if @location_custom_cfg_append -%><% @location_custom_cfg_append.each do |value| -%>
<%= value %>
Expand Down
8 changes: 6 additions & 2 deletions templates/vhost/vhost_location_proxy.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
<%= value %>
<% end -%><% end -%>
<% if @location_cfg_prepend -%><% @location_cfg_prepend.sort_by {|k,v| k}.each do |key,value| -%>
<%= key %> <%= value %>;
<% Array(value).each do |sub| -%>
<%= key %> <%= sub %>;
<% end %>
<% end -%><% end -%>
<% if @proxy_cache -%>
proxy_cache <%= @proxy_cache %>;
Expand All @@ -27,7 +29,9 @@
rewrite <%= rewrite_rule %>;
<% end -%>
<% if @location_cfg_append -%><% @location_cfg_append.sort_by {|k,v| k}.each do |key,value| -%>
<%= key %> <%= value %>;
<% Array(value).each do |sub| -%>
<%= key %> <%= sub %>;
<% end %>
<% end -%><% end -%>
<% if @location_custom_cfg_append -%><% @location_custom_cfg_append.each do |value| -%>
<%= value %>
Expand Down
8 changes: 6 additions & 2 deletions templates/vhost/vhost_location_stub_status.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
location <%= @location %> {
<% if @location_cfg_prepend -%><% @location_cfg_prepend.sort_by {|k,v| k}.each do |key,value| -%>
<%= key %> <%= value %>;
<% Array(value).each do |sub| -%>
<%= key %> <%= sub %>;
<% end %>
<% end -%><% end -%>
stub_status on;
<% if @location_cfg_append -%><% @location_cfg_append.sort_by {|k,v| k}.each do |key,value| -%>
<%= key %> <%= value %>;
<% Array(value).each do |sub| -%>
<%= key %> <%= sub %>;
<% end %>
<% end -%><% end -%>
}

14 changes: 8 additions & 6 deletions templates/vhost/vhost_ssl_footer.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
include <%= file %>;
<% end -%><% end -%>
<% if @vhost_cfg_append -%><% @vhost_cfg_append.sort_by{ |k, v| k.to_s == 'allow' ? '' : k.to_s }.each do |key,value| -%>
<%= key %> <%= value %>;
<% end -%>
<% end -%>
<% Array(value).each do |sub| -%>
<%= key %> <%= sub %>;
<% end %>
<% end -%><% end -%>
<% if @vhost_cfg_ssl_append -%><% @vhost_cfg_ssl_append.sort_by{ |k, v| k.to_s == 'allow' ? '' : k.to_s }.each do |key,value| -%>
<%= key %> <%= value %>;
<% end -%>
<% end -%>
<% Array(value).each do |sub| -%>
<%= key %> <%= sub %>;
<% end %>
<% end -%><% end -%>
}
<% if @rewrite_www_to_non_www -%>
server {
Expand Down
Loading