diff options
author | Thom May <thom@chef.io> | 2017-01-18 11:31:19 +0000 |
---|---|---|
committer | Thom May <thom@chef.io> | 2017-02-14 10:22:23 -0800 |
commit | d4b87e5e0f73d92836b4523907e17b1a88be9317 (patch) | |
tree | 2c1cfe83eedec5c2a9d1c9bff40d07b3a8e75a4f /lib/chef/http | |
parent | f76e23dd27410505440eb06a174c6ce8c5afb341 (diff) | |
download | chef-d4b87e5e0f73d92836b4523907e17b1a88be9317.tar.gz |
Beginning of automatic API version detection
When we make a request to a chef server, we capture the minimum and
maximum support API versions and allow them to be queried.
We then provide some infrastructure for making decisions on which class
should be used, in a middleware-ish mechanism.
Signed-off-by: Thom May <thom@chef.io>
Diffstat (limited to 'lib/chef/http')
-rw-r--r-- | lib/chef/http/api_versions.rb | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/chef/http/api_versions.rb b/lib/chef/http/api_versions.rb new file mode 100644 index 0000000000..e164da262d --- /dev/null +++ b/lib/chef/http/api_versions.rb @@ -0,0 +1,50 @@ +#-- +# Copyright:: Copyright 2017, Chef Software Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require "chef/server_api_versions" + +class Chef + class HTTP + # An HTTP middleware to retrieve and store the Chef Server's minimum + # and maximum supported API versions. + class APIVersions + + def initialize(options = {}) + end + + def handle_request(method, url, headers = {}, data = false) + [method, url, headers, data] + end + + def handle_response(http_response, rest_request, return_value) + if http_response.key?("x-ops-server-api-version") + ServerAPIVersions.instance.set_versions(http_response["x-ops-server-api-version"]) + end + [http_response, rest_request, return_value] + end + + def stream_response_handler(response) + nil + end + + def handle_stream_complete(http_response, rest_request, return_value) + [http_response, rest_request, return_value] + end + + end + end +end |