diff options
author | Thom May <thom@chef.io> | 2017-03-29 09:34:09 +0100 |
---|---|---|
committer | Thom May <thom@chef.io> | 2017-03-29 13:25:00 +0100 |
commit | d6dc0b04c6f3c3d8a1461778c0c2604f879b505b (patch) | |
tree | 129eacaa80dd104f542d60b775fd1b665ebb425c /lib/chef/http | |
parent | 50808ca1b1691e45c4017e6e117764ddd617e93f (diff) | |
download | chef-d6dc0b04c6f3c3d8a1461778c0c2604f879b505b.tar.gz |
Retry API requests if using an unsupported versiontm/retryable_api
Signed-off-by: Thom May <thom@chef.io>
Diffstat (limited to 'lib/chef/http')
-rw-r--r-- | lib/chef/http/api_versions.rb | 3 | ||||
-rw-r--r-- | lib/chef/http/authenticator.rb | 21 |
2 files changed, 18 insertions, 6 deletions
diff --git a/lib/chef/http/api_versions.rb b/lib/chef/http/api_versions.rb index 696c7072bf..674d8f85a7 100644 --- a/lib/chef/http/api_versions.rb +++ b/lib/chef/http/api_versions.rb @@ -32,6 +32,9 @@ class Chef end def handle_response(http_response, rest_request, return_value) + if http_response.code == "406" + ServerAPIVersions.instance.reset! + end if http_response.key?("x-ops-server-api-version") ServerAPIVersions.instance.set_versions(JSONCompat.parse(http_response["x-ops-server-api-version"])) end diff --git a/lib/chef/http/authenticator.rb b/lib/chef/http/authenticator.rb index 84065bf816..65367af107 100644 --- a/lib/chef/http/authenticator.rb +++ b/lib/chef/http/authenticator.rb @@ -30,6 +30,8 @@ class Chef attr_reader :raw_key attr_reader :attr_names attr_reader :auth_credentials + attr_reader :version_class + attr_reader :api_version attr_accessor :sign_request @@ -39,15 +41,12 @@ class Chef @signing_key_filename = opts[:signing_key_filename] @key = load_signing_key(opts[:signing_key_filename], opts[:raw_key]) @auth_credentials = AuthCredentials.new(opts[:client_name], @key) - if opts[:api_version] - @api_version = opts[:api_version] - else - @api_version = DEFAULT_SERVER_API_VERSION - end + @version_class = opts[:version_class] + @api_version = opts[:api_version] end def handle_request(method, url, headers = {}, data = false) - headers["X-Ops-Server-API-Version"] = @api_version + headers["X-Ops-Server-API-Version"] = request_version headers.merge!(authentication_headers(method, url, data, headers)) if sign_requests? [method, url, headers, data] end @@ -64,6 +63,16 @@ class Chef [http_response, rest_request, return_value] end + def request_version + if version_class + version_class.best_request_version + elsif api_version + api_version + else + DEFAULT_SERVER_API_VERSION + end + end + def sign_requests? auth_credentials.sign_requests? && @sign_request end |