From 53e3465cea3eb349ee5fcdba65a147ef5d805b7b Mon Sep 17 00:00:00 2001 From: Lamont Granquist Date: Wed, 22 Sep 2021 08:30:30 -0700 Subject: Add http_options property to remote_file Signed-off-by: Lamont Granquist --- lib/chef/http.rb | 4 ++-- lib/chef/provider/remote_file/http.rb | 2 +- lib/chef/resource/remote_file.rb | 3 +++ spec/unit/provider/remote_file/http_spec.rb | 10 ++++++++++ 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/chef/http.rb b/lib/chef/http.rb index 00e1d2bd50..68d99b2af1 100644 --- a/lib/chef/http.rb +++ b/lib/chef/http.rb @@ -468,12 +468,12 @@ class Chef # @api private def http_retry_delay - config[:http_retry_delay] + options[:http_retry_delay] || config[:http_retry_delay] end # @api private def http_retry_count - config[:http_retry_count] + options[:http_retry_count] || config[:http_retry_count] end # @api private diff --git a/lib/chef/provider/remote_file/http.rb b/lib/chef/provider/remote_file/http.rb index ef2461848d..40f64a0e85 100644 --- a/lib/chef/provider/remote_file/http.rb +++ b/lib/chef/provider/remote_file/http.rb @@ -137,7 +137,7 @@ class Chef if new_resource.ssl_verify_mode opts[:ssl_verify_mode] = new_resource.ssl_verify_mode end - opts + opts.merge(new_resource.http_options) end end diff --git a/lib/chef/resource/remote_file.rb b/lib/chef/resource/remote_file.rb index 18f182f40c..89e63eea6b 100644 --- a/lib/chef/resource/remote_file.rb +++ b/lib/chef/resource/remote_file.rb @@ -118,6 +118,9 @@ class Chef property :authentication, Symbol, equal_to: %i{remote local}, default: :remote + property :http_options, Hash, default: {}, + description: "A Hash of custom HTTP options. For example: `http_options({ http_retry_count: 0, http_retry_delay: 2 })`" + def after_created validate_identity_platform(remote_user, remote_password, remote_domain) identity = qualify_user(remote_user, remote_password, remote_domain) diff --git a/spec/unit/provider/remote_file/http_spec.rb b/spec/unit/provider/remote_file/http_spec.rb index 032cf474ef..8eca721cd0 100644 --- a/spec/unit/provider/remote_file/http_spec.rb +++ b/spec/unit/provider/remote_file/http_spec.rb @@ -321,4 +321,14 @@ describe Chef::Provider::RemoteFile::HTTP do end + describe "#http_client_opts" do + before do + new_resource.http_options({ retries: 2, retry_delay: 3 }) + end + + it "should set http client options" do + expect(fetcher.send(:http_client_opts)).to eq({ retries: 2, retry_delay: 3 }) + end + end + end -- cgit v1.2.1