Key value parameter maps to take array as value

Allow arrays to be specified as values in location_cfg_{prepend,append} and
vhost_cfg_{ssl_,}{prepend,append} parameters.
This commit is contained in:
Daniel Black 2014-03-07 23:53:32 +11:00 committed by Daniel Black
parent fb560784e8
commit 04e34dce39
12 changed files with 131 additions and 54 deletions

View file

@ -44,11 +44,12 @@ describe 'nginx::resource::location' do
{ {
:title => 'should contain ordered prepended directives', :title => 'should contain ordered prepended directives',
:attr => 'location_cfg_prepend', :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 => [ :match => [
' allow test value 3;', ' allow test value 3;',
' test1 test value 1;', ' test1 test value 1;',
' test2 test value 2;', ' test2 test value 2a;',
' test2 test value 2b;',
], ],
}, },
{ {
@ -90,10 +91,11 @@ describe 'nginx::resource::location' do
{ {
:title => 'should contain ordered appended directives', :title => 'should contain ordered appended directives',
:attr => 'location_cfg_append', :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 => [ :match => [
' allow test value 3;', ' allow test value 3;',
' test1 test value 1;', ' test1 test value 1a;',
' test1 test value 1b;',
' test2 test value 2;', ' test2 test value 2;',
], ],
}, },
@ -157,10 +159,11 @@ describe 'nginx::resource::location' do
{ {
:title => 'should contain ordered prepended directives', :title => 'should contain ordered prepended directives',
:attr => 'location_cfg_prepend', :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 => [ :match => [
' allow test value 3;', ' allow test value 3;',
' test1 test value 1;', ' test1 test value 1a;',
' test1 test value 1b;',
' test2 test value 2;', ' test2 test value 2;',
], ],
}, },
@ -173,9 +176,11 @@ describe 'nginx::resource::location' do
{ {
:title => 'should contain ordered appended directives', :title => 'should contain ordered appended directives',
:attr => 'location_cfg_append', :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 => [ :match => [
' allow test value 3;', ' allow test value 3a;',
' allow test value 3b;',
' allow test value 3c;',
' test1 test value 1;', ' test1 test value 1;',
' test2 test value 2;', ' test2 test value 2;',
], ],
@ -208,20 +213,22 @@ describe 'nginx::resource::location' do
{ {
:title => 'should contain ordered prepended directives', :title => 'should contain ordered prepended directives',
:attr => 'location_cfg_prepend', :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 => [ :match => [
' allow test value 3;', ' allow test value 3;',
' test1 test value 1;', ' test1 test value 1;',
' test2 test value 2;', ' test2 test value 2a;',
' test2 test value 2b;',
], ],
}, },
{ {
:title => 'should contain ordered appended directives', :title => 'should contain ordered appended directives',
:attr => 'location_cfg_append', :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 => [ :match => [
' allow test value 3;', ' allow test value 3;',
' test1 test value 1;', ' test1 test value 1a;',
' test1 test value 1b;',
' test2 test value 2;', ' test2 test value 2;',
], ],
}, },
@ -253,11 +260,12 @@ describe 'nginx::resource::location' do
{ {
:title => 'should contain ordered prepended directives', :title => 'should contain ordered prepended directives',
:attr => 'location_cfg_prepend', :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 => [ :match => [
' allow test value 3;', ' allow test value 3;',
' test1 test value 1;', ' test1 test value 1a;',
' test2 test value 2;', ' test1 test value 1b;',
' test2 test value 2;',
], ],
}, },
{ {
@ -299,11 +307,12 @@ describe 'nginx::resource::location' do
{ {
:title => 'should contain ordered appended directives', :title => 'should contain ordered appended directives',
:attr => 'location_cfg_append', :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 => [ :match => [
' allow test value 3;', ' allow test value 3;',
' test1 test value 1;', ' test1 test value 1;',
' test2 test value 2;', ' test2 test value 2a;',
' test2 test value 2b;',
], ],
}, },
].each do |param| ].each do |param|
@ -346,11 +355,12 @@ describe 'nginx::resource::location' do
{ {
:title => 'should contain ordered prepended directives', :title => 'should contain ordered prepended directives',
:attr => 'location_cfg_prepend', :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 => [ :match => [
' allow test value 3;', ' allow test value 3;',
' test1 test value 1;', ' test1 test value 1;',
' test2 test value 2;', ' test2 test value 2a;',
' test2 test value 2b;',
], ],
}, },
{ {
@ -386,10 +396,11 @@ describe 'nginx::resource::location' do
{ {
:title => 'should contain ordered appended directives', :title => 'should contain ordered appended directives',
:attr => 'location_cfg_append', :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 => [ :match => [
' allow test value 3;', ' allow test value 3;',
' test1 test value 1;', ' test1 test value 1a;',
' test1 test value 1b;',
' test2 test value 2;', ' test2 test value 2;',
], ],
}, },
@ -441,10 +452,11 @@ describe 'nginx::resource::location' do
{ {
:title => 'should contain ordered config directives', :title => 'should contain ordered config directives',
:attr => 'location_custom_cfg', :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 => [ :match => [
' allow test value 3;', ' allow test value 3;',
' test1 test value 1;', ' test1 test value 1a;',
' test1 test value 1b;',
' test2 test value 2;', ' test2 test value 2;',
], ],
}, },

View file

@ -130,10 +130,11 @@ describe 'nginx::resource::vhost' do
{ {
:title => 'should contain ordered prepended directives', :title => 'should contain ordered prepended directives',
:attr => 'vhost_cfg_prepend', :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 => [ :match => [
' allow test value 3;', ' allow test value 3;',
' test1 test value 1;', ' test1 test value 1a;',
' test1 test value 1b;',
' test2 test value 2;', ' test2 test value 2;',
], ],
}, },
@ -218,11 +219,12 @@ describe 'nginx::resource::vhost' do
{ {
:title => 'should contain ordered appended directives', :title => 'should contain ordered appended directives',
:attr => 'vhost_cfg_append', :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 => [ :match => [
' allow test value 3;', ' allow test value 3;',
' test1 test value 1;', ' test1 test value 1;',
' test2 test value 2;', ' test2 test value 2a;',
' test2 test value 2b;',
], ],
}, },
{ {
@ -383,6 +385,28 @@ describe 'nginx::resource::vhost' do
:value => '/path/to/error.log', :value => '/path/to/error.log',
:match => ' error_log /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', :title => 'should set root',
:attr => 'use_default_location', :attr => 'use_default_location',
@ -436,6 +460,17 @@ describe 'nginx::resource::vhost' do
' test2 test value 2;', ' 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', :title => 'should contain www to non-www rewrite',
:attr => 'rewrite_www_to_non_www', :attr => 'rewrite_www_to_non_www',

View file

@ -5,10 +5,10 @@ include <%= file %>;
<%# exists) to be first in the output order. The hash keys also need to be -%> <%# exists) to be first in the output order. The hash keys also need to be -%>
<%# sorted so that the ordering is stable. -%> <%# 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| -%> <% if @vhost_cfg_append -%><% @vhost_cfg_append.sort_by{ |k, v| k.to_s == 'allow' ? '' : k.to_s }.each do |key,value| -%>
<%= key %> <%= value %>; <% Array(value).each do |sub| -%>
<% end -%> <%= key %> <%= sub %>;
<% end -%> <% end %>
} <% end -%><% end -%>
<% if @rewrite_www_to_non_www -%> <% if @rewrite_www_to_non_www -%>
server { server {
listen <%= @listen_ip %>:<%= @listen_port %>; listen <%= @listen_ip %>:<%= @listen_port %>;

View file

@ -18,7 +18,9 @@ server {
<%# exists) to be first in the output order. The hash keys also need to be -%> <%# exists) to be first in the output order. The hash keys also need to be -%>
<%# sorted so that the ordering is stable. -%> <%# 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| -%> <% 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 -%> <% end -%><% end -%>
<% if @root -%> <% if @root -%>
root <%= @root %>; root <%= @root %>;

View file

@ -1,10 +1,14 @@
location <%= @location %> { location <%= @location %> {
<% if @location_cfg_prepend -%><% @location_cfg_prepend.sort_by {|k,v| k}.each do |key,value| -%> <% 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 -%> <% end -%><% end -%>
alias <%= @location_alias %>; alias <%= @location_alias %>;
<% if @location_cfg_append -%><% @location_cfg_append.sort_by {|k,v| k}.each do |key,value| -%> <% 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 -%> <% end -%><% end -%>
} }

View file

@ -9,7 +9,9 @@
<%= value %> <%= value %>
<% end -%><% end -%> <% end -%><% end -%>
<% if @location_cfg_prepend -%><% @location_cfg_prepend.sort_by {|k,v| k}.each do |key,value| -%> <% 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 -%> <% end -%><% end -%>
<% if defined? @www_root -%> <% if defined? @www_root -%>
root <%= @www_root %>; root <%= @www_root %>;
@ -33,7 +35,9 @@
auth_basic_user_file <%= @auth_basic_user_file %>; auth_basic_user_file <%= @auth_basic_user_file %>;
<% end -%> <% end -%>
<% if @location_cfg_append -%><% @location_cfg_append.sort_by {|k,v| k}.each do |key,value| -%> <% 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 -%> <% end -%><% end -%>
<% if @location_custom_cfg_append -%><% @location_custom_cfg_append.each do |value| -%> <% if @location_custom_cfg_append -%><% @location_custom_cfg_append.each do |value| -%>
<%= value %> <%= value %>

View file

@ -1,6 +1,8 @@
location <%= @location %> { location <%= @location %> {
<% if @location_custom_cfg -%><% @location_custom_cfg.sort_by {|k,v| k}.each do |key,value| -%> <% 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 -%> <% end -%><% end -%>
} }

View file

@ -1,6 +1,8 @@
location <%= @location %> { location <%= @location %> {
<% if @location_cfg_prepend -%><% @location_cfg_prepend.sort_by {|k,v| k}.each do |key,value| -%> <% 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 -%> <% end -%><% end -%>
<% if @location_custom_cfg_prepend -%><% @location_custom_cfg_prepend.each do |value| -%> <% if @location_custom_cfg_prepend -%><% @location_custom_cfg_prepend.each do |value| -%>
<%= value %> <%= value %>
@ -20,7 +22,9 @@
fastcgi_param SCRIPT_FILENAME <%= @fastcgi_script %>; fastcgi_param SCRIPT_FILENAME <%= @fastcgi_script %>;
<% end -%> <% end -%>
<% if @location_cfg_append -%><% @location_cfg_append.sort_by {|k,v| k}.each do |key,value| -%> <% 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 -%> <% end -%><% end -%>
<% if @location_custom_cfg_append -%><% @location_custom_cfg_append.each do |value| -%> <% if @location_custom_cfg_append -%><% @location_custom_cfg_append.each do |value| -%>
<%= value %> <%= value %>

View file

@ -9,7 +9,9 @@
<%= value %> <%= value %>
<% end -%><% end -%> <% end -%><% end -%>
<% if @location_cfg_prepend -%><% @location_cfg_prepend.sort_by {|k,v| k}.each do |key,value| -%> <% 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 -%> <% end -%><% end -%>
<% if @proxy_cache -%> <% if @proxy_cache -%>
proxy_cache <%= @proxy_cache %>; proxy_cache <%= @proxy_cache %>;
@ -27,7 +29,9 @@
rewrite <%= rewrite_rule %>; rewrite <%= rewrite_rule %>;
<% end -%> <% end -%>
<% if @location_cfg_append -%><% @location_cfg_append.sort_by {|k,v| k}.each do |key,value| -%> <% 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 -%> <% end -%><% end -%>
<% if @location_custom_cfg_append -%><% @location_custom_cfg_append.each do |value| -%> <% if @location_custom_cfg_append -%><% @location_custom_cfg_append.each do |value| -%>
<%= value %> <%= value %>

View file

@ -1,10 +1,14 @@
location <%= @location %> { location <%= @location %> {
<% if @location_cfg_prepend -%><% @location_cfg_prepend.sort_by {|k,v| k}.each do |key,value| -%> <% 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 -%> <% end -%><% end -%>
stub_status on; stub_status on;
<% if @location_cfg_append -%><% @location_cfg_append.sort_by {|k,v| k}.each do |key,value| -%> <% 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 -%> <% end -%><% end -%>
} }

View file

@ -2,13 +2,15 @@
include <%= file %>; include <%= file %>;
<% end -%><% end -%> <% end -%><% end -%>
<% if @vhost_cfg_append -%><% @vhost_cfg_append.sort_by{ |k, v| k.to_s == 'allow' ? '' : k.to_s }.each do |key,value| -%> <% if @vhost_cfg_append -%><% @vhost_cfg_append.sort_by{ |k, v| k.to_s == 'allow' ? '' : k.to_s }.each do |key,value| -%>
<%= key %> <%= value %>; <% Array(value).each do |sub| -%>
<% end -%> <%= key %> <%= sub %>;
<% end -%> <% 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| -%> <% 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 %>; <% Array(value).each do |sub| -%>
<% end -%> <%= key %> <%= sub %>;
<% end -%> <% end %>
<% end -%><% end -%>
} }
<% if @rewrite_www_to_non_www -%> <% if @rewrite_www_to_non_www -%>
server { server {

View file

@ -49,10 +49,14 @@ server {
error_log <%= @ssl_error_log %>; error_log <%= @ssl_error_log %>;
<% if @vhost_cfg_prepend -%><% @vhost_cfg_prepend.sort_by{ |k, v| k.to_s == 'allow' ? '' : k.to_s }.each do |key,value| -%> <% 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 -%> <% end -%><% end -%>
<% if @vhost_cfg_ssl_prepend -%><% @vhost_cfg_ssl_prepend.sort_by{ |k, v| k.to_s == 'allow' ? '' : k.to_s }.each do |key,value| -%> <% if @vhost_cfg_ssl_prepend -%><% @vhost_cfg_ssl_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 -%> <% end -%><% end -%>
<% if @root -%> <% if @root -%>
root <%= @root %>; root <%= @root %>;