From 3027d9f35aa02cceb5ab7736763ca1c8e4bc8386 Mon Sep 17 00:00:00 2001 From: Matthew Haughton <3flex@users.noreply.github.com> Date: Mon, 13 Apr 2015 13:42:08 -0400 Subject: [PATCH] location: move auth_basic directives to header Allows setting these directives on any location: * auth_basic * auth_basic_user_file --- spec/defines/resource_location_spec.rb | 24 ++++++++++++------------ templates/vhost/location_header.erb | 6 ++++++ templates/vhost/locations/directory.erb | 9 --------- templates/vhost/locations/proxy.erb | 9 --------- 4 files changed, 18 insertions(+), 30 deletions(-) diff --git a/spec/defines/resource_location_spec.rb b/spec/defines/resource_location_spec.rb index aca02e549..ba8eb2abf 100644 --- a/spec/defines/resource_location_spec.rb +++ b/spec/defines/resource_location_spec.rb @@ -148,6 +148,18 @@ :value => [], :notmatch => /rewrite/ }, + { + :title => 'should set auth_basic', + :attr => 'auth_basic', + :value => 'value', + :match => ' auth_basic "value";', + }, + { + :title => 'should set auth_basic_user_file', + :attr => 'auth_basic_user_file', + :value => 'value', + :match => ' auth_basic_user_file value;', + }, ].each do |param| context "when #{param[:attr]} is #{param[:value]}" do let :default_params do { :location => 'location', :proxy => 'proxy_value', :vhost => 'vhost1' } end @@ -318,18 +330,6 @@ :value => ['name1','name2'], :match => ' index name1 name2;', }, - { - :title => 'should set auth_basic', - :attr => 'auth_basic', - :value => 'value', - :match => ' auth_basic "value";', - }, - { - :title => 'should set auth_basic_user_file', - :attr => 'auth_basic_user_file', - :value => 'value', - :match => ' auth_basic_user_file value;', - }, ].each do |param| context "when #{param[:attr]} is #{param[:value]}" do let :params do default_params.merge({ param[:attr].to_sym => param[:value] }) end diff --git a/templates/vhost/location_header.erb b/templates/vhost/location_header.erb index 023cd2388..64c5b93b7 100644 --- a/templates/vhost/location_header.erb +++ b/templates/vhost/location_header.erb @@ -19,6 +19,12 @@ deny <%= deny_rule %>; <%- end -%> <% end -%> +<% if @auth_basic -%> + auth_basic "<%= @auth_basic %>"; +<%- end %> +<%- if @auth_basic_user_file -%> + auth_basic_user_file <%= @auth_basic_user_file %>; +<% end -%> <% if @location_custom_cfg_prepend -%> <%- @location_custom_cfg_prepend.each do |key,value| -%> <%- if value.is_a?(Hash) -%> diff --git a/templates/vhost/locations/directory.erb b/templates/vhost/locations/directory.erb index 95c973763..60850a0c1 100644 --- a/templates/vhost/locations/directory.erb +++ b/templates/vhost/locations/directory.erb @@ -11,12 +11,3 @@ <% if @try_files -%> try_files<% @try_files.each do |try| -%> <%= try %><% end -%>; <% end -%> -<% if instance_variables.any? { |iv| iv.to_s.include? 'auth_basic' } -%> - - <%- if @auth_basic -%> - auth_basic "<%= @auth_basic %>"; - <%- end -%> - <%- if defined? @auth_basic_user_file -%> - auth_basic_user_file <%= @auth_basic_user_file %>; - <%- end -%> -<% end -%> \ No newline at end of file diff --git a/templates/vhost/locations/proxy.erb b/templates/vhost/locations/proxy.erb index 971a0abd4..1687417bf 100644 --- a/templates/vhost/locations/proxy.erb +++ b/templates/vhost/locations/proxy.erb @@ -21,12 +21,3 @@ <% if @proxy_cache_valid -%> proxy_cache_valid <%= @proxy_cache_valid %>; <% end -%> -<% if instance_variables.any? { |iv| iv.to_s.include? 'auth_basic' } -%> - - <%- if @auth_basic -%> - auth_basic "<%= @auth_basic %>"; - <%- end -%> - <%- if defined? @auth_basic_user_file -%> - auth_basic_user_file <%= @auth_basic_user_file %>; - <%- end -%> -<% end -%>