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 of arrays and keys in custom_cfg_[prepend,append].. #273

Closed
wants to merge 15 commits 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
127 changes: 97 additions & 30 deletions spec/defines/resource_location_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,17 @@
{
: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',
'test4' => { 'subtest1' => ['"sub test value1a"', '"sub test value 1b"'],
'subtest2' => '"sub test value2"' } },
: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;',
' test4 subtest1 "sub test value1a";',
' test4 subtest1 "sub test value1b";',
' test4 subtest2 "sub test value2";',
],
},
{
Expand Down Expand Up @@ -90,11 +96,17 @@
{
: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',
'test4' => { 'subtest1' => ['"sub test value1a"', '"sub test value 1b"'],
'subtest2' => '"sub test value2"' } },
:match => [
' allow test value 3;',
' test1 test value 1;',
' test1 test value 1a;',
' test1 test value 1b;',
' test2 test value 2;',
' test4 subtest1 "sub test value1a";',
' test4 subtest1 "sub test value1b";',
' test4 subtest2 "sub test value2";',
],
},
{
Expand Down Expand Up @@ -157,11 +169,17 @@
{
: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',
'test4' => { 'subtest1' => ['"sub test value1a"', '"sub test value 1b"'],
'subtest2' => '"sub test value2"' } },
:match => [
' allow test value 3;',
' test1 test value 1;',
' test1 test value 1a;',
' test1 test value 1b;',
' test2 test value 2;',
' test4 subtest1 "sub test value1a";',
' test4 subtest1 "sub test value1b";',
' test4 subtest2 "sub test value2";',
],
},
{
Expand All @@ -173,11 +191,18 @@
{
: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'],
'test4' => { 'subtest1' => ['"sub test value1a"', '"sub test value 1b"'],
'subtest2' => '"sub test value2"' } },
: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;',
' test4 subtest1 "sub test value1a";',
' test4 subtest1 "sub test value1b";',
' test4 subtest2 "sub test value2";',
],
},
].each do |param|
Expand Down Expand Up @@ -208,21 +233,33 @@
{
: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',
'test4' => { 'subtest1' => ['"sub test value1a"', '"sub test value 1b"'],
'subtest2' => '"sub test value2"' } },
: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;',
' test4 subtest1 "sub test value1a";',
' test4 subtest1 "sub test value1b";',
' test4 subtest2 "sub test value2";',
],
},
{
: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',
'test4' => { 'subtest1' => ['"sub test value1a"', '"sub test value 1b"'],
'subtest2' => '"sub test value2"' } },
: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;',
' test4 subtest1 "sub test value1a";',
' test4 subtest1 "sub test value1b";',
' test4 subtest2 "sub test value2";',
],
},
].each do |param|
Expand Down Expand Up @@ -253,11 +290,17 @@
{
: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',
'test4' => { 'subtest1' => ['"sub test value1a"', '"sub test value 1b"'],
'subtest2' => '"sub test value2"' } },
: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;',
' test4 subtest1 "sub test value1a";',
' test4 subtest1 "sub test value1b";',
' test4 subtest2 "sub test value2";',
],
},
{
Expand Down Expand Up @@ -299,11 +342,17 @@
{
: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',
'test4' => { 'subtest1' => ['"sub test value1a"', '"sub test value 1b"'],
'subtest2' => '"sub test value2"' } },
:match => [
' allow test value 3;',
' test1 test value 1;',
' test2 test value 2;',
' test2 test value 2a;',
' test2 test value 2b;',
' test4 subtest1 "sub test value1a";',
' test4 subtest1 "sub test value1b";',
' test4 subtest2 "sub test value2";',
],
},
].each do |param|
Expand Down Expand Up @@ -346,11 +395,17 @@
{
: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',
'test4' => { 'subtest1' => ['"sub test value1a"', '"sub test value 1b"'],
'subtest2' => '"sub test value2"' } },
:match => [
' allow test value 3;',
' test1 test value 1;',
' test2 test value 2;',
' test2 test value 2a;',
' test2 test value 2b;',
' test4 subtest1 "sub test value1a";',
' test4 subtest1 "sub test value1b";',
' test4 subtest2 "sub test value2";',
],
},
{
Expand Down Expand Up @@ -386,11 +441,17 @@
{
: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',
'test4' => { 'subtest1' => ['"sub test value1a"', '"sub test value 1b"'],
'subtest2' => '"sub test value2"' } },
:match => [
' allow test value 3;',
' test1 test value 1;',
' test1 test value 1a;',
' test1 test value 1b;',
' test2 test value 2;',
' test4 subtest1 "sub test value1a";',
' test4 subtest1 "sub test value1b";',
' test4 subtest2 "sub test value2";',
],
},
{
Expand Down Expand Up @@ -441,11 +502,17 @@
{
: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',
'test4' => { 'subtest1' => ['"sub test value1a"', '"sub test value 1b"'],
'subtest2' => '"sub test value2"' } },
:match => [
' allow test value 3;',
' test1 test value 1;',
' test1 test value 1a;',
' test1 test value 1b;',
' test2 test value 2;',
' test4 subtest1 "sub test value1a";',
' test4 subtest1 "sub test value1b";',
' test4 subtest2 "sub test value2";',
],
},
].each do |param|
Expand Down
8 changes: 8 additions & 0 deletions spec/defines/resource_upstream_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,19 @@
'test3' => 'test value 3',
'test1' => 'test value 1',
'test2' => 'test value 2',
'test4' => ['test value 1', 'test value 2'],
'test5' => {'subkey1' => 'subvalue1'},
'test6' => {'subkey1' => ['subvalue1', 'subvalue2']},
},
:match => [
' test1 test value 1;',
' test2 test value 2;',
' test3 test value 3;',
' test4 test value 1;',
' test4 test value 2;',
' test5 subkey1 subvalue1;',
' test6 subkey1 subvalue1;',
' test6 subkey1 subvalue2;',
],
},
{
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
10 changes: 9 additions & 1 deletion templates/conf.d/upstream.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
upstream <%= @name %> {
<% if @upstream_cfg_prepend -%><% @upstream_cfg_prepend.sort_by{|k,v| k}.each do |key,value| %>
<%= key %> <%= value %>;
<% if value.is_a?(Hash) -%><% value.each do |subkey,subvalue| -%>
<% Array(subvalue).each do |asubvalue| -%>
<%= key %> <%= subkey %> <%= asubvalue %>;
<% end -%>
<% end -%><% else -%>
<% Array(value).each do |asubvalue| -%>
<%= key %> <%= asubvalue %>;
<% end -%>
<% end -%>
<% end -%><% end -%>
<% @members.each do |i| %>
server <%= i %> fail_timeout=<%= @upstream_fail_timeout %>;<% end %>
Expand Down
11 changes: 9 additions & 2 deletions templates/vhost/vhost_footer.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,21 @@ 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 %>;
<% if value.is_a?(Hash) -%><% value.each do |subkey,subvalue| -%>
<% Array(subvalue).each do |asubvalue| -%>
<%= key %> <%= subkey %> <%= asubvalue %>;
<% end -%>
<% end -%><% else -%>
<% Array(value).each do |asubvalue| -%>
<%= key %> <%= asubvalue %>;
<% end -%>
<% end -%>
<% end -%><% end -%>
}
<% if @rewrite_www_to_non_www -%>
server {
listen <%= @listen_ip %>:<%= @listen_port %>;
server_name www.<%= @name.gsub(/^www\./, '') %>;
rewrite ^ http://<%= @name.gsub(/^www\./, '') %>$uri permanent;
}
<% end %>
<% end -%>
10 changes: 9 additions & 1 deletion templates/vhost/vhost_header.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@ 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 %>;
<% if value.is_a?(Hash) -%><% value.each do |subkey,subvalue| -%>
<% Array(subvalue).each do |asubvalue| -%>
<%= key %> <%= subkey %> <%= asubvalue %>;
<% end -%>
<% end -%><% else -%>
<% Array(value).each do |asubvalue| -%>
<%= key %> <%= asubvalue %>;
<% end -%>
<% end -%>
<% end -%><% end -%>
<% if @root -%>
root <%= @root %>;
Expand Down
Loading