summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2021-09-22 08:30:30 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2021-09-22 08:31:59 -0700
commit53e3465cea3eb349ee5fcdba65a147ef5d805b7b (patch)
tree4b5dd8698089b7bfc03127bd11add7aea04ff9eb
parent93e807cf42e19f66f35030c99803f60833da20f9 (diff)
downloadchef-53e3465cea3eb349ee5fcdba65a147ef5d805b7b.tar.gz
Add http_options property to remote_filelcg/remote-file-http-options
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r--lib/chef/http.rb4
-rw-r--r--lib/chef/provider/remote_file/http.rb2
-rw-r--r--lib/chef/resource/remote_file.rb3
-rw-r--r--spec/unit/provider/remote_file/http_spec.rb10
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