Class: Chef::ServerAPI

Inherits:
HTTP
  • Object
show all
Defined in:
lib/chef/server_api.rb

Instance Attribute Summary

Attributes inherited from HTTP

#keepalives, #middlewares, #options, #redirect_limit, #sign_on_redirect, #url

Instance Method Summary collapse

Methods inherited from HTTP

#delete, #get, #head, #http_client, #last_response, middlewares, #post, #put, #request, #streaming_request, #streaming_request_with_progress, use

Constructor Details

#initialize(url = Chef::Config[:chef_server_url], options = {}) ⇒ ServerAPI

Returns a new instance of ServerAPI.



32
33
34
35
36
37
38
39
40
41
# File 'lib/chef/server_api.rb', line 32

def initialize(url = Chef::Config[:chef_server_url], options = {})
  # # If making a change here, also update Chef::Knife::Raw::RawInputServerAPI.
  options[:client_name] ||= Chef::Config[:node_name]
  options[:raw_key] ||= Chef::Config[:client_key_contents]
  options[:signing_key_filename] ||= Chef::Config[:client_key] unless options[:raw_key]
  options[:ssh_agent_signing] ||= Chef::Config[:ssh_agent_signing]
  options[:signing_key_filename] = nil if chef_zero_uri?(url)
  options[:inflate_json_class] = false
  super(url, options)
end

Instance Method Details

#raw_request(method, path, headers = {}, data = false) ⇒ Object

Makes an HTTP request to path with the given method, headers, and data (if applicable). Does not apply any middleware, besides that needed for Authentication.



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/chef/server_api.rb', line 65

def raw_request(method, path, headers = {}, data = false)
  url = create_url(path)
  method, url, headers, data = Chef::HTTP::Authenticator.new(options).handle_request(method, url, headers, data)
  method, url, headers, data = Chef::HTTP::RemoteRequestID.new(options).handle_request(method, url, headers, data)
  response, rest_request, return_value = send_http_request(method, url, headers, data)
  response.error! unless success_response?(response)
  return_value
rescue Exception => exception
  log_failed_request(response, return_value) unless response.nil?

  if exception.respond_to?(:chef_rest_request=)
    exception.chef_rest_request = rest_request
  end
  raise
end