Module: Chef::Mixin::ApiVersionRequestHandling

Included in:
ApiClientV1, UserV1
Defined in:
lib/chef/mixin/api_version_request_handling.rb

Instance Method Summary collapse

Instance Method Details

#reregister_only_v0_supported_error_msg(max_version, min_version) ⇒ Object



52
53
54
55
56
57
58
59
60
# File 'lib/chef/mixin/api_version_request_handling.rb', line 52

def reregister_only_v0_supported_error_msg(max_version, min_version)
  <<~EOH
    The reregister command only supports server API version 0.
    The server that received the request supports a min version of #{min_version} and a max version of #{max_version}.
    User keys are now managed via the key rotation commands.
    Please refer to the documentation on how to manage your keys via the key rotation commands:
    https://docs.chef.io/ctl_chef_server/#key-rotation
  EOH
end

#server_client_api_version_intersection(exception, supported_client_versions) ⇒ Object

supported_client_versions: Output: nil:

If the exception was not a 406 or the server does not support versioning

Array of length zero:

If there was no intersection between supported client versions and supported server versions

Array of Integers:

If there was an intersection of supported versions, the array returns will contain that intersection

Parameters:

  • exception (Net::HTTPClientException)

    may or may not contain the x-ops-server-api-version header

  • supported_client_versions (Array<Integer>)

    The API versions the client supports.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/chef/mixin/api_version_request_handling.rb', line 33

def server_client_api_version_intersection(exception, supported_client_versions)
  # return empty array unless 406 Unacceptable with proper header
  return nil if exception.response.code != "406" || exception.response["x-ops-server-api-version"].nil?

  # intersection of versions the server and client support, will be of length zero if no intersection
  server_supported_client_versions = []

  header = Chef::JSONCompat.from_json(exception.response["x-ops-server-api-version"])
  min_server_version = Integer(header["min_version"])
  max_server_version = Integer(header["max_version"])

  supported_client_versions.each do |version|
    if version >= min_server_version && version <= max_server_version
      server_supported_client_versions.push(version)
    end
  end
  server_supported_client_versions
end