diff options
author | tylercloke <tylercloke@gmail.com> | 2015-05-27 14:32:24 -0700 |
---|---|---|
committer | tylercloke <tylercloke@gmail.com> | 2015-06-05 10:38:48 -0700 |
commit | 9b9d376f2e86cd2738c2c2928f77bf48f1dd20ee (patch) | |
tree | 226227e7e32f421a0dde0f1ad2046059eff449c3 /lib/chef/knife.rb | |
parent | 20f7e1c78c55d2a16d5033bc2bbe5904d225adb0 (diff) | |
download | chef-9b9d376f2e86cd2738c2c2928f77bf48f1dd20ee.tar.gz |
Added versioned Chef Object API support code and repaired Chef::User.create.
Also added Chef::User.create V1 API support. Chef::User.create will attempt to use V1 of the server API, and if it fails, it will fall back to V0.
Diffstat (limited to 'lib/chef/knife.rb')
-rw-r--r-- | lib/chef/knife.rb | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/lib/chef/knife.rb b/lib/chef/knife.rb index 71215e7fbf..4a93697a1b 100644 --- a/lib/chef/knife.rb +++ b/lib/chef/knife.rb @@ -487,11 +487,13 @@ class Chef ui.error "Service temporarily unavailable" ui.info "Response: #{format_rest_error(response)}" when Net::HTTPNotAcceptable - min_version = Chef::JSONCompat.from_json(response.body)["min_version"] - max_version = Chef::JSONCompat.from_json(response.body)["max_version"] + version_header = Chef::JSONCompat.from_json(response["x-ops-server-api-version"]) + client_api_version = version_header["request_version"] + min_server_version = version_header["min_version"] + max_server_version = version_header["max_version"] ui.error "The version of Chef that Knife is using is not supported by the Chef server you sent this request to" - ui.info "This version of Chef requires a server API version of #{Chef::HTTP::Authenticator::SERVER_API_VERSION}" - ui.info "The Chef server you sent the request to supports a min API verson of #{min_version} and a max API version of #{max_version}" + ui.info "The request that Knife sent was using API version #{client_api_version}" + ui.info "The Chef server you sent the request to supports a min API verson of #{min_server_version} and a max API version of #{max_server_version}" ui.info "Please either update your Chef client or server to be a compatible set" else ui.error response.message @@ -549,6 +551,16 @@ class Chef self.msg("Deleted #{obj_name}") end + # helper method for testing if a field exists + # and returning the usage and proper error if not + def test_mandatory_field(field, fieldname) + if field.nil? + show_usage + ui.fatal("You must specify a #{fieldname}") + exit 1 + end + end + def rest @rest ||= begin require 'chef/rest' |