From 25a96920f662f43c1c28e99e4636bdbecdca788d Mon Sep 17 00:00:00 2001 From: Guilherme Maluf Date: Tue, 28 Jul 2015 15:19:02 -0300 Subject: [PATCH] Add tempurl middleware options Tempurl middleware is set with default options only This commits make it possible to manage all tempurl configs defined in proxy-server.conf-sample[1]: methods incoming_remove_headers incoming_allow_headers outgoing_remove_headers outgoing_allow_headers Parameters are optional and can be set with array or string [1] https://github.com/openstack/swift/blob/master/etc/proxy-server.conf-sample Change-Id: I1fab905a46aa58c43b8b3fd35ecdaf310bffc121 --- manifests/proxy/tempurl.pp | 83 ++++++++++++++++++++++-- spec/classes/swift_proxy_tempurl_spec.rb | 43 ++++++++++++ templates/proxy/tempurl.conf.erb | 16 ++++- 3 files changed, 137 insertions(+), 5 deletions(-) diff --git a/manifests/proxy/tempurl.pp b/manifests/proxy/tempurl.pp index 200337b1..b58a4372 100644 --- a/manifests/proxy/tempurl.pp +++ b/manifests/proxy/tempurl.pp @@ -1,21 +1,96 @@ # -# Configure swift cache_errors. +# Configure swift tempurl. # -# == Dependencies +# == Parameters +# +# [*methods*] +# Methods allowed with Temp URLs. +# Example: ['GET','HEAD','PUT','POST','DELETE'] or 'GET HEAD PUT POST DELETE' +# Optional. Defaults to undef. +# +# [*incoming_remove_headers*] +# The headers to remove from incoming requests. +# Example: ['x-timestamp'] or 'x-timestamp' +# Optional. Defaults to undef. +# +# [*incoming_allow_headers*] +# The headers allowed as exceptions to incoming_remove_headers +# Example: ['*'] or '*' +# Optional. Defaults to undef. +# +# [*outgoing_remove_headers*] +# The headers to remove from outgoing responses +# Example: ['x-object-meta-*'] or 'x-object-meta-*' +# Optional. Defaults to undef. +# +# [*outgoing_allow_headers*] +# The headers allowed as exceptions to outgoing_remove_headers +# Example: ['x-object-meta-public-*'] or 'x-object-meta-public-*' +# Optional. Defaults to undef. # # == Examples # -# include swift::proxy::tempurl +# class {'swift::proxy::tempurl': +# methods => ['GET','HEAD','PUT'], +# incoming_remove_headers => 'x-timestamp-*', +# } # # == Authors # +# Guilherme Maluf # Mehdi Abaakouk # # == Copyright # # Copyright 2012 eNovance licensing@enovance.com # -class swift::proxy::tempurl() { +class swift::proxy::tempurl ( + $methods = undef, + $incoming_remove_headers = undef, + $incoming_allow_headers = undef, + $outgoing_remove_headers = undef, + $outgoing_allow_headers = undef, +) { + + if($methods) { + if is_array($methods) { + $methods_real = join($methods,' ') + } elsif is_string($methods) { + $methods_real = $methods + } + } + + if($incoming_remove_headers) { + if is_array($incoming_remove_headers) { + $incoming_remove_headers_real = join($incoming_remove_headers,' ') + } elsif is_string($incoming_remove_headers) { + $incoming_remove_headers_real = $incoming_remove_headers + } + } + + if($incoming_allow_headers) { + if is_array($incoming_allow_headers) { + $incoming_allow_headers_real = join($incoming_allow_headers,' ') + } elsif is_string($incoming_allow_headers) { + $incoming_allow_headers_real = $incoming_allow_headers + } + } + + if($outgoing_remove_headers) { + if is_array($outgoing_remove_headers) { + $outgoing_remove_headers_real = join($outgoing_remove_headers,' ') + } elsif is_string($outgoing_remove_headers) { + $outgoing_remove_headers_real = $outgoing_remove_headers + } + } + + if($outgoing_allow_headers) { + if is_array($outgoing_allow_headers) { + $outgoing_allow_headers_real = join($outgoing_allow_headers,' ') + } elsif is_string($outgoing_allow_headers) { + $outgoing_allow_headers_real = $outgoing_allow_headers + } + } concat::fragment { 'swift-proxy-tempurl': target => '/etc/swift/proxy-server.conf', diff --git a/spec/classes/swift_proxy_tempurl_spec.rb b/spec/classes/swift_proxy_tempurl_spec.rb index f007d87a..ac68dfb0 100644 --- a/spec/classes/swift_proxy_tempurl_spec.rb +++ b/spec/classes/swift_proxy_tempurl_spec.rb @@ -18,4 +18,47 @@ describe 'swift::proxy::tempurl' do it { is_expected.to contain_file(fragment_file).with_content(/[filter:tempurl]/) } it { is_expected.to contain_file(fragment_file).with_content(/use = egg:swift#tempurl/) } + ['methods', + 'incoming_remove_headers', + 'incoming_allow_headers', + 'outgoing_remove_headers', + 'outgoing_allow_headers' ].each do |h| + it { is_expected.to_not contain_file(fragment_file).with_content(/#{h}/) } + end + + context "when params are set" do + let :params do { + 'methods' => ['GET','HEAD','PUT'], + 'incoming_remove_headers' => ['x-foo','x-bar-*'], + 'incoming_allow_headers' => ['x-foo','x-bar-*'], + 'outgoing_remove_headers' => ['x-foo','x-bar-*'], + 'outgoing_allow_headers' => ['x-foo','x-bar-*'], + } end + + it { is_expected.to contain_file(fragment_file).with_content(/methods = GET HEAD PUT/) } + ['incoming_remove_headers', + 'incoming_allow_headers', + 'outgoing_remove_headers', + 'outgoing_allow_headers' ].each do |h| + it { is_expected.to contain_file(fragment_file).with_content(/#{h} = x-foo x-bar-*/) } + end + + describe 'when params are not array' do + let :params do { + 'methods' => 'GET HEAD PUT', + 'incoming_remove_headers' => 'x-foo x-bar-*', + 'incoming_allow_headers' => 'x-foo x-bar-*', + 'outgoing_remove_headers' => 'x-foo x-bar-*', + 'outgoing_allow_headers' => 'x-foo x-bar-*', + } end + + it { is_expected.to contain_file(fragment_file).with_content(/methods = GET HEAD PUT/) } + ['incoming_remove_headers', + 'incoming_allow_headers', + 'outgoing_remove_headers', + 'outgoing_allow_headers' ].each do |h| + it { is_expected.to contain_file(fragment_file).with_content(/#{h} = x-foo x-bar-*/) } + end + end + end end diff --git a/templates/proxy/tempurl.conf.erb b/templates/proxy/tempurl.conf.erb index 4d0219a5..58ae0540 100644 --- a/templates/proxy/tempurl.conf.erb +++ b/templates/proxy/tempurl.conf.erb @@ -1,4 +1,18 @@ [filter:tempurl] use = egg:swift#tempurl - +<% if @methods_real-%> +methods = <%= @methods_real %> +<% end -%> +<% if @incoming_remove_headers_real-%> +incoming_remove_headers = <%= @incoming_remove_headers_real %> +<% end -%> +<% if @incoming_allow_headers_real-%> +incoming_allow_headers = <%= @incoming_allow_headers_real %> +<% end -%> +<% if @outgoing_remove_headers_real-%> +outgoing_remove_headers = <%= @outgoing_remove_headers_real %> +<% end -%> +<% if @outgoing_allow_headers_real-%> +outgoing_allow_headers = <%= @outgoing_allow_headers_real %> +<% end -%>