Skip to content

Commit

Permalink
Merge pull request #352 from rabbitt/refactor-location
Browse files Browse the repository at this point in the history
refactor locations to remove a bit of redundancy
  • Loading branch information
James Fryman committed Jun 24, 2014
2 parents b0a1df3 + 3330310 commit 4f38050
Show file tree
Hide file tree
Showing 15 changed files with 169 additions and 339 deletions.
24 changes: 16 additions & 8 deletions manifests/resource/location.pp
Original file line number Diff line number Diff line change
Expand Up @@ -258,17 +258,17 @@

# Use proxy or fastcgi template if $proxy is defined, otherwise use directory template.
if ($proxy != undef) {
$content_real = template('nginx/vhost/vhost_location_proxy.erb')
$content_real = template('nginx/vhost/locations/proxy.erb')
} elsif ($location_alias != undef) {
$content_real = template('nginx/vhost/vhost_location_alias.erb')
$content_real = template('nginx/vhost/locations/alias.erb')
} elsif ($stub_status != undef) {
$content_real = template('nginx/vhost/vhost_location_stub_status.erb')
$content_real = template('nginx/vhost/locations/stub_status.erb')
} elsif ($fastcgi != undef) {
$content_real = template('nginx/vhost/vhost_location_fastcgi.erb')
$content_real = template('nginx/vhost/locations/fastcgi.erb')
} elsif ($www_root != undef) {
$content_real = template('nginx/vhost/vhost_location_directory.erb')
$content_real = template('nginx/vhost/locations/directory.erb')
} else {
$content_real = template('nginx/vhost/vhost_location_empty.erb')
$content_real = template('nginx/vhost/locations/empty.erb')
}

if $fastcgi != undef and !defined(File[$fastcgi_params]) {
Expand All @@ -286,7 +286,11 @@
concat::fragment { "${tmpFile}":
ensure => present,
target => $config_file,
content => $content_real,
content => join([
template('nginx/vhost/location_header.erb'),
$content_real,
template('nginx/vhost/location_footer.erb')
], ''),
order => "${priority}",
}
}
Expand All @@ -299,7 +303,11 @@
concat::fragment {"${sslTmpFile}":
ensure => present,
target => $config_file,
content => $content_real,
content => join([
template('nginx/vhost/location_header.erb'),
$content_real,
template('nginx/vhost/location_footer.erb')
], ''),
order => "${ssl_priority}",
}
}
Expand Down
31 changes: 31 additions & 0 deletions templates/vhost/location_footer.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<% if @location_cfg_append -%>
<%- @location_cfg_append.sort_by {|k,v| k}.each do |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 @location_custom_cfg_append -%>
<%- @location_custom_cfg_append.each do |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 -%>
}
41 changes: 41 additions & 0 deletions templates/vhost/location_header.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
location <%= @location %> {
<% if @location_allow -%>
<%- @location_allow.each do |allow_rule| -%>
allow <%= allow_rule %>;
<%- end -%>
<% end -%>
<% if @location_deny -%>
<%- @location_deny.each do |deny_rule| -%>
deny <%= deny_rule %>;
<%- end -%>
<% end -%>
<% if @location_custom_cfg_prepend -%>
<%- @location_custom_cfg_prepend.each do |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 @location_cfg_prepend -%>
<%- @location_cfg_prepend.sort_by {|k,v| k}.each do |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 -%>
4 changes: 4 additions & 0 deletions templates/vhost/locations/alias.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
alias <%= @location_alias %>;
<% if defined? @autoindex -%>
autoindex <%= @autoindex %>;
<% end -%>
21 changes: 21 additions & 0 deletions templates/vhost/locations/directory.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<% if defined? @www_root -%>
root <%= @www_root %>;
<% end -%>
<% if @try_files -%>
try_files<% @try_files.each do |try| -%> <%= try %><% end -%>;
<% end -%>
<% if defined? @autoindex -%>
autoindex <%= @autoindex %>;
<% end -%>
<% if @index_files.count > 0 -%>
index <% Array(@index_files).each do |i| %> <%= i %><% end %>;
<% end -%>
<% @rewrite_rules.each do |rewrite_rule| -%>
rewrite <%= rewrite_rule %>;
<% end -%>
<% if defined? @auth_basic -%>
auth_basic "<%= @auth_basic %>";
<% end -%>
<% if defined? @auth_basic_user_file -%>
auth_basic_user_file <%= @auth_basic_user_file %>;
<% end -%>
15 changes: 15 additions & 0 deletions templates/vhost/locations/empty.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<% if @location_custom_cfg -%>
<%- @location_custom_cfg.sort_by {|k,v| k}.each do |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 -%>
14 changes: 14 additions & 0 deletions templates/vhost/locations/fastcgi.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<% if defined? @www_root -%>
root <%= @www_root %>;
<% end -%>
<% if @fastcgi_split_path -%>
fastcgi_split_path_info <%= @fastcgi_split_path %>;
<% end -%>
<% if @try_files -%>
try_files<% @try_files.each do |try| -%> <%= try %><% end -%>;
<% end -%>
include <%= @fastcgi_params %>;
fastcgi_pass <%= @fastcgi %>;
<% if defined? @fastcgi_script %>
fastcgi_param SCRIPT_FILENAME <%= @fastcgi_script %>;
<% end -%>
26 changes: 26 additions & 0 deletions templates/vhost/locations/proxy.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<% if @proxy_cache -%>
proxy_cache <%= @proxy_cache %>;
proxy_cache_valid <%= @proxy_cache_valid %>;
<% end -%>
proxy_pass <%= @proxy %>;
proxy_read_timeout <%= @proxy_read_timeout %>;
proxy_connect_timeout <%= @proxy_connect_timeout %>;
proxy_redirect <%= @proxy_redirect %>;
<% @proxy_set_header.each do |header| -%>
proxy_set_header <%= header %>;
<% end -%>
<% if @proxy_method -%>
proxy_method <%= @proxy_method %>;
<% end -%>
<% if @proxy_set_body -%>
proxy_set_body <%= @proxy_set_body %>;
<% end -%>
<% @rewrite_rules.each do |rewrite_rule| -%>
rewrite <%= rewrite_rule %>;
<% end -%>
<% if defined? @auth_basic -%>
auth_basic "<%= @auth_basic %>";
<% end -%>
<% if defined? @auth_basic_user_file -%>
auth_basic_user_file <%= @auth_basic_user_file %>;
<% end -%>
1 change: 1 addition & 0 deletions templates/vhost/locations/stub_status.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
stub_status on;
56 changes: 0 additions & 56 deletions templates/vhost/vhost_location_alias.erb

This file was deleted.

65 changes: 0 additions & 65 deletions templates/vhost/vhost_location_directory.erb

This file was deleted.

13 changes: 0 additions & 13 deletions templates/vhost/vhost_location_empty.erb

This file was deleted.

Loading

0 comments on commit 4f38050

Please sign in to comment.