Merge pull request #574 from railsdog/prachetasp/nginx_cfg_prepend

Prepend to the nginx config block
This commit is contained in:
James Fryman 2015-03-09 10:15:06 -05:00
commit 3322fb5a0e
3 changed files with 45 additions and 0 deletions

View file

@ -62,6 +62,7 @@ class nginx::config(
$multi_accept = 'off',
$names_hash_bucket_size = '64',
$names_hash_max_size = '512',
$nginx_cfg_prepend = false,
$proxy_buffers = '32 4k',
$proxy_buffer_size = '8k',
$proxy_cache_inactive = '20m',
@ -151,6 +152,12 @@ class nginx::config(
}
}
if ($nginx_cfg_prepend != false) {
if !(is_hash($nginx_cfg_prepend) or is_array($nginx_cfg_prepend)) {
fail('$nginx_cfg_prepend must be either a hash or array')
}
}
validate_string($nginx_error_log)
validate_string($http_access_log)
validate_string($proxy_headers_hash_bucket_size)

View file

@ -164,6 +164,35 @@ describe 'nginx::config' do
' test1 test value 2;',
],
},
{
:title => 'should contain ordered appended directives from hash',
:attr => 'nginx_cfg_prepend',
:value => { 'test1' => 'test value 1', 'test2' => 'test value 2', 'allow' => 'test value 3' },
:match => [
'allow test value 3;',
'test1 test value 1;',
'test2 test value 2;',
],
},
{
:title => 'should contain duplicate appended directives from list of hashes',
:attr => 'nginx_cfg_prepend',
:value => [[ 'allow', 'test value 1'], ['allow', 'test value 2' ]],
:match => [
'allow test value 1;',
'allow test value 2;',
],
},
{
:title => 'should contain duplicate appended directives from array values',
:attr => 'nginx_cfg_prepend',
:value => { 'test1' => ['test value 1', 'test value 2', 'test value 3'] },
:match => [
'test1 test value 1;',
'test1 test value 2;',
'test1 test value 3;',
],
},
{
:title => 'should set pid',
:attr => 'pid',

View file

@ -11,6 +11,15 @@ pid <%= @pid %>;
<% end -%>
error_log <%= @nginx_error_log %>;
<% if @nginx_cfg_prepend -%>
<%- field_width = @nginx_cfg_prepend.inject(0) { |l,(k,v)| k.size > l ? k.size : l } -%>
<%- @nginx_cfg_prepend.sort_by{|k,v| k}.each do |key,value| -%>
<%- Array(value).each do |asubvalue| -%>
<%= sprintf("%-*s", field_width, key) %> <%= asubvalue %>;
<%- end -%>
<%- end -%>
<% end -%>
events {
worker_connections <%= @worker_connections -%>;
<%- if @multi_accept == 'on' -%>