From 16d76a9c15958610ef30ee11655a71c2c15e27b2 Mon Sep 17 00:00:00 2001 From: Jacob McCoy Wade Date: Tue, 2 Jun 2015 10:48:57 -0700 Subject: [PATCH 1/6] Adding proxy_cache_path_hash flag in order to use either a string or hash value --- manifests/config.pp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/manifests/config.pp b/manifests/config.pp index af05844f4..f8ae56526 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -69,6 +69,7 @@ $proxy_cache_keys_zone = 'd2:100m', $proxy_cache_levels = '1', $proxy_cache_max_size = '500m', + $proxy_cache_path_hash = 'string', $proxy_cache_path = false, $proxy_connect_timeout = '90', $proxy_headers_hash_bucket_size = '64', @@ -113,7 +114,10 @@ } validate_bool($confd_purge) validate_bool($vhost_purge) - if ($proxy_cache_path != false) { + if ($proxy_cache_path_hash != 'string') { + validate_hash($proxy_cache_path) + } + elsif ($proxy_cache_path != false) { validate_string($proxy_cache_path) } validate_re($proxy_cache_levels, '^[12](:[12])*$') From f92b895cb9047436c1da290711d1717fe6dd91a5 Mon Sep 17 00:00:00 2001 From: Jacob McCoy Wade Date: Tue, 2 Jun 2015 10:50:11 -0700 Subject: [PATCH 2/6] Adding a version of proxy_cache_path that will work with either a hash value or a string value --- templates/conf.d/nginx.conf.erb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/templates/conf.d/nginx.conf.erb b/templates/conf.d/nginx.conf.erb index 4838a90f3..7cb0815dc 100644 --- a/templates/conf.d/nginx.conf.erb +++ b/templates/conf.d/nginx.conf.erb @@ -64,9 +64,12 @@ http { gzip_disable "MSIE [1-6]\.(?!.*SV1)"; <% end -%> -<% if @proxy_cache_path -%> +<% if @proxy_cache_path_hash != 'string' -%> +<% @proxy_cache_path.sort_by{|k,v| k}.each do |key,value| -%> + proxy_cache_path <%= key %> keys_zone=<%= value %> levels=<%= @proxy_cache_levels %> max_size=<%= @proxy_cache_max_size %> inactive=<%= @proxy_cache_inactive %>; +<% end -%> +<% elsif @proxy_cache_path -%> proxy_cache_path <%= @proxy_cache_path %> levels=<%= @proxy_cache_levels %> keys_zone=<%= @proxy_cache_keys_zone %> max_size=<%= @proxy_cache_max_size %> inactive=<%= @proxy_cache_inactive %>; - <% end -%> <% if @fastcgi_cache_path -%> fastcgi_cache_path <%= @fastcgi_cache_path %> levels=<%= @fastcgi_cache_levels %> keys_zone=<%= @fastcgi_cache_keys_zone %> max_size=<%= @fastcgi_cache_max_size %> inactive=<%= @fastcgi_cache_inactive %>; From 876713f895175029686a1f16faa18d817d00518e Mon Sep 17 00:00:00 2001 From: Jacob McCoy Wade Date: Tue, 2 Jun 2015 10:48:57 -0700 Subject: [PATCH 3/6] Adding ability to specify multiple proxy_cache_path entries with unique proxy_cache_keys_zone values --- manifests/config.pp | 6 +++++- templates/conf.d/nginx.conf.erb | 7 +++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/manifests/config.pp b/manifests/config.pp index af05844f4..f8ae56526 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -69,6 +69,7 @@ $proxy_cache_keys_zone = 'd2:100m', $proxy_cache_levels = '1', $proxy_cache_max_size = '500m', + $proxy_cache_path_hash = 'string', $proxy_cache_path = false, $proxy_connect_timeout = '90', $proxy_headers_hash_bucket_size = '64', @@ -113,7 +114,10 @@ } validate_bool($confd_purge) validate_bool($vhost_purge) - if ($proxy_cache_path != false) { + if ($proxy_cache_path_hash != 'string') { + validate_hash($proxy_cache_path) + } + elsif ($proxy_cache_path != false) { validate_string($proxy_cache_path) } validate_re($proxy_cache_levels, '^[12](:[12])*$') diff --git a/templates/conf.d/nginx.conf.erb b/templates/conf.d/nginx.conf.erb index 4838a90f3..7cb0815dc 100644 --- a/templates/conf.d/nginx.conf.erb +++ b/templates/conf.d/nginx.conf.erb @@ -64,9 +64,12 @@ http { gzip_disable "MSIE [1-6]\.(?!.*SV1)"; <% end -%> -<% if @proxy_cache_path -%> +<% if @proxy_cache_path_hash != 'string' -%> +<% @proxy_cache_path.sort_by{|k,v| k}.each do |key,value| -%> + proxy_cache_path <%= key %> keys_zone=<%= value %> levels=<%= @proxy_cache_levels %> max_size=<%= @proxy_cache_max_size %> inactive=<%= @proxy_cache_inactive %>; +<% end -%> +<% elsif @proxy_cache_path -%> proxy_cache_path <%= @proxy_cache_path %> levels=<%= @proxy_cache_levels %> keys_zone=<%= @proxy_cache_keys_zone %> max_size=<%= @proxy_cache_max_size %> inactive=<%= @proxy_cache_inactive %>; - <% end -%> <% if @fastcgi_cache_path -%> fastcgi_cache_path <%= @fastcgi_cache_path %> levels=<%= @fastcgi_cache_levels %> keys_zone=<%= @fastcgi_cache_keys_zone %> max_size=<%= @fastcgi_cache_max_size %> inactive=<%= @fastcgi_cache_inactive %>; From 24d8d4d5c5f251b798095781546e138574498d5e Mon Sep 17 00:00:00 2001 From: Matthew Haughton <3flex@users.noreply.github.com> Date: Mon, 1 Jun 2015 12:02:26 -0400 Subject: [PATCH 4/6] metadata: allow for puppetlabs-concat 2.0.0 --- metadata.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metadata.json b/metadata.json index 8a062fc06..9afb10617 100644 --- a/metadata.json +++ b/metadata.json @@ -10,7 +10,7 @@ "dependencies": [ {"name":"puppetlabs/stdlib","version_requirement":">= 4.2.0 <5.0.0"}, {"name":"puppetlabs/apt","version_requirement":">= 1.8.0 <3.0.0"}, - {"name":"puppetlabs/concat","version_requirement":">= 1.1.1 <2.0.0"} + {"name":"puppetlabs/concat","version_requirement":">= 1.1.1 <3.0.0"} ], "requirements": [ { From 4d93e049ca2c3389daf718af56ff66999ece2c55 Mon Sep 17 00:00:00 2001 From: Jacob McCoy Wade Date: Fri, 29 May 2015 14:21:34 -0700 Subject: [PATCH 5/6] Adding ability to add proxy_cache_use_stale and proxy_cache_key within a location resource Adding spec tests for proxy_cache_key and proxy_cache_use_stale --- manifests/resource/location.pp | 12 ++++++++++++ manifests/resource/vhost.pp | 14 ++++++++++++++ spec/defines/resource_location_spec.rb | 14 +++++++++++++- templates/vhost/locations/proxy.erb | 6 ++++++ 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/manifests/resource/location.pp b/manifests/resource/location.pp index 3b5313a72..6c8f3607a 100644 --- a/manifests/resource/location.pp +++ b/manifests/resource/location.pp @@ -70,6 +70,10 @@ # [*option*] - Reserved for future use # [*proxy_cache*] - This directive sets name of zone for caching. # The same zone can be used in multiple places. +# [*proxy_cache_key*] - Override the default proxy_cache_key of +# $scheme$proxy_host$request_uri +# [*proxy_cache_use_stale*] - Override the default proxy_cache_use_stale value +# of off. # [*proxy_cache_valid*] - This directive sets the time for caching # different replies. # [*proxy_method*] - If defined, overrides the HTTP method of the @@ -166,6 +170,8 @@ $include = undef, $try_files = undef, $proxy_cache = false, + $proxy_cache_key = undef, + $proxy_cache_use_stale = undef, $proxy_cache_valid = false, $proxy_method = undef, $proxy_set_body = undef, @@ -277,6 +283,12 @@ if ($proxy_cache != false) { validate_string($proxy_cache) } + if ($proxy_cache_key != undef) { + validate_string($proxy_cache_key) + } + if ($proxy_cache_use_stale != undef) { + validate_string($proxy_cache_use_stale) + } if ($proxy_cache_valid != false) { validate_string($proxy_cache_valid) } diff --git a/manifests/resource/vhost.pp b/manifests/resource/vhost.pp index 8e9a94cc8..95a55f53d 100644 --- a/manifests/resource/vhost.pp +++ b/manifests/resource/vhost.pp @@ -85,6 +85,10 @@ # checked as an array. Cannot be used in conjuction with $proxy. # [*proxy_cache*] - This directive sets name of zone for caching. # The same zone can be used in multiple places. +# [*proxy_cache_key*] - Override the default proxy_cache_key of +# $scheme$proxy_host$request_uri +# [*proxy_cache_use_stale*] - Override the default proxy_cache_use_stale value +# of off. # [*proxy_cache_valid*] - This directive sets the time for caching # different replies. # [*proxy_method*] - If defined, overrides the HTTP method of the @@ -193,6 +197,8 @@ $proxy_connect_timeout = $::nginx::config::proxy_connect_timeout, $proxy_set_header = [], $proxy_cache = false, + $proxy_cache_key = undef, + $proxy_cache_use_stale = undef, $proxy_cache_valid = false, $proxy_method = undef, $proxy_set_body = undef, @@ -322,6 +328,12 @@ if ($proxy_cache != false) { validate_string($proxy_cache) } + if ($proxy_cache_key != undef) { + validate_string($proxy_cache_key) + } + if ($proxy_cache_use_stale != undef) { + validate_string($proxy_cache_use_stale) + } if ($proxy_cache_valid != false) { validate_string($proxy_cache_valid) } @@ -530,6 +542,8 @@ proxy_read_timeout => $proxy_read_timeout, proxy_connect_timeout => $proxy_connect_timeout, proxy_cache => $proxy_cache, + proxy_cache_key => $proxy_cache_key, + proxy_cache_use_stale => $proxy_cache_use_stale, proxy_cache_valid => $proxy_cache_valid, proxy_method => $proxy_method, proxy_set_header => $proxy_set_header, diff --git a/spec/defines/resource_location_spec.rb b/spec/defines/resource_location_spec.rb index 20a246dc0..7f550808c 100644 --- a/spec/defines/resource_location_spec.rb +++ b/spec/defines/resource_location_spec.rb @@ -604,7 +604,19 @@ :value => false, :notmatch => /proxy_cache\b/ }, - { + { + :title => 'should set proxy_cache_key', + :attr => 'proxy_cache_key', + :value => 'value', + :match => /^\s+proxy_cache_key\s+value;/, + }, + { + :title => 'should set proxy_cache_use_stale', + :attr => 'proxy_cache_use_stale', + :value => 'value', + :match => /^\s+proxy_cache_use_stale\s+value;/ + }, + { :title => 'should set proxy_pass', :attr => 'proxy', :value => 'value', diff --git a/templates/vhost/locations/proxy.erb b/templates/vhost/locations/proxy.erb index 1687417bf..237dac4fe 100644 --- a/templates/vhost/locations/proxy.erb +++ b/templates/vhost/locations/proxy.erb @@ -21,3 +21,9 @@ <% if @proxy_cache_valid -%> proxy_cache_valid <%= @proxy_cache_valid %>; <% end -%> +<% if @proxy_cache_use_stale -%> + proxy_cache_use_stale <%= @proxy_cache_use_stale %>; +<% end -%> +<% if @proxy_cache_key -%> + proxy_cache_key <%= @proxy_cache_key %>; +<% end -%> From 3b21779bfc5af6d6e5d10dfd72a34490f30dceba Mon Sep 17 00:00:00 2001 From: Jacob McCoy Wade Date: Wed, 3 Jun 2015 14:41:56 -0700 Subject: [PATCH 6/6] removing proxy_cache_path_hash from nginx::config and adding validation for either has or string for proxy_cache_path made the conditional test to use is_a?(Hash) for simplicity's sake in templates/conf.d/nginx.conf.erb --- manifests/config.pp | 11 +++++------ templates/conf.d/nginx.conf.erb | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/manifests/config.pp b/manifests/config.pp index f8ae56526..e3d29f9d4 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -69,7 +69,6 @@ $proxy_cache_keys_zone = 'd2:100m', $proxy_cache_levels = '1', $proxy_cache_max_size = '500m', - $proxy_cache_path_hash = 'string', $proxy_cache_path = false, $proxy_connect_timeout = '90', $proxy_headers_hash_bucket_size = '64', @@ -114,11 +113,11 @@ } validate_bool($confd_purge) validate_bool($vhost_purge) - if ($proxy_cache_path_hash != 'string') { - validate_hash($proxy_cache_path) - } - elsif ($proxy_cache_path != false) { - validate_string($proxy_cache_path) + if ( $proxy_cache_path != false) { + if ( is_string($proxy_cache_path) or is_hash($proxy_cache_path)) {} + else { + fail('proxy_cache_path must be a string or a hash') + } } validate_re($proxy_cache_levels, '^[12](:[12])*$') validate_string($proxy_cache_keys_zone) diff --git a/templates/conf.d/nginx.conf.erb b/templates/conf.d/nginx.conf.erb index 7cb0815dc..e9c6fd1a8 100644 --- a/templates/conf.d/nginx.conf.erb +++ b/templates/conf.d/nginx.conf.erb @@ -64,7 +64,7 @@ http { gzip_disable "MSIE [1-6]\.(?!.*SV1)"; <% end -%> -<% if @proxy_cache_path_hash != 'string' -%> +<% if @proxy_cache_path.is_a?(Hash) -%> <% @proxy_cache_path.sort_by{|k,v| k}.each do |key,value| -%> proxy_cache_path <%= key %> keys_zone=<%= value %> levels=<%= @proxy_cache_levels %> max_size=<%= @proxy_cache_max_size %> inactive=<%= @proxy_cache_inactive %>; <% end -%>