Skip to content

Commit

Permalink
Merge pull request voxpupuli#926 from darken99/uwsgi_param
Browse files Browse the repository at this point in the history
uwsgi: allow custom uwsgi_param directives
  • Loading branch information
wyardley committed Oct 17, 2016
2 parents b8287f2 + 514e58e commit 943df7b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
16 changes: 16 additions & 0 deletions manifests/resource/location.pp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
# [*fastcgi_split_path*] - Allows settings of fastcgi_split_path_info so
# that you can split the script_name and path_info via regex
# [*uwsgi*] - location of uwsgi (host:port)
# [*uwsgi_param*] - Set additional custom uwsgi_params
# [*uwsgi_params*] - optional alternative uwsgi_params file to use
# [*uwsgi_read_timeout*] - optional value for uwsgi_read_timeout
# [*ssl*] - Indicates whether to setup SSL bindings for
Expand Down Expand Up @@ -137,6 +138,17 @@
# 'APP_ENV' => 'local',
# }
# }
#
# Add Custom uwsgi_params
# nginx::resource::location { 'test2.local-bob':
# ensure => present,
# www_root => '/var/www/bob',
# location => '/bob',
# vhost => 'test2.local',
# uwsgi_param => {
# 'APP_ENV' => 'local',
# }
# }

define nginx::resource::location (
$ensure = present,
Expand All @@ -162,6 +174,7 @@
$fastcgi_script = undef,
$fastcgi_split_path = undef,
$uwsgi = undef,
$uwsgi_param = undef,
$uwsgi_params = "${nginx::config::conf_dir}/uwsgi_params",
$uwsgi_read_timeout = undef,
$ssl = false,
Expand Down Expand Up @@ -247,6 +260,9 @@
if ($uwsgi != undef) {
validate_string($uwsgi)
}
if ($uwsgi_param != undef) {
validate_hash($uwsgi_param)
}
validate_string($uwsgi_params)
if ($uwsgi_read_timeout != undef) {
validate_string($uwsgi_read_timeout)
Expand Down
25 changes: 25 additions & 0 deletions spec/defines/resource_location_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,31 @@
end
end
end

context "when uwsgi_param is {'CUSTOM_PARAM' => 'value'}" do
let(:params) { default_params.merge(uwsgi_param: { 'CUSTOM_PARAM' => 'value', 'CUSTOM_PARAM2' => 'value2' }) }
it 'sets uwsgi_param' do
should contain_concat__fragment('vhost1-500-' + Digest::MD5.hexdigest(params[:location].to_s)).
with_content(%r{uwsgi_param\s+CUSTOM_PARAM\s+value;}).
with_content(%r{uwsgi_param\s+CUSTOM_PARAM2\s+value2;})
end
end

context 'when uwsgi_param is {\'HTTP_PROXY\' => ""}' do
let(:params) { default_params.merge(uwsgi_param: { 'HTTP_PROXY' => '""' }) }
it 'sets uwsgi_param' do
should contain_concat__fragment('vhost1-500-' + Digest::MD5.hexdigest(params[:location].to_s)).
with_content(%r{uwsgi_param\s+HTTP_PROXY\s+"";})
end
end

context 'when uwsgi_param is not set' do
let(:params) { default_params }
it 'does not set uwsgi_param' do
should contain_concat__fragment('vhost1-500-' + Digest::MD5.hexdigest(params[:location].to_s)).
without_content(%r{^\s+uwsgi_param\s+})
end
end
end

describe 'vhost_location_proxy template content' do
Expand Down
6 changes: 6 additions & 0 deletions templates/vhost/locations/uwsgi.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
<% end -%>
include <%= @uwsgi_params %>;
uwsgi_pass <%= @uwsgi %>;
<% if @uwsgi_param -%>
<%- field_width = @uwsgi_param.inject(0) { |l,(k,v)| k.size > l ? k.size : l } -%>
<%- @uwsgi_param.sort_by {|k,v| k}.each do |key, val| -%>
uwsgi_param <%= sprintf("%-*s", field_width, key) %> <%= val %>;
<%- end -%>
<% end -%>
<% if @uwsgi_read_timeout-%>
uwsgi_read_timeout <%= @uwsgi_read_timeout %>;
<% end -%>

0 comments on commit 943df7b

Please sign in to comment.