From 04e34dce39692e5a4ea3c9d80941ac21eda3d210 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Fri, 7 Mar 2014 23:53:32 +1100 Subject: [PATCH] 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. --- spec/defines/resource_location_spec.rb | 64 +++++++++++-------- spec/defines/resource_vhost_spec.rb | 43 +++++++++++-- templates/vhost/vhost_footer.erb | 8 +-- templates/vhost/vhost_header.erb | 4 +- templates/vhost/vhost_location_alias.erb | 8 ++- templates/vhost/vhost_location_directory.erb | 8 ++- templates/vhost/vhost_location_empty.erb | 4 +- templates/vhost/vhost_location_fastcgi.erb | 8 ++- templates/vhost/vhost_location_proxy.erb | 8 ++- .../vhost/vhost_location_stub_status.erb | 8 ++- templates/vhost/vhost_ssl_footer.erb | 14 ++-- templates/vhost/vhost_ssl_header.erb | 8 ++- 12 files changed, 131 insertions(+), 54 deletions(-) diff --git a/spec/defines/resource_location_spec.rb b/spec/defines/resource_location_spec.rb index 82de857..0346f4b 100644 --- a/spec/defines/resource_location_spec.rb +++ b/spec/defines/resource_location_spec.rb @@ -44,11 +44,12 @@ describe 'nginx::resource::location' do { :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;', ], }, { @@ -90,10 +91,11 @@ describe 'nginx::resource::location' do { :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;', ], }, @@ -157,10 +159,11 @@ describe 'nginx::resource::location' do { :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;', ], }, @@ -173,9 +176,11 @@ describe 'nginx::resource::location' do { :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;', ], @@ -208,20 +213,22 @@ describe 'nginx::resource::location' do { :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;', ], }, @@ -253,11 +260,12 @@ describe 'nginx::resource::location' do { :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;', ], }, { @@ -299,11 +307,12 @@ describe 'nginx::resource::location' do { :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| @@ -346,11 +355,12 @@ describe 'nginx::resource::location' do { :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;', ], }, { @@ -386,10 +396,11 @@ describe 'nginx::resource::location' do { :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;', ], }, @@ -441,10 +452,11 @@ describe 'nginx::resource::location' do { :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;', ], }, diff --git a/spec/defines/resource_vhost_spec.rb b/spec/defines/resource_vhost_spec.rb index fe1d564..9d4ef3d 100644 --- a/spec/defines/resource_vhost_spec.rb +++ b/spec/defines/resource_vhost_spec.rb @@ -130,10 +130,11 @@ describe 'nginx::resource::vhost' do { :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;', ], }, @@ -218,11 +219,12 @@ describe 'nginx::resource::vhost' do { :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;', ], }, { @@ -383,6 +385,28 @@ describe 'nginx::resource::vhost' do :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', @@ -436,6 +460,17 @@ describe 'nginx::resource::vhost' do ' 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', diff --git a/templates/vhost/vhost_footer.erb b/templates/vhost/vhost_footer.erb index 3181d4b..97c0762 100644 --- a/templates/vhost/vhost_footer.erb +++ b/templates/vhost/vhost_footer.erb @@ -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 %>; diff --git a/templates/vhost/vhost_header.erb b/templates/vhost/vhost_header.erb index ca74f65..699aa97 100644 --- a/templates/vhost/vhost_header.erb +++ b/templates/vhost/vhost_header.erb @@ -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 %>; diff --git a/templates/vhost/vhost_location_alias.erb b/templates/vhost/vhost_location_alias.erb index 23d102b..d3fcdf9 100644 --- a/templates/vhost/vhost_location_alias.erb +++ b/templates/vhost/vhost_location_alias.erb @@ -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 -%> } diff --git a/templates/vhost/vhost_location_directory.erb b/templates/vhost/vhost_location_directory.erb index 36874ab..3f15a3f 100644 --- a/templates/vhost/vhost_location_directory.erb +++ b/templates/vhost/vhost_location_directory.erb @@ -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 %>; @@ -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 %> diff --git a/templates/vhost/vhost_location_empty.erb b/templates/vhost/vhost_location_empty.erb index aea023c..ac5c779 100644 --- a/templates/vhost/vhost_location_empty.erb +++ b/templates/vhost/vhost_location_empty.erb @@ -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 -%> } diff --git a/templates/vhost/vhost_location_fastcgi.erb b/templates/vhost/vhost_location_fastcgi.erb index 05d15fb..ced54eb 100644 --- a/templates/vhost/vhost_location_fastcgi.erb +++ b/templates/vhost/vhost_location_fastcgi.erb @@ -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 %> @@ -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 %> diff --git a/templates/vhost/vhost_location_proxy.erb b/templates/vhost/vhost_location_proxy.erb index d6420c3..e04cee9 100644 --- a/templates/vhost/vhost_location_proxy.erb +++ b/templates/vhost/vhost_location_proxy.erb @@ -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 %>; @@ -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 %> diff --git a/templates/vhost/vhost_location_stub_status.erb b/templates/vhost/vhost_location_stub_status.erb index 29e93df..932a1f7 100644 --- a/templates/vhost/vhost_location_stub_status.erb +++ b/templates/vhost/vhost_location_stub_status.erb @@ -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 -%> } diff --git a/templates/vhost/vhost_ssl_footer.erb b/templates/vhost/vhost_ssl_footer.erb index 217660d..df4a920 100644 --- a/templates/vhost/vhost_ssl_footer.erb +++ b/templates/vhost/vhost_ssl_footer.erb @@ -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 { diff --git a/templates/vhost/vhost_ssl_header.erb b/templates/vhost/vhost_ssl_header.erb index f5992ba..b4394fa 100644 --- a/templates/vhost/vhost_ssl_header.erb +++ b/templates/vhost/vhost_ssl_header.erb @@ -49,10 +49,14 @@ server { 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| -%> - <%= key %> <%= value %>; +<% Array(value).each do |sub| -%> + <%= key %> <%= sub %>; +<% 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| -%> - <%= key %> <%= value %>; +<% Array(value).each do |sub| -%> + <%= key %> <%= sub %>; +<% end %> <% end -%><% end -%> <% if @root -%> root <%= @root %>;