From a353ef8c7536f842b7ec7fc144af3ccd2eceeca8 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Tue, 27 Oct 2020 08:35:28 +0900 Subject: [PATCH] Refactor the swift::proxy::tempurl class - Use $::os_service_default as the default value instead of undef. - Use any2array to generate raw value rendered into proxy-server.conf. This removes warnings about undefined variables. Change-Id: Idc3a2afc591e6a5025b6cc529ae7f10637cd2a64 --- manifests/proxy/tempurl.pp | 65 ++++++------------------ spec/classes/swift_proxy_tempurl_spec.rb | 2 +- 2 files changed, 16 insertions(+), 51 deletions(-) diff --git a/manifests/proxy/tempurl.pp b/manifests/proxy/tempurl.pp index d2f089ae..f4a29d2c 100644 --- a/manifests/proxy/tempurl.pp +++ b/manifests/proxy/tempurl.pp @@ -6,27 +6,27 @@ # [*methods*] # Methods allowed with Temp URLs. # Example: ['GET','HEAD','PUT','POST','DELETE'] or 'GET HEAD PUT POST DELETE' -# Optional. Defaults to undef. +# Optional. Defaults to $::os_service_default. # # [*incoming_remove_headers*] # The headers to remove from incoming requests. # Example: ['x-timestamp'] or 'x-timestamp' -# Optional. Defaults to undef. +# Optional. Defaults to $::os_service_default. # # [*incoming_allow_headers*] # The headers allowed as exceptions to incoming_remove_headers # Example: ['*'] or '*' -# Optional. Defaults to undef. +# Optional. Defaults to $::os_service_default. # # [*outgoing_remove_headers*] # The headers to remove from outgoing responses # Example: ['x-object-meta-*'] or 'x-object-meta-*' -# Optional. Defaults to undef. +# Optional. Defaults to $::os_service_default. # # [*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. +# Optional. Defaults to $::os_service_default. # # == Examples # @@ -45,55 +45,20 @@ # Copyright 2012 eNovance licensing@enovance.com # class swift::proxy::tempurl ( - $methods = undef, - $incoming_remove_headers = undef, - $incoming_allow_headers = undef, - $outgoing_remove_headers = undef, - $outgoing_allow_headers = undef, + $methods = $::os_service_default, + $incoming_remove_headers = $::os_service_default, + $incoming_allow_headers = $::os_service_default, + $outgoing_remove_headers = $::os_service_default, + $outgoing_allow_headers = $::os_service_default, ) { include swift::deps - 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 - } - } - + $methods_real = join(any2array($methods), ' ') + $incoming_remove_headers_real = join(any2array($incoming_remove_headers), ' ') + $incoming_allow_headers_real = join(any2array($incoming_allow_headers), ' ') + $outgoing_remove_headers_real = join(any2array($outgoing_remove_headers), ' ') + $outgoing_allow_headers_real = join(any2array($outgoing_allow_headers), ' ') swift_proxy_config { 'filter:tempurl/use': value => 'egg:swift#tempurl'; diff --git a/spec/classes/swift_proxy_tempurl_spec.rb b/spec/classes/swift_proxy_tempurl_spec.rb index 5b02f9d7..19fdf53b 100644 --- a/spec/classes/swift_proxy_tempurl_spec.rb +++ b/spec/classes/swift_proxy_tempurl_spec.rb @@ -9,7 +9,7 @@ describe 'swift::proxy::tempurl' do 'incoming_allow_headers', 'outgoing_remove_headers', 'outgoing_allow_headers' ].each do |h| - it { is_expected.to_not contain_swift_proxy_config("filter:tempurl/#{h}").with_value('') } + it { is_expected.to contain_swift_proxy_config("filter:tempurl/#{h}").with_value('') } end context "when params are set" do