Merge pull request #352 from rabbitt/refactor-location

refactor locations to remove a bit of redundancy
This commit is contained in:
James Fryman 2014-06-24 09:23:13 -05:00
commit 4f38050148
15 changed files with 169 additions and 339 deletions

View file

@ -258,17 +258,17 @@ define nginx::resource::location (
# 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]) {
@ -286,7 +286,11 @@ define nginx::resource::location (
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}",
}
}
@ -299,7 +303,11 @@ define nginx::resource::location (
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}",
}
}

View file

@ -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 -%>
}

View file

@ -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 -%>

View file

@ -0,0 +1,4 @@
alias <%= @location_alias %>;
<% if defined? @autoindex -%>
autoindex <%= @autoindex %>;
<% end -%>

View file

@ -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 -%>

View file

@ -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 -%>

View file

@ -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 -%>

View file

@ -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 -%>

View file

@ -0,0 +1 @@
stub_status on;

View file

@ -1,56 +0,0 @@
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 -%>
alias <%= @location_alias %>;
<% if defined? @autoindex -%>
autoindex <%= @autoindex %>;
<% end -%>
<% 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 -%>
}

View file

@ -1,65 +0,0 @@
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 |value| -%>
<%= value %>
<% 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 -%>
<% 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 -%>
<% 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 -%>
}

View file

@ -1,13 +0,0 @@
location <%= @location %> {
<% 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 -%>
}

View file

@ -1,66 +0,0 @@
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 -%>
<% 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 -%>
<% 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 -%>
}

View file

@ -1,78 +0,0 @@
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 -%>
<% 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 -%>
<% 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 -%>
}

View file

@ -1,53 +0,0 @@
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 -%>
stub_status on;
<% 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 -%>
}