Skip to content

Commit

Permalink
Merge pull request #1343 from Rubueno/autoindex
Browse files Browse the repository at this point in the history
Fixes #1027 - Enable setting autoindex variables
  • Loading branch information
bastelfreak authored Oct 31, 2019
2 parents cdb39e0 + 55a2a3d commit 2a84fbb
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 65 deletions.
140 changes: 75 additions & 65 deletions manifests/resource/location.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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']) {
Expand Down
10 changes: 10 additions & 0 deletions manifests/resource/server.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
26 changes: 26 additions & 0 deletions spec/defines/resource_location_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions spec/defines/resource_server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions templates/server/locations/directory.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 -%>
9 changes: 9 additions & 0 deletions templates/server/server_header.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 -%>
Expand Down
9 changes: 9 additions & 0 deletions templates/server/server_ssl_header.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 -%>
Expand Down

0 comments on commit 2a84fbb

Please sign in to comment.