summaryrefslogtreecommitdiff
path: root/lib/chef/mixin/versioned_api.rb
diff options
context:
space:
mode:
authorThom May <thom@may.lt>2017-03-29 18:36:20 +0100
committerGitHub <noreply@github.com>2017-03-29 18:36:20 +0100
commitd843ecc7557d60246af7f64bf7d3959027a46f3d (patch)
tree582caeeabaa0556364bd2caeb3890a4080340803 /lib/chef/mixin/versioned_api.rb
parent12242c1886d8d1a41e8c61c24d074fb76db4dbdd (diff)
parentd6dc0b04c6f3c3d8a1461778c0c2604f879b505b (diff)
downloadchef-d843ecc7557d60246af7f64bf7d3959027a46f3d.tar.gz
Merge pull request #5960 from chef/tm/retryable_api
Retry API requests if using an unsupported version
Diffstat (limited to 'lib/chef/mixin/versioned_api.rb')
-rw-r--r--lib/chef/mixin/versioned_api.rb17
1 files changed, 16 insertions, 1 deletions
diff --git a/lib/chef/mixin/versioned_api.rb b/lib/chef/mixin/versioned_api.rb
index 9c2f2f4cdb..17c9838d29 100644
--- a/lib/chef/mixin/versioned_api.rb
+++ b/lib/chef/mixin/versioned_api.rb
@@ -40,11 +40,15 @@ class Chef
end
def versioned_api_class
+ get_class_for(:max_server_version)
+ end
+
+ def get_class_for(type)
versioned_interfaces.select do |klass|
version = klass.send(:minimum_api_version)
# min and max versions will be nil if we've not made a request to the server yet,
# in which case we'll just start with the highest version and see what happens
- ServerAPIVersions.instance.min_server_version.nil? || (version >= ServerAPIVersions.instance.min_server_version && version <= ServerAPIVersions.instance.max_server_version)
+ ServerAPIVersions.instance.min_server_version.nil? || (version >= ServerAPIVersions.instance.min_server_version && version <= ServerAPIVersions.instance.send(type))
end
.sort { |a, b| a.send(:minimum_api_version) <=> b.send(:minimum_api_version) }
.last
@@ -59,6 +63,17 @@ class Chef
module_eval(str, __FILE__, line_no)
end
+ # When teeing up an HTTP request, we need to be able to ask which API version we should use.
+ # Something in Net::HTTP seems to expect to strip headers, so we return this as a string.
+ def best_request_version
+ klass = get_class_for(:max_server_version)
+ klass.minimum_api_version.to_s
+ end
+
+ def possible_requests
+ versioned_interfaces.length
+ end
+
def new(*args)
object = versioned_api_class.allocate
object.send(:initialize, *args)