diff --git a/manifests/resource/location.pp b/manifests/resource/location.pp index 5746500b9..01fcc1e91 100644 --- a/manifests/resource/location.pp +++ b/manifests/resource/location.pp @@ -17,6 +17,13 @@ # read from. Cannot be set in conjunction with $proxy # [*autoindex*] - Set it on 'on' to activate autoindex directory # listing. Undef by default. +# [*autoindex_exact_size*] - Set it on 'on' or 'off' to +# activate/deactivate autoindex displaying exact filesize, or rounded to +# kilobytes, megabytes and gigabytes. Undef by default. +# [*autoindex_format*] - Sets the format of a directory listing. +# Undef by default. +# [*autoindex_localtime*] - Specifies whether times in the directory +# listing should be output in the local time zone or UTC. # [*index_files*] - Default index files for NGINX to read when # traversing a directory # [*proxy*] - Proxy server(s) for a location to connect to. @@ -171,74 +178,77 @@ # } define nginx::resource::location ( - Enum['present', 'absent'] $ensure = 'present', - Boolean $internal = false, - String $location = $name, - Variant[String[1],Array[String[1],1]] $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, + Variant[String[1],Array[String[1],1]] $server = undef, + Optional[String] $www_root = undef, + Optional[String] $autoindex = undef, + Optional[Enum['on', 'off']] $autoindex_exact_size = undef, + Optional[Enum['html', 'xml', 'json', 'jsonp']] $autoindex_format = undef, + Optional[Enum['on', 'off']] $autoindex_localtime = 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, - String $proxy_send_timeout = $nginx::proxy_send_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, - Array $proxy_ignore_header = $nginx::proxy_ignore_header, - Optional[String] $proxy_next_upstream = undef, - 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[Nginx::Size] $proxy_max_temp_file_size = undef, - Optional[Nginx::Size] $proxy_busy_buffers_size = undef, - Optional[Enum['on', 'off']] $absolute_redirect = 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, - Hash $add_header = {}, + 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, + String $proxy_send_timeout = $nginx::proxy_send_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, + Array $proxy_ignore_header = $nginx::proxy_ignore_header, + Optional[String] $proxy_next_upstream = undef, + 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[Nginx::Size] $proxy_max_temp_file_size = undef, + Optional[Nginx::Size] $proxy_busy_buffers_size = undef, + Optional[Enum['on', 'off']] $absolute_redirect = 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, + Hash $add_header = {}, ) { if ! defined(Class['nginx']) { diff --git a/manifests/resource/server.pp b/manifests/resource/server.pp index 3c536636e..7770ff630 100755 --- a/manifests/resource/server.pp +++ b/manifests/resource/server.pp @@ -22,6 +22,10 @@ # [*add_header*] - Hash: Adds headers to the HTTP response when response code is equal to 200, 204, 301, 302 or 304. # [*index_files*] - Default index files for NGINX to read when traversing a directory # [*autoindex*] - Set it on 'on' or 'off 'to activate/deactivate autoindex directory listing. Undef by default. +# [*autoindex_exact_size*] - Set it on 'on' or 'off' to activate/deactivate autoindex displaying exact filesize, or rounded to +# kilobytes, megabytes and gigabytes. Undef by default. +# [*autoindex_format*] - Sets the format of a directory listing. Undef by default. +# [*autoindex_localtime*] - Specifies whether times in the directory listing should be output in the local time zone or UTC. # [*proxy*] - Proxy server(s) for the root location to connect to. Accepts a single value, can be used in # conjunction with nginx::resource::upstream # [*proxy_read_timeout*] - Override the default proxy read timeout value of 90 seconds @@ -225,6 +229,9 @@ 'index.htm', 'index.php'], Optional[String] $autoindex = undef, + Optional[Enum['on', 'off']] $autoindex_exact_size = undef, + Optional[Enum['html', 'xml', 'json', 'jsonp']] $autoindex_format = undef, + Optional[Enum['on', 'off']] $autoindex_localtime = undef, Array[String] $server_name = [$name], Optional[String] $www_root = undef, Boolean $rewrite_www_to_non_www = false, @@ -398,6 +405,9 @@ try_files => $try_files, www_root => $www_root, autoindex => $autoindex, + autoindex_exact_size => $autoindex_exact_size, + autoindex_format => $autoindex_format, + autoindex_localtime => $autoindex_localtime, index_files => $index_files, location_custom_cfg => $location_custom_cfg, location_cfg_prepend => $location_cfg_prepend, diff --git a/spec/defines/resource_location_spec.rb b/spec/defines/resource_location_spec.rb index 02548e2d0..a6bf11d71 100644 --- a/spec/defines/resource_location_spec.rb +++ b/spec/defines/resource_location_spec.rb @@ -357,6 +357,12 @@ value: 'on', match: ' autoindex on;' }, + { + title: 'should set autoindex_format', + attr: 'autoindex_format', + value: 'html', + match: ' autoindex_format html;' + }, { title: 'should set try_file(s)', attr: 'try_files', @@ -515,6 +521,26 @@ without_content(%r{^[ ]+autoindex[^;]+;}) end end + + context "when autoindex_localtime is 'on'" do + let(:params) { default_params.merge(autoindex_localtime: 'on') } + + it { is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest('location')) } + it 'sets autoindex_localtime' do + is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest('location')). + with_content(%r{^[ ]+autoindex_localtime\s+on;}) + end + end + + context 'when autoindex_localtime is not set' do + let(:params) { default_params } + + it { is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest('location')) } + it 'does not set autoindex_localtime' do + is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest('location')). + without_content(%r{^[ ]+autoindex_localtime[^;]+;}) + end + end end describe 'server_location_empty template content' do diff --git a/spec/defines/resource_server_spec.rb b/spec/defines/resource_server_spec.rb index bb42ad5e0..3433c8dd9 100644 --- a/spec/defines/resource_server_spec.rb +++ b/spec/defines/resource_server_spec.rb @@ -361,6 +361,12 @@ attr: 'autoindex', value: 'on', match: ' autoindex on;' + }, + { + title: 'should set autoindex_exact_size', + attr: 'autoindex_exact_size', + value: 'on', + match: ' autoindex_exact_size on;' } ].each do |param| context "when #{param[:attr]} is #{param[:value]}" do @@ -952,6 +958,12 @@ attr: 'autoindex', value: 'on', match: ' autoindex on;' + }, + { + title: 'should set autoindex_exact_size', + attr: 'autoindex_exact_size', + value: 'on', + match: ' autoindex_exact_size on;' } ].each do |param| context "when #{param[:attr]} is #{param[:value]}" do diff --git a/templates/server/locations/directory.erb b/templates/server/locations/directory.erb index edc6e8b8e..d86357766 100644 --- a/templates/server/locations/directory.erb +++ b/templates/server/locations/directory.erb @@ -5,6 +5,15 @@ autoindex <%= @autoindex %>; <% end -%> +<% if defined? @autoindex_exact_size -%> + autoindex_exact_size <%= @autoindex_exact_size %>; +<% end -%> +<% if defined? @autoindex_format -%> + autoindex_format <%= @autoindex_format %>; +<% end -%> +<% if defined? @autoindex_localtime -%> + autoindex_localtime <%= @autoindex_localtime %>; +<% end -%> <% if @index_files and @index_files.count > 0 -%> index <% Array(@index_files).each do |i| %> <%= i %><% end %>; <% end -%> diff --git a/templates/server/server_header.erb b/templates/server/server_header.erb index 6f44b7d88..6d55d2a2d 100644 --- a/templates/server/server_header.erb +++ b/templates/server/server_header.erb @@ -140,6 +140,15 @@ server { <% if defined? @autoindex -%> autoindex <%= @autoindex %>; <% end -%> +<% if defined? @autoindex_exact_size -%> + autoindex_exact_size <%= @autoindex_exact_size %>; +<% end -%> +<% if defined? @autoindex_format -%> + autoindex_format <%= @autoindex_format %>; +<% end -%> +<% if defined? @autoindex_localtime -%> + autoindex_localtime <%= @autoindex_localtime %>; +<% end -%> <% if defined? @log_by_lua -%> log_by_lua '<%= @log_by_lua %>'; <% end -%> diff --git a/templates/server/server_ssl_header.erb b/templates/server/server_ssl_header.erb index 66ecd3cea..ad4c119b1 100644 --- a/templates/server/server_ssl_header.erb +++ b/templates/server/server_ssl_header.erb @@ -73,6 +73,15 @@ server { <% if defined? @autoindex -%> autoindex <%= @autoindex %>; <% end -%> +<% if defined? @autoindex_exact_size -%> + autoindex_exact_size <%= @autoindex_exact_size %>; +<% end -%> +<% if defined? @autoindex_format -%> + autoindex_format <%= @autoindex_format %>; +<% end -%> +<% if defined? @autoindex_localtime -%> + autoindex_localtime <%= @autoindex_localtime %>; +<% end -%> <% if @absolute_redirect -%> absolute_redirect <%= @absolute_redirect %>; <% end -%>