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

Add option http_cfg_prepend #870

Merged
merged 3 commits into from
Sep 26, 2016
Merged
Show file tree
Hide file tree
Changes from 2 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
7 changes: 7 additions & 0 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
$gzip_proxied = 'off',
$gzip_types = undef,
$gzip_vary = 'off',
$http_cfg_prepend = false,
$http_cfg_append = false,
$http_tcp_nodelay = 'on',
$http_tcp_nopush = 'off',
Expand Down Expand Up @@ -176,6 +177,12 @@
}
validate_string($proxy_buffers)
validate_string($proxy_buffer_size)
if ($http_cfg_prepend != false) {
if !(is_hash($http_cfg_prepend) or is_array($http_cfg_prepend)) {
fail('$http_cfg_prepend must be either a hash or array')
}
}

if ($http_cfg_append != false) {
if !(is_hash($http_cfg_append) or is_array($http_cfg_append)) {
fail('$http_cfg_append must be either a hash or array')
Expand Down
2 changes: 2 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
$fastcgi_cache_path = undef,
$fastcgi_cache_use_stale = undef,
$gzip = undef,
$http_cfg_prepend = undef,
$http_cfg_append = undef,
$http_tcp_nodelay = undef,
$http_tcp_nopush = undef,
Expand Down Expand Up @@ -245,6 +246,7 @@
fastcgi_cache_use_stale => $fastcgi_cache_use_stale,
gzip => $gzip,
http_access_log => $http_access_log,
http_cfg_prepend => $http_cfg_prepend,
http_cfg_append => $http_cfg_append,
http_tcp_nodelay => $http_tcp_nodelay,
http_tcp_nopush => $http_tcp_nopush,
Expand Down
28 changes: 28 additions & 0 deletions spec/classes/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,34 @@
value: false,
notmatch: %r{fastcgi_cache_use_stale}
},
{
title: 'should contain ordered appended directives from hash',
attr: 'http_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: 'http_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: 'http_cfg_prepend',
value: { 'test1' => ['test value 1', 'test value 2', 'test value 3'] },
match: [
' test1 test value 1;',
' test1 test value 2;'
]
},
{
title: 'should contain ordered appended directives from hash',
attr: 'http_cfg_append',
Expand Down
8 changes: 8 additions & 0 deletions templates/conf.d/nginx.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ events {
}

http {
<% if @http_cfg_append -%>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be checking for http_cfg_prepend

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<%- field_width = @http_cfg_prepend.inject(0) { |l,(k,v)| k.size > l ? k.size : l } -%>
<%- @http_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 -%>
include <%= @conf_dir %>/mime.types;
default_type application/octet-stream;
<% if @log_format -%>
Expand Down