Skip to content

Add alias_path, proxy_http_version and additional auth capabilities #73

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions manifests/resource/location.pp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
$auth_basic = undef,
$www_root = undef,
$create_www_root = false,
$alias_path = undef,
$owner = '',
$groupowner = '',
$redirect = undef,
Expand All @@ -47,6 +48,7 @@
$proxy_read_timeout = '90',
$proxy_set_header = ['Host $host', 'X-Real-IP $remote_addr', 'X-Forwarded-For $proxy_add_x_forwarded_for', 'X-Forwarded-Proto $scheme' ],
$proxy_redirect = undef,
$proxy_http_version = undef,
$ssl = false,
$ssl_only = false,
$option = undef,
Expand Down Expand Up @@ -99,21 +101,23 @@
}

## Check for various error condtiions
# Check vhost
if ($vhost == undef) {
fail('Cannot create a location reference without attaching to a virtual host')
}
if (($www_root == undef) and ($proxy == undef) and ($redirect == undef)) {
fail('Cannot create a location reference without a www_root, proxy or redirect defined')
# Check www_root/proxy/redirect/alias_path
if (($www_root == undef) and ($proxy == undef) and ($redirect == undef) and ($alias_path == undef)) {
fail('Cannot create a location reference without a www_root, proxy, redirect, or alias_path defined')
}
if (($www_root != undef) and ($proxy != undef)) {
fail('Cannot define both directory and proxy in a virtual host')
}
if (($www_root != undef) and ($redirect != undef)) {
fail('Cannot define both directory and redirect in a virtual host')
}
if (($proxy != undef) and ($redirect != undef)) {
fail('Cannot define both proxy and redirect in a virtual host')

$mutual_exclusive = [$www_root, $proxy, $redirect, $alias_path]

# count all values which are not nil/undef - must be 1
if (count($mutual_exclusive) != 1) {
fail("Cannot define more than one of the following values: www_root: '$www_root', redirect: '$redirect', proxy: '$proxy', and alias_path: '$alias_path'!")
}

# Check auth
if (($auth_basic_user_file != undef) and ($auth_basic == undef)) {
fail('Cannot define auth_basic_user_file without auth_basic')
}
Expand Down
8 changes: 7 additions & 1 deletion manifests/resource/vhost.pp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
$proxy = undef,
$proxy_read_timeout = '90',
$proxy_set_header = undef,
$proxy_http_version = undef,
$proxy_redirect = undef,
$redirect = undef,
$index_files = ['index.html', 'index.htm', 'index.php'],
Expand All @@ -71,7 +72,9 @@
$create_www_root = false,
$owner = '',
$groupowner = '',
$fastcgi = absent
$fastcgi = absent,
$auth_basic = undef,
$auth_basic_user_file = undef
) {

File {
Expand Down Expand Up @@ -150,6 +153,7 @@
proxy_read_timeout => $proxy_read_timeout,
proxy_set_header => $proxy_set_header,
proxy_redirect => $proxy_redirect,
proxy_http_version => $proxy_http_version,
redirect => $redirect,
www_root => $www_root,
create_www_root => $create_www_root,
Expand All @@ -159,6 +163,8 @@
template_proxy => $template_proxy,
template_ssl_proxy => $template_ssl_proxy,
template_directory => $template_directory,
auth_basic => $auth_basic,
auth_basic_user_file => $auth_basic_user_file,
}

# Use the File Fragment Pattern to construct the configuration files.
Expand Down
1 change: 1 addition & 0 deletions templates/conf.d/proxy.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ proxy_buffers <%= scope.lookupvar('nginx::params::nx_proxy_buffers') %
<% scope.lookupvar('nginx::params::nx_proxy_set_header').each do |header| %>
proxy_set_header <%= header %>;
<% end %>
<% unless @nx_proxy_http_version.nil? || @nx_proxy_http_version.empty? -%>proxy_http_version <%= scope.lookupvar('nginx::params::nx_proxy_http_version') %>;<% end %>
5 changes: 5 additions & 0 deletions templates/vhost/vhost_location_directory.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
location <%= @location %> {
<% unless @www_root.nil? || @www_root.empty? -%>
root <%= @www_root %>;
<% end -%>
<% unless @alias_path.nil? || @alias_path.empty? -%>
alias <%= @alias_path %>;
<% end -%>
index <% @index_files.each do |i| %> <%= i %> <% end %>;
<% unless @auth_basic.nil? || @auth_basic.empty? -%>
auth_basic <%= @auth_basic %>;
Expand Down
3 changes: 3 additions & 0 deletions templates/vhost/vhost_location_proxy.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<% unless @proxy_redirect.nil? || @proxy_redirect.empty? -%>
proxy_redirect <%= @proxy_redirect %>;
<% end -%>
<% unless @proxy_http_version.nil? || @proxy_http_version.empty? -%>
proxy_http_version <%= @proxy_http_version %>;
<% end %>
<% unless @proxy_set_header.nil? || @proxy_set_header.empty? -%>
<% @proxy_set_header.each do |header| -%>
proxy_set_header <%= header %>;
Expand Down