lib/chef-api/connection.rb in chef-api-0.5.0 vs lib/chef-api/connection.rb in chef-api-0.6.0

- old
+ new

@@ -96,15 +96,16 @@ # Make a HTTP GET request # # @param path (see Connection#request) # @param [Hash] params # the list of query params + # @param request_options (see Connection#request) # # @raise (see Connection#request) # @return (see Connection#request) # - def get(path, params = {}) + def get(path, params = {}, request_options = {}) request(:get, path, params) end # # Make a HTTP POST request @@ -112,56 +113,60 @@ # @param path (see Connection#request) # @param [String, #read] data # the body to use for the request # @param [Hash] params # the list of query params + # @param request_options (see Connection#request) # # @raise (see Connection#request) # @return (see Connection#request) # - def post(path, data, params = {}) + def post(path, data, params = {}, request_options = {}) request(:post, path, data, params) end # # Make a HTTP PUT request # # @param path (see Connection#request) # @param data (see Connection#post) # @param params (see Connection#post) + # @param request_options (see Connection#request) # # @raise (see Connection#request) # @return (see Connection#request) # - def put(path, data, params = {}) + def put(path, data, params = {}, request_options = {}) request(:put, path, data, params) end # # Make a HTTP PATCH request # # @param path (see Connection#request) # @param data (see Connection#post) # @param params (see Connection#post) + # @param request_options (see Connection#request) # # @raise (see Connection#request) # @return (see Connection#request) # - def patch(path, data, params = {}) + def patch(path, data, params = {}, request_options = {}) request(:patch, path, data, params) end # # Make a HTTP DELETE request # # @param path (see Connection#request) # @param params (see Connection#get) + # @param request_options (see Connection#request) # # @raise (see Connection#request) # @return (see Connection#request) # - def delete(path, params = {}) + def delete(path, params = {}, request_options = {}) request(:delete, path, params) end # # Make an HTTP request with the given verb, data, params, and headers. If @@ -178,15 +183,20 @@ # request against # @param [#read, Hash, nil] data # the data to use (varies based on the +verb+) # @param [Hash] params # the params to use for :patch, :post, :put + # @param [Hash] request_options + # the list of options/configurables for the actual request # + # @option request_options [true, false] :sign (default: +true+) + # whether to sign the request using mixlib authentication headers + # # @return [String, Hash] # the response body # - def request(verb, path, data = {}, params = {}) + def request(verb, path, data = {}, params = {}, request_options = {}) log.info "#{verb.to_s.upcase} #{path}..." log.debug "Chef flavor: #{flavor.inspect}" # Build the URI and request object from the given information if [:delete, :get].include?(verb) @@ -228,11 +238,15 @@ request.body = data end end # Sign the request - add_signing_headers(verb, uri.path, request) + if request_options[:sign] == false + log.info "Skipping signed header authentication (user requested)..." + else + add_signing_headers(verb, uri.path, request) + end # Create the HTTP connection object - since the proxy information defaults # to +nil+, we can just pass it to the initializer method instead of doing # crazy strange conditionals. connection = Net::HTTP.new(uri.host, uri.port, @@ -254,10 +268,10 @@ # Naughty, naughty, naughty! Don't blame when when someone hops in # and executes a MITM attack! unless ssl_verify log.warn "Disabling SSL verification..." log.warn "Neither ChefAPI nor the maintainers are responsible for " \ - "damanges incurred as a result of disabling SSL verification. " \ + "damages incurred as a result of disabling SSL verification. " \ "Please use this with extreme caution, or consider specifying " \ "a custom certificate using `config.ssl_pem_file'." connection.verify_mode = OpenSSL::SSL::VERIFY_NONE end end