class ChefCLI::ChefServerAPIMulti

A wrapper for `Chef::ServerAPI` that supports multi-threading by creating a `Chef::ServerAPI` object per-thread.

This is intended to be used for downloading cookbooks from the Chef Infa Server, where the API of the Chef Infra Server requires each file to be downloaded individually.

It also configures `Chef::ServerAPI` to enable keepalives by default. To disable them, `keepalives: false` must be set in the options to the constructor.

Constants

KEEPALIVES_TRUE

Attributes

opts[R]
url[R]

Public Class Methods

new(url, opts) click to toggle source
# File lib/chef-cli/chef_server_api_multi.rb, line 39
def initialize(url, opts)
  @url = url
  @opts = KEEPALIVES_TRUE.merge(opts)
end

Public Instance Methods

client_for_thread() click to toggle source
# File lib/chef-cli/chef_server_api_multi.rb, line 68
def client_for_thread
  Thread.current[:chef_server_api_multi] ||= Chef::ServerAPI.new(@url, @opts)
end
delete(*args) click to toggle source
# File lib/chef-cli/chef_server_api_multi.rb, line 60
def delete(*args)
  client_for_thread.delete(*args)
end
get(*args) click to toggle source
# File lib/chef-cli/chef_server_api_multi.rb, line 48
def get(*args)
  client_for_thread.get(*args)
end
head(*args) click to toggle source
# File lib/chef-cli/chef_server_api_multi.rb, line 44
def head(*args)
  client_for_thread.head(*args)
end
post(*args) click to toggle source
# File lib/chef-cli/chef_server_api_multi.rb, line 56
def post(*args)
  client_for_thread.post(*args)
end
put(*args) click to toggle source
# File lib/chef-cli/chef_server_api_multi.rb, line 52
def put(*args)
  client_for_thread.put(*args)
end
streaming_request(*args, &block) click to toggle source
# File lib/chef-cli/chef_server_api_multi.rb, line 64
def streaming_request(*args, &block)
  client_for_thread.streaming_request(*args, &block)
end