From 360239c8dc5fc3eded26d27cb2cc5fa932193874 Mon Sep 17 00:00:00 2001 From: Martin Konrad Date: Fri, 6 Jun 2014 22:23:19 -0400 Subject: [PATCH 1/4] Support parameters along with proxy_pass --- README.md | 4 +++- templates/vhost/_proxy.erb | 1 - 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1418696bf..22c7f0fb9 100644 --- a/README.md +++ b/README.md @@ -1127,7 +1127,7 @@ Specifies the destination address of a [ProxyPass](http://httpd.apache.org/docs/ #####`proxy_pass` -Specifies an array of `path => URI` for a [ProxyPass](http://httpd.apache.org/docs/current/mod/mod_proxy.html#proxypass) configuration. Defaults to 'undef'. +Specifies an array of `path => URI` for a [ProxyPass](http://httpd.apache.org/docs/current/mod/mod_proxy.html#proxypass) configuration. Defaults to 'undef'. Optionally parameters can be added as an array. ```puppet apache::vhost { 'site.name.fdqn': @@ -1138,6 +1138,8 @@ apache::vhost { 'site.name.fdqn': { 'path' => '/c', 'url' => 'http://backend-a/c', 'params' => 'max=20 ttl=120 retry=300' }, { 'path' => '/l', 'url' => 'http://backend-xy', 'reverse_urls' => ['http://backend-x', 'http://backend-y'] }, + { 'path' => '/d', 'url' => 'http://backend-a/d', + 'params' => ['retry=0', 'timeout=5'] }, ], } ``` diff --git a/templates/vhost/_proxy.erb b/templates/vhost/_proxy.erb index 190239de9..847715795 100644 --- a/templates/vhost/_proxy.erb +++ b/templates/vhost/_proxy.erb @@ -8,7 +8,6 @@ <%- end -%> <%- [@proxy_pass].flatten.compact.each do |proxy| -%> ProxyPass <%= proxy['path'] %> <%= proxy['url'] %> <%- if !proxy['params'].nil? -%> <%= proxy['params'] %> <%- end -%> - > <%- if proxy['reverse_urls'].nil? -%> ProxyPassReverse <%= proxy['url'] %> From 934f2d4884b945f53150e5e6d488f1256ad8dc77 Mon Sep 17 00:00:00 2001 From: Martin Konrad Date: Mon, 18 Aug 2014 14:27:27 -0400 Subject: [PATCH 2/4] Support keywords along with proxy_pass, use hash for params --- README.md | 4 +++- templates/vhost/_proxy.erb | 8 +++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 22c7f0fb9..d31ae362f 100644 --- a/README.md +++ b/README.md @@ -1139,7 +1139,9 @@ apache::vhost { 'site.name.fdqn': { 'path' => '/l', 'url' => 'http://backend-xy', 'reverse_urls' => ['http://backend-x', 'http://backend-y'] }, { 'path' => '/d', 'url' => 'http://backend-a/d', - 'params' => ['retry=0', 'timeout=5'] }, + 'params' => { 'retry' => '0', 'timeout' => '5' }, }, + { 'path' => '/e', 'url' => 'http://backend-a/e', + 'keywords' => ['nocanon', 'interpolate'] }, ], } ``` diff --git a/templates/vhost/_proxy.erb b/templates/vhost/_proxy.erb index 847715795..dd25e2c87 100644 --- a/templates/vhost/_proxy.erb +++ b/templates/vhost/_proxy.erb @@ -7,7 +7,13 @@ ProxyPreserveHost On <%- end -%> <%- [@proxy_pass].flatten.compact.each do |proxy| -%> - ProxyPass <%= proxy['path'] %> <%= proxy['url'] %> <%- if !proxy['params'].nil? -%> <%= proxy['params'] %> <%- end -%> + ProxyPass <%= proxy['path'] %> <%= proxy['url'] -%> + <%- if proxy['params'] -%> + <%- proxy['params'].each_pair do |key, value| -%> <%= key %>=<%= value -%> + <%- end -%> + <%- end -%> + <%- if proxy['keywords'] %> <%= proxy['keywords'].join(' ') -%> + <%- end %> > <%- if proxy['reverse_urls'].nil? -%> ProxyPassReverse <%= proxy['url'] %> From 4c54a52c17e346e0c487e293c7727cb131aaca06 Mon Sep 17 00:00:00 2001 From: Martin Konrad Date: Mon, 18 Aug 2014 17:22:40 -0400 Subject: [PATCH 3/4] Add some tests for ProxyPass parameters --- tests/vhost_proxypass.pp | 60 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 tests/vhost_proxypass.pp diff --git a/tests/vhost_proxypass.pp b/tests/vhost_proxypass.pp new file mode 100644 index 000000000..968de4195 --- /dev/null +++ b/tests/vhost_proxypass.pp @@ -0,0 +1,60 @@ +## vhost with proxyPass directive +# NB: Please see the other vhost_*.pp example files for further +# examples. + +# Base class. Declares default vhost on port 80 and default ssl +# vhost on port 443 listening on all interfaces and serving +# $apache::docroot +class { 'apache': } + +# Most basic vhost with proxy_pass +apache::vhost { 'first.example.com': + port => 80, + docroot => '/var/www/first', + proxy_pass => [ + { + 'path' => '/first', + 'url' => "http://localhost:8080/first" + }, + ], +} + +# vhost with proxy_pass and parameters +apache::vhost { 'second.example.com': + port => 80, + docroot => '/var/www/second', + proxy_pass => [ + { + 'path' => '/second', + 'url' => "http://localhost:8080/second", + 'params' => {'retry' => '0', 'timeout' => '5'} + }, + ], +} + +# vhost with proxy_pass and keywords +apache::vhost { 'third.example.com': + port => 80, + docroot => '/var/www/third', + proxy_pass => [ + { + 'path' => '/third', + 'url' => "http://localhost:8080/third", + 'keywords' => ['noquery', 'interpolate'] + }, + ], +} + +# vhost with proxy_pass, parameters and keywords +apache::vhost { 'fourth.example.com': + port => 80, + docroot => '/var/www/fourth', + proxy_pass => [ + { + 'path' => '/fourth', + 'url' => "http://localhost:8080/fourth", + 'params' => {'retry' => '0', 'timeout' => '5'}, + 'keywords' => ['noquery', 'interpolate'] + }, + ], +} \ No newline at end of file From 0edb041427f4b6019db48d776b351833558552d6 Mon Sep 17 00:00:00 2001 From: Tim Hartmann Date: Thu, 23 Oct 2014 15:50:15 -0400 Subject: [PATCH 4/4] Linting and adding some tests Adding tests --- spec/defines/vhost_spec.rb | 16 +++++++++--- tests/vhost_proxypass.pp | 50 +++++++++++++++++++++----------------- 2 files changed, 41 insertions(+), 25 deletions(-) diff --git a/spec/defines/vhost_spec.rb b/spec/defines/vhost_spec.rb index 3eac5ffb4..84a95bf44 100644 --- a/spec/defines/vhost_spec.rb +++ b/spec/defines/vhost_spec.rb @@ -172,8 +172,13 @@ 'proxy_dest' => '/', 'proxy_pass' => [ { - 'path' => '/a', - 'url' => 'http://backend-a/' + 'path' => '/a', + 'url' => 'http://backend-a/', + 'keywords' => ['noquery', 'interpolate'], + 'params' => { + 'retry' => '0', + 'timeout' => '5' + } } ], 'suphp_addhandler' => 'foo', @@ -296,7 +301,12 @@ it { is_expected.to contain_concat__fragment('rspec.example.com-action') } it { is_expected.to contain_concat__fragment('rspec.example.com-block') } it { is_expected.to contain_concat__fragment('rspec.example.com-error_document') } - it { is_expected.to contain_concat__fragment('rspec.example.com-proxy') } + it { is_expected.to contain_concat__fragment('rspec.example.com-proxy').with_content( + /retry=0/) } + it { is_expected.to contain_concat__fragment('rspec.example.com-proxy').with_content( + /timeout=5/) } + it { is_expected.to contain_concat__fragment('rspec.example.com-proxy').with_content( + /noquery interpolate/) } it { is_expected.to contain_concat__fragment('rspec.example.com-rack') } it { is_expected.to contain_concat__fragment('rspec.example.com-redirect') } it { is_expected.to contain_concat__fragment('rspec.example.com-rewrite') } diff --git a/tests/vhost_proxypass.pp b/tests/vhost_proxypass.pp index 968de4195..e911f85f9 100644 --- a/tests/vhost_proxypass.pp +++ b/tests/vhost_proxypass.pp @@ -9,37 +9,40 @@ # Most basic vhost with proxy_pass apache::vhost { 'first.example.com': - port => 80, - docroot => '/var/www/first', - proxy_pass => [ + port => 80, + docroot => '/var/www/first', + proxy_pass => [ { - 'path' => '/first', - 'url' => "http://localhost:8080/first" + 'path' => '/first', + 'url' => 'http://localhost:8080/first' }, ], } # vhost with proxy_pass and parameters apache::vhost { 'second.example.com': - port => 80, - docroot => '/var/www/second', - proxy_pass => [ + port => 80, + docroot => '/var/www/second', + proxy_pass => [ { 'path' => '/second', - 'url' => "http://localhost:8080/second", - 'params' => {'retry' => '0', 'timeout' => '5'} + 'url' => 'http://localhost:8080/second', + 'params' => { + 'retry' => '0', + 'timeout' => '5' + } }, ], } # vhost with proxy_pass and keywords apache::vhost { 'third.example.com': - port => 80, - docroot => '/var/www/third', - proxy_pass => [ + port => 80, + docroot => '/var/www/third', + proxy_pass => [ { - 'path' => '/third', - 'url' => "http://localhost:8080/third", + 'path' => '/third', + 'url' => 'http://localhost:8080/third', 'keywords' => ['noquery', 'interpolate'] }, ], @@ -47,14 +50,17 @@ # vhost with proxy_pass, parameters and keywords apache::vhost { 'fourth.example.com': - port => 80, - docroot => '/var/www/fourth', - proxy_pass => [ + port => 80, + docroot => '/var/www/fourth', + proxy_pass => [ { - 'path' => '/fourth', - 'url' => "http://localhost:8080/fourth", - 'params' => {'retry' => '0', 'timeout' => '5'}, + 'path' => '/fourth', + 'url' => 'http://localhost:8080/fourth', + 'params' => { + 'retry' => '0', + 'timeout' => '5' + }, 'keywords' => ['noquery', 'interpolate'] }, ], -} \ No newline at end of file +}