Skip to content

Commit

Permalink
Merge pull request #642 from jd-daniels/master
Browse files Browse the repository at this point in the history
Allow better control of http level proxy directives
  • Loading branch information
3flex committed Jun 15, 2015
2 parents a3644ca + 310ed82 commit 110b8bb
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 59 deletions.
3 changes: 1 addition & 2 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,7 @@
}

file { "${conf_dir}/conf.d/proxy.conf":
ensure => file,
content => template($proxy_conf_template),
ensure => absent,
}

file { "${conf_dir}/conf.d/default.conf":
Expand Down
53 changes: 11 additions & 42 deletions spec/classes/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@
:group => 'root',
:mode => '0644'
)}
it { is_expected.to contain_file("/etc/nginx/conf.d/proxy.conf").with(
:ensure => 'file',
:owner => 'root',
:group => 'root',
:mode => '0644'
)}
it { is_expected.to contain_file("/tmp/nginx.d").with(
:ensure => 'absent',
:purge => true,
Expand Down Expand Up @@ -379,48 +373,23 @@
:value => false,
:notmatch => /mail/,
},
].each do |param|
context "when #{param[:attr]} is #{param[:value]}" do
let :params do { param[:attr].to_sym => param[:value] } end

it { is_expected.to contain_file("/etc/nginx/nginx.conf").with_mode('0644') }
it param[:title] do
matches = Array(param[:match])

if matches.all? { |m| m.is_a? Regexp }
matches.each { |item| is_expected.to contain_file('/etc/nginx/nginx.conf').with_content(item) }
else
lines = catalogue.resource('file', '/etc/nginx/nginx.conf').send(:parameters)[:content].split("\n")
expect(lines & Array(param[:match])).to eq(Array(param[:match]))
end

Array(param[:notmatch]).each do |item|
is_expected.to contain_file("/etc/nginx/nginx.conf").without_content(item)
end
end
end
end
end

describe "proxy.conf template content" do
[
{
:title => 'should set proxy_buffers',
:attr => 'proxy_buffers',
:value => '50 5k',
:match => 'proxy_buffers 50 5k;',
:match => ' proxy_buffers 50 5k;',
},
{
:title => 'should set proxy_buffer_size',
:attr => 'proxy_buffer_size',
:value => '2k',
:match => 'proxy_buffer_size 2k;',
:match => ' proxy_buffer_size 2k;',
},
{
:title => 'should set proxy_http_version',
:attr => 'proxy_http_version',
:value => '1.1',
:match => 'proxy_http_version 1.1;',
:match => ' proxy_http_version 1.1;',
},
{
:title => 'should not set proxy_http_version',
Expand All @@ -433,39 +402,39 @@
:attr => 'proxy_set_header',
:value => ['header1','header2'],
:match => [
'proxy_set_header header1;',
'proxy_set_header header2;',
' proxy_set_header header1;',
' proxy_set_header header2;',
],
},
{
:title => 'should set client_body_temp_path',
:attr => 'client_body_temp_path',
:value => '/path/to/body_temp',
:match => 'client_body_temp_path /path/to/body_temp;',
:match => ' client_body_temp_path /path/to/body_temp;',
},
{
:title => 'should set proxy_temp_path',
:attr => 'proxy_temp_path',
:value => '/path/to/proxy_temp',
:match => 'proxy_temp_path /path/to/proxy_temp;',
:match => ' proxy_temp_path /path/to/proxy_temp;',
},
].each do |param|
context "when #{param[:attr]} is #{param[:value]}" do
let :params do { param[:attr].to_sym => param[:value] } end

it { is_expected.to contain_file("/etc/nginx/conf.d/proxy.conf").with_mode('0644') }
it { is_expected.to contain_file("/etc/nginx/nginx.conf").with_mode('0644') }
it param[:title] do
matches = Array(param[:match])

if matches.all? { |m| m.is_a? Regexp }
matches.each { |item| is_expected.to contain_file('/etc/nginx/conf.d/proxy.conf').with_content(item) }
matches.each { |item| is_expected.to contain_file('/etc/nginx/nginx.conf').with_content(item) }
else
lines = catalogue.resource('file', '/etc/nginx/conf.d/proxy.conf').send(:parameters)[:content].split("\n")
lines = catalogue.resource('file', '/etc/nginx/nginx.conf').send(:parameters)[:content].split("\n")
expect(lines & Array(param[:match])).to eq(Array(param[:match]))
end

Array(param[:notmatch]).each do |item|
is_expected.to contain_file("/etc/nginx/conf.d/proxy.conf").without_content(item)
is_expected.to contain_file("/etc/nginx/nginx.conf").without_content(item)
end
end
end
Expand Down
39 changes: 39 additions & 0 deletions templates/conf.d/nginx.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,45 @@ http {
gzip_disable "MSIE [1-6]\.(?!.*SV1)";

<% end -%>
<% if @client_body_temp_path -%>
client_body_temp_path <%= @client_body_temp_path %>;
<% end -%>
<% if @client_max_body_size -%>
client_max_body_size <%= @client_max_body_size %>;
<% end -%>
<% if @client_body_buffer_size -%>
client_body_buffer_size <%= @client_body_buffer_size %>;
<% end -%>
<% if @proxy_redirect -%>
proxy_redirect <%= @proxy_redirect %>;
<% end -%>
<% if @proxy_temp_path -%>
proxy_temp_path <%= @proxy_temp_path %>;
<% end -%>
<% if @proxy_connect_timeout -%>
proxy_connect_timeout <%= @proxy_connect_timeout %>;
<% end -%>
<% if @proxy_send_timeout -%>
proxy_send_timeout <%= @proxy_send_timeout %>;
<% end -%>
<% if @proxy_read_timeout -%>
proxy_read_timeout <%= @proxy_read_timeout %>;
<% end -%>
<% if @proxy_buffers -%>
proxy_buffers <%= @proxy_buffers %>;
<% end -%>
<% if @proxy_buffer_size -%>
proxy_buffer_size <%= @proxy_buffer_size %>;
<% end -%>
<% if @proxy_http_version -%>
proxy_http_version <%= @proxy_http_version %>;
<% end -%>
<% @proxy_set_header.each do |header| -%>
proxy_set_header <%= header %>;
<% end -%>
<% if @proxy_headers_hash_bucket_size -%>
proxy_headers_hash_bucket_size <%= @proxy_headers_hash_bucket_size %>;
<% end -%>
<% if @proxy_cache_path -%>
proxy_cache_path <%= @proxy_cache_path %> levels=<%= @proxy_cache_levels %> keys_zone=<%= @proxy_cache_keys_zone %> max_size=<%= @proxy_cache_max_size %> inactive=<%= @proxy_cache_inactive %>;

Expand Down
15 changes: 0 additions & 15 deletions templates/conf.d/proxy.conf.erb

This file was deleted.

0 comments on commit 110b8bb

Please sign in to comment.