Skip to content

Commit

Permalink
adding support for proxy_cache_bypass and proxy_cache_lock (voxpupuli…
Browse files Browse the repository at this point in the history
…#1150)

* adding support for proxy_cache_bypass and proxy_cache_lock

* adding tests and restrict proxy_cache_lock to enum
  • Loading branch information
ceonizm authored and wyardley committed Nov 18, 2017
1 parent d44c554 commit 275e6bb
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 57 deletions.
116 changes: 60 additions & 56 deletions manifests/resource/location.pp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@
# of off.
# [*proxy_cache_valid*] - This directive sets the time for caching
# different replies.
# [*proxy_cache_lock*] - This directive sets the locking mechanism for pouplating cache.
# [*proxy_cache_bypass*] - Defines conditions which the response will not be cached
# [*proxy_method*] - If defined, overrides the HTTP method of the
# request to be passed to the backend.
# [*proxy_http_version*] - Sets the proxy http version
Expand Down Expand Up @@ -153,65 +155,67 @@
# }

define nginx::resource::location (
Enum['present', 'absent'] $ensure = present,
Boolean $internal = false,
String $location = $name,
String $server = undef,
Optional[String] $www_root = undef,
Optional[String] $autoindex = undef,
Array $index_files = [
Enum['present', 'absent'] $ensure = present,
Boolean $internal = false,
String $location = $name,
String $server = undef,
Optional[String] $www_root = undef,
Optional[String] $autoindex = undef,
Array $index_files = [
'index.html',
'index.htm',
'index.php'],
Optional[String] $proxy = undef,
Optional[String] $proxy_redirect = $::nginx::proxy_redirect,
String $proxy_read_timeout = $::nginx::proxy_read_timeout,
String $proxy_connect_timeout = $::nginx::proxy_connect_timeout,
Array $proxy_set_header = $::nginx::proxy_set_header,
Array $proxy_hide_header = $::nginx::proxy_hide_header,
Array $proxy_pass_header = $::nginx::proxy_pass_header,
Optional[String] $fastcgi = undef,
Optional[String] $fastcgi_index = undef,
Optional[Hash] $fastcgi_param = undef,
String $fastcgi_params = "${::nginx::conf_dir}/fastcgi.conf",
Optional[String] $fastcgi_script = undef,
Optional[String] $fastcgi_split_path = undef,
Optional[String] $uwsgi = undef,
Optional[Hash] $uwsgi_param = undef,
String $uwsgi_params = "${nginx::config::conf_dir}/uwsgi_params",
Optional[String] $uwsgi_read_timeout = undef,
Boolean $ssl = false,
Boolean $ssl_only = false,
Optional[String] $location_alias = undef,
Optional[Enum['any', 'all']] $location_satisfy = undef,
Optional[Array] $location_allow = undef,
Optional[Array] $location_deny = undef,
Optional[Boolean ] $stub_status = undef,
Optional[Variant[String, Array]] $raw_prepend = undef,
Optional[Variant[String, Array]] $raw_append = undef,
Optional[Hash] $location_custom_cfg = undef,
Optional[Hash] $location_cfg_prepend = undef,
Optional[Hash] $location_cfg_append = undef,
Optional[Hash] $location_custom_cfg_prepend = undef,
Optional[Hash] $location_custom_cfg_append = undef,
Optional[Array] $include = undef,
Optional[Array] $try_files = undef,
Optional[String] $proxy_cache = undef,
Optional[String] $proxy_cache_key = undef,
Optional[String] $proxy_cache_use_stale = undef,
Optional[Variant[Array, String]] $proxy_cache_valid = undef,
Optional[String] $proxy_method = undef,
Optional[String] $proxy_http_version = undef,
Optional[String] $proxy_set_body = undef,
Optional[Enum['on', 'off']] $proxy_buffering = undef,
Optional[String] $auth_basic = undef,
Optional[String] $auth_basic_user_file = undef,
Optional[String] $auth_request = undef,
Array $rewrite_rules = [],
Integer[401,599] $priority = 500,
Boolean $mp4 = false,
Boolean $flv = false,
Optional[String] $expires = undef,
Optional[String] $proxy = undef,
Optional[String] $proxy_redirect = $::nginx::proxy_redirect,
String $proxy_read_timeout = $::nginx::proxy_read_timeout,
String $proxy_connect_timeout = $::nginx::proxy_connect_timeout,
Array $proxy_set_header = $::nginx::proxy_set_header,
Array $proxy_hide_header = $::nginx::proxy_hide_header,
Array $proxy_pass_header = $::nginx::proxy_pass_header,
Optional[String] $fastcgi = undef,
Optional[String] $fastcgi_index = undef,
Optional[Hash] $fastcgi_param = undef,
String $fastcgi_params = "${::nginx::conf_dir}/fastcgi.conf",
Optional[String] $fastcgi_script = undef,
Optional[String] $fastcgi_split_path = undef,
Optional[String] $uwsgi = undef,
Optional[Hash] $uwsgi_param = undef,
String $uwsgi_params = "${nginx::config::conf_dir}/uwsgi_params",
Optional[String] $uwsgi_read_timeout = undef,
Boolean $ssl = false,
Boolean $ssl_only = false,
Optional[String] $location_alias = undef,
Optional[Enum['any', 'all']] $location_satisfy = undef,
Optional[Array] $location_allow = undef,
Optional[Array] $location_deny = undef,
Optional[Boolean ] $stub_status = undef,
Optional[Variant[String, Array]] $raw_prepend = undef,
Optional[Variant[String, Array]] $raw_append = undef,
Optional[Hash] $location_custom_cfg = undef,
Optional[Hash] $location_cfg_prepend = undef,
Optional[Hash] $location_cfg_append = undef,
Optional[Hash] $location_custom_cfg_prepend = undef,
Optional[Hash] $location_custom_cfg_append = undef,
Optional[Array] $include = undef,
Optional[Array] $try_files = undef,
Optional[String] $proxy_cache = undef,
Optional[String] $proxy_cache_key = undef,
Optional[String] $proxy_cache_use_stale = undef,
Optional[Enum['on', 'off']] $proxy_cache_lock = undef,
Optional[Variant[Array, String]] $proxy_cache_valid = undef,
Optional[Variant[Array, String]] $proxy_cache_bypass = undef,
Optional[String] $proxy_method = undef,
Optional[String] $proxy_http_version = undef,
Optional[String] $proxy_set_body = undef,
Optional[Enum['on', 'off']] $proxy_buffering = undef,
Optional[String] $auth_basic = undef,
Optional[String] $auth_basic_user_file = undef,
Optional[String] $auth_request = undef,
Array $rewrite_rules = [],
Integer[401,599] $priority = 500,
Boolean $mp4 = false,
Boolean $flv = false,
Optional[String] $expires = undef,
) {

if ! defined(Class['nginx']) {
Expand Down
6 changes: 6 additions & 0 deletions manifests/resource/server.pp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
# [*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_cache_lock*] - This directive sets the locking mechanism for pouplating cache.
# [*proxy_cache_bypass*] - Defines conditions which the response will not be cached
# [*proxy_method*] - If defined, overrides the HTTP method of the request to be passed to the backend.
# [*proxy_http_version*] - Sets the proxy http version
# [*proxy_set_body*] - If defined, sets the body passed to the backend.
Expand Down Expand Up @@ -187,6 +189,8 @@
Optional[String] $proxy_cache_key = undef,
Optional[String] $proxy_cache_use_stale = undef,
Optional[Variant[Array[String], String]] $proxy_cache_valid = undef,
Optional[Enum['on', 'off']] $proxy_cache_lock = undef,
Optional[Variant[Array[String], String]] $proxy_cache_bypass = undef,
Optional[String] $proxy_method = undef,
Optional[String] $proxy_http_version = undef,
Optional[String] $proxy_set_body = undef,
Expand Down Expand Up @@ -354,7 +358,9 @@
proxy_set_header => $proxy_set_header,
proxy_hide_header => $proxy_hide_header,
proxy_pass_header => $proxy_pass_header,
proxy_cache_lock => $proxy_cache_lock,
proxy_set_body => $proxy_set_body,
proxy_cache_bypass => $proxy_cache_bypass,
proxy_buffering => $proxy_buffering,
fastcgi => $fastcgi,
fastcgi_index => $fastcgi_index,
Expand Down
30 changes: 30 additions & 0 deletions spec/defines/resource_location_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,36 @@
value: 'value',
match: %r{^\s+proxy_cache_use_stale\s+value;}
},
{
title: 'should set proxy_cache_bypass with a string',
attr: 'proxy_cache_bypass',
value: '$pragma',
match: %r{^\s+proxy_cache_bypass\s+\$pragma;}
},
{
title: 'should set proxy_cache_bypass with an array',
attr: 'proxy_cache_bypass',
value: [
'$pragma',
'$cookie'
],
match: [
%r{^\s+proxy_cache_bypass\s+\$pragma;},
%r{^\s+proxy_cache_bypass\s+\$cookie;}
]
},
{
title: 'should set proxy_cache_lock with a string',
attr: 'proxy_cache_lock',
value: 'on',
match: %r{^\s+proxy_cache_lock\s+on;}
},
{
title: 'should set proxy_cache_lock with a string',
attr: 'proxy_cache_lock',
value: 'off',
match: %r{^\s+proxy_cache_lock\s+off;}
},
{
title: 'should set proxy_pass',
attr: 'proxy',
Expand Down
10 changes: 9 additions & 1 deletion templates/server/locations/proxy.erb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<% if @proxy_cache -%>
proxy_cache <%= @proxy_cache %>;
<% end -%>
<% if @proxy_cache_valid && Array(@proxy_cache_valid).size > 0 -%>
<% if @proxy_cache_valid -%>
<%- Array(@proxy_cache_valid).each do |line| -%>
proxy_cache_valid <%= line %>;
<%- end -%>
Expand All @@ -46,4 +46,12 @@
<% if @proxy_cache_key -%>
proxy_cache_key <%= @proxy_cache_key %>;
<% end -%>
<% if @proxy_cache_bypass -%>
<%- Array(@proxy_cache_bypass).each do |line| -%>
proxy_cache_bypass <%= line %>;
<% end -%>
<% end -%>
<% if @proxy_cache_lock -%>
proxy_cache_lock <%= @proxy_cache_lock %>;
<% end -%>
<% end -%>

0 comments on commit 275e6bb

Please sign in to comment.