chef-infra-api 0.10.2 → 0.10.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/chef-api.rb +3 -3
- data/lib/chef-api/authentication.rb +5 -6
- data/lib/chef-api/connection.rb +33 -34
- data/lib/chef-api/log.rb +7 -0
- data/lib/chef-api/version.rb +1 -1
- metadata +14 -7
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: bfaf820214bff244dc5bbb0141182eeabd4ff439253b7a927657f147ca9eac85
         | 
| 4 | 
            +
              data.tar.gz: 00711733d13ca6c69da8e13394f5843756939e7c2b2c1bd4e19404ae70864bcc
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 374c0aab76e5adea28152eada7c80898e3655e901bf10c29a681b40b45613968ba16e62065b7e242b2d54070645f9b760d6acdd374227999f3b88755408f52bf
         | 
| 7 | 
            +
              data.tar.gz: 57f70faea407c62265676ec1cf1ee67d3f35a73d7446ca85105b3129a37824bb00a9707aa34ec997fccc30706d61a6e2c29cf5eaa887575a88f08bf0db1e8746
         | 
    
        data/lib/chef-api.rb
    CHANGED
    
    | @@ -1,6 +1,6 @@ | |
| 1 1 | 
             
            require "json"
         | 
| 2 | 
            -
            require "logify"
         | 
| 3 2 | 
             
            require "pathname"
         | 
| 3 | 
            +
            require_relative "chef-api/log"
         | 
| 4 4 | 
             
            require_relative "chef-api/version"
         | 
| 5 5 |  | 
| 6 6 | 
             
            module ChefAPI
         | 
| @@ -35,7 +35,7 @@ module ChefAPI | |
| 35 35 | 
             
                #   the log level to set
         | 
| 36 36 | 
             
                #
         | 
| 37 37 | 
             
                def log_level=(level)
         | 
| 38 | 
            -
                   | 
| 38 | 
            +
                  ChefAPI::Log.level = level
         | 
| 39 39 | 
             
                end
         | 
| 40 40 |  | 
| 41 41 | 
             
                #
         | 
| @@ -44,7 +44,7 @@ module ChefAPI | |
| 44 44 | 
             
                # @return [Symbol]
         | 
| 45 45 | 
             
                #
         | 
| 46 46 | 
             
                def log_level
         | 
| 47 | 
            -
                   | 
| 47 | 
            +
                  ChefAPI::Log.level
         | 
| 48 48 | 
             
                end
         | 
| 49 49 |  | 
| 50 50 | 
             
                #
         | 
| @@ -11,7 +11,6 @@ require "time" | |
| 11 11 |  | 
| 12 12 | 
             
            module ChefAPI
         | 
| 13 13 | 
             
              class Authentication
         | 
| 14 | 
            -
                include Logify
         | 
| 15 14 |  | 
| 16 15 | 
             
                # @todo: Enable this in the future when Mixlib::Authentication supports
         | 
| 17 16 | 
             
                # signing the full request body instead of just the uploaded file parameter.
         | 
| @@ -148,22 +147,22 @@ module ChefAPI | |
| 148 147 | 
             
                def canonical_key
         | 
| 149 148 | 
             
                  return @canonical_key if @canonical_key
         | 
| 150 149 |  | 
| 151 | 
            -
                   | 
| 150 | 
            +
                  ChefAPI::Log.info "Parsing private key..."
         | 
| 152 151 |  | 
| 153 152 | 
             
                  if @key.nil?
         | 
| 154 | 
            -
                     | 
| 153 | 
            +
                    ChefAPI::Log.warn "No private key given!"
         | 
| 155 154 | 
             
                    raise "No private key given!"
         | 
| 156 155 | 
             
                  end
         | 
| 157 156 |  | 
| 158 157 | 
             
                  if @key.is_a?(OpenSSL::PKey::RSA)
         | 
| 159 | 
            -
                     | 
| 158 | 
            +
                    ChefAPI::Log.debug "Detected private key is an OpenSSL Ruby object"
         | 
| 160 159 | 
             
                    @canonical_key = @key
         | 
| 161 160 | 
             
                  elsif @key =~ /(.+)\.pem$/ || File.exist?(File.expand_path(@key))
         | 
| 162 | 
            -
                     | 
| 161 | 
            +
                    ChefAPI::Log.debug "Detected private key is the path to a file"
         | 
| 163 162 | 
             
                    contents = File.read(File.expand_path(@key))
         | 
| 164 163 | 
             
                    @canonical_key = OpenSSL::PKey::RSA.new(contents)
         | 
| 165 164 | 
             
                  else
         | 
| 166 | 
            -
                     | 
| 165 | 
            +
                    ChefAPI::Log.debug "Detected private key was the literal string key"
         | 
| 167 166 | 
             
                    @canonical_key = OpenSSL::PKey::RSA.new(@key)
         | 
| 168 167 | 
             
                  end
         | 
| 169 168 |  | 
    
        data/lib/chef-api/connection.rb
    CHANGED
    
    | @@ -34,7 +34,6 @@ module ChefAPI | |
| 34 34 | 
             
                  end
         | 
| 35 35 | 
             
                end
         | 
| 36 36 |  | 
| 37 | 
            -
                include Logify
         | 
| 38 37 | 
             
                include ChefAPI::Configurable
         | 
| 39 38 |  | 
| 40 39 | 
             
                proxy :clients,        "Resource::Client"
         | 
| @@ -198,8 +197,8 @@ module ChefAPI | |
| 198 197 | 
             
                #   the response body
         | 
| 199 198 | 
             
                #
         | 
| 200 199 | 
             
                def request(verb, path, data = {}, params = {}, request_options = {})
         | 
| 201 | 
            -
                   | 
| 202 | 
            -
                   | 
| 200 | 
            +
                  ChefAPI::Log.info  "#{verb.to_s.upcase} #{path}..."
         | 
| 201 | 
            +
                  ChefAPI::Log.debug "Chef flavor: #{flavor.inspect}"
         | 
| 203 202 |  | 
| 204 203 | 
             
                  # Build the URI and request object from the given information
         | 
| 205 204 | 
             
                  if %i{delete get}.include?(verb)
         | 
| @@ -215,36 +214,36 @@ module ChefAPI | |
| 215 214 | 
             
                  # Setup PATCH/POST/PUT
         | 
| 216 215 | 
             
                  if %i{patch post put}.include?(verb)
         | 
| 217 216 | 
             
                    if data.respond_to?(:read)
         | 
| 218 | 
            -
                       | 
| 217 | 
            +
                      ChefAPI::Log.info "Detected file/io presence"
         | 
| 219 218 | 
             
                      request.body_stream = data
         | 
| 220 219 | 
             
                    elsif data.is_a?(Hash)
         | 
| 221 220 | 
             
                      # If any of the values in the hash are File-like, assume this is a
         | 
| 222 221 | 
             
                      # multi-part post
         | 
| 223 222 | 
             
                      if data.values.any? { |value| value.respond_to?(:read) }
         | 
| 224 | 
            -
                         | 
| 223 | 
            +
                        ChefAPI::Log.info "Detected multipart body"
         | 
| 225 224 |  | 
| 226 225 | 
             
                        multipart = Multipart::Body.new(data)
         | 
| 227 226 |  | 
| 228 | 
            -
                         | 
| 229 | 
            -
                         | 
| 227 | 
            +
                        ChefAPI::Log.debug "Content-Type: #{multipart.content_type}"
         | 
| 228 | 
            +
                        ChefAPI::Log.debug "Content-Length: #{multipart.content_length}"
         | 
| 230 229 |  | 
| 231 230 | 
             
                        request.content_length = multipart.content_length
         | 
| 232 231 | 
             
                        request.content_type   = multipart.content_type
         | 
| 233 232 |  | 
| 234 233 | 
             
                        request.body_stream    = multipart.stream
         | 
| 235 234 | 
             
                      else
         | 
| 236 | 
            -
                         | 
| 235 | 
            +
                        ChefAPI::Log.info "Detected form data"
         | 
| 237 236 | 
             
                        request.form_data = data
         | 
| 238 237 | 
             
                      end
         | 
| 239 238 | 
             
                    else
         | 
| 240 | 
            -
                       | 
| 239 | 
            +
                      ChefAPI::Log.info "Detected regular body"
         | 
| 241 240 | 
             
                      request.body = data
         | 
| 242 241 | 
             
                    end
         | 
| 243 242 | 
             
                  end
         | 
| 244 243 |  | 
| 245 244 | 
             
                  # Sign the request
         | 
| 246 245 | 
             
                  if request_options[:sign] == false
         | 
| 247 | 
            -
                     | 
| 246 | 
            +
                    ChefAPI::Log.info "Skipping signed header authentication (user requested)..."
         | 
| 248 247 | 
             
                  else
         | 
| 249 248 | 
             
                    add_signing_headers(verb, uri.path, request)
         | 
| 250 249 | 
             
                  end
         | 
| @@ -276,8 +275,8 @@ module ChefAPI | |
| 276 275 | 
             
                    # Naughty, naughty, naughty! Don't blame when when someone hops in
         | 
| 277 276 | 
             
                    # and executes a MITM attack!
         | 
| 278 277 | 
             
                    unless ssl_verify
         | 
| 279 | 
            -
                       | 
| 280 | 
            -
                       | 
| 278 | 
            +
                      ChefAPI::Log.warn "Disabling SSL verification..."
         | 
| 279 | 
            +
                      ChefAPI::Log.warn "Neither ChefAPI nor the maintainers are responsible for " \
         | 
| 281 280 | 
             
                        "damages incurred as a result of disabling SSL verification. " \
         | 
| 282 281 | 
             
                        "Please use this with extreme caution, or consider specifying " \
         | 
| 283 282 | 
             
                        "a custom certificate using `config.ssl_pem_file'."
         | 
| @@ -290,13 +289,13 @@ module ChefAPI | |
| 290 289 | 
             
                  connection.start do |http|
         | 
| 291 290 | 
             
                    response = http.request(request)
         | 
| 292 291 |  | 
| 293 | 
            -
                     | 
| 294 | 
            -
                     | 
| 292 | 
            +
                    ChefAPI::Log.debug "Raw response:"
         | 
| 293 | 
            +
                    ChefAPI::Log.debug response.body
         | 
| 295 294 |  | 
| 296 295 | 
             
                    case response
         | 
| 297 296 | 
             
                    when Net::HTTPRedirection
         | 
| 298 297 | 
             
                      redirect = URI.parse(response["location"]).to_s
         | 
| 299 | 
            -
                       | 
| 298 | 
            +
                      ChefAPI::Log.debug "Performing HTTP redirect to #{redirect}"
         | 
| 300 299 | 
             
                      request(verb, redirect, data)
         | 
| 301 300 | 
             
                    when Net::HTTPSuccess
         | 
| 302 301 | 
             
                      success(response)
         | 
| @@ -305,7 +304,7 @@ module ChefAPI | |
| 305 304 | 
             
                    end
         | 
| 306 305 | 
             
                  end
         | 
| 307 306 | 
             
                rescue SocketError, Errno::ECONNREFUSED, EOFError
         | 
| 308 | 
            -
                   | 
| 307 | 
            +
                  ChefAPI::Log.warn "Unable to reach the Chef Server"
         | 
| 309 308 | 
             
                  raise Error::HTTPServerUnavailable.new
         | 
| 310 309 | 
             
                end
         | 
| 311 310 |  | 
| @@ -328,13 +327,13 @@ module ChefAPI | |
| 328 327 | 
             
                # @return [URI]
         | 
| 329 328 | 
             
                #
         | 
| 330 329 | 
             
                def build_uri(verb, path, params = {})
         | 
| 331 | 
            -
                   | 
| 330 | 
            +
                  ChefAPI::Log.info "Building URI..."
         | 
| 332 331 |  | 
| 333 332 | 
             
                  # Add any query string parameters
         | 
| 334 333 | 
             
                  if querystring = to_query_string(params)
         | 
| 335 | 
            -
                     | 
| 336 | 
            -
                     | 
| 337 | 
            -
                     | 
| 334 | 
            +
                    ChefAPI::Log.debug "Detected verb deserves a querystring"
         | 
| 335 | 
            +
                    ChefAPI::Log.debug "Building querystring using #{params.inspect}"
         | 
| 336 | 
            +
                    ChefAPI::Log.debug "Compiled querystring is #{querystring.inspect}"
         | 
| 338 337 | 
             
                    path = [path, querystring].compact.join("?")
         | 
| 339 338 | 
             
                  end
         | 
| 340 339 |  | 
| @@ -343,8 +342,8 @@ module ChefAPI | |
| 343 342 |  | 
| 344 343 | 
             
                  # Don't merge absolute URLs
         | 
| 345 344 | 
             
                  unless uri.absolute?
         | 
| 346 | 
            -
                     | 
| 347 | 
            -
                     | 
| 345 | 
            +
                    ChefAPI::Log.debug "Detected URI is relative"
         | 
| 346 | 
            +
                    ChefAPI::Log.debug "Appending #{path} to #{endpoint}"
         | 
| 348 347 | 
             
                    uri = URI.parse(File.join(endpoint, path))
         | 
| 349 348 | 
             
                  end
         | 
| 350 349 |  | 
| @@ -395,15 +394,15 @@ module ChefAPI | |
| 395 394 | 
             
                #   the parsed response, as an object
         | 
| 396 395 | 
             
                #
         | 
| 397 396 | 
             
                def success(response)
         | 
| 398 | 
            -
                   | 
| 397 | 
            +
                  ChefAPI::Log.info "Parsing response as success..."
         | 
| 399 398 |  | 
| 400 399 | 
             
                  case response["Content-Type"]
         | 
| 401 400 | 
             
                  when /json/
         | 
| 402 | 
            -
                     | 
| 403 | 
            -
                     | 
| 401 | 
            +
                    ChefAPI::Log.debug "Detected response as JSON"
         | 
| 402 | 
            +
                    ChefAPI::Log.debug "Parsing response body as JSON"
         | 
| 404 403 | 
             
                    JSON.parse(response.body)
         | 
| 405 404 | 
             
                  else
         | 
| 406 | 
            -
                     | 
| 405 | 
            +
                    ChefAPI::Log.debug "Detected response as text/plain"
         | 
| 407 406 | 
             
                    response.body
         | 
| 408 407 | 
             
                  end
         | 
| 409 408 | 
             
                end
         | 
| @@ -416,15 +415,15 @@ module ChefAPI | |
| 416 415 | 
             
                #   the response object from the request
         | 
| 417 416 | 
             
                #
         | 
| 418 417 | 
             
                def error(response)
         | 
| 419 | 
            -
                   | 
| 418 | 
            +
                  ChefAPI::Log.info "Parsing response as error..."
         | 
| 420 419 |  | 
| 421 420 | 
             
                  case response["Content-Type"]
         | 
| 422 421 | 
             
                  when /json/
         | 
| 423 | 
            -
                     | 
| 424 | 
            -
                     | 
| 422 | 
            +
                    ChefAPI::Log.debug "Detected error response as JSON"
         | 
| 423 | 
            +
                    ChefAPI::Log.debug "Parsing error response as JSON"
         | 
| 425 424 | 
             
                    message = JSON.parse(response.body)
         | 
| 426 425 | 
             
                  else
         | 
| 427 | 
            -
                     | 
| 426 | 
            +
                    ChefAPI::Log.debug "Detected response as text/plain"
         | 
| 428 427 | 
             
                    message = response.body
         | 
| 429 428 | 
             
                  end
         | 
| 430 429 |  | 
| @@ -456,7 +455,7 @@ module ChefAPI | |
| 456 455 | 
             
                # @param [Net::HTTP::Request] request
         | 
| 457 456 | 
             
                #
         | 
| 458 457 | 
             
                def add_request_headers(request)
         | 
| 459 | 
            -
                   | 
| 458 | 
            +
                  ChefAPI::Log.info "Adding request headers..."
         | 
| 460 459 |  | 
| 461 460 | 
             
                  headers = {
         | 
| 462 461 | 
             
                    "Accept" => "application/json",
         | 
| @@ -468,7 +467,7 @@ module ChefAPI | |
| 468 467 | 
             
                  }
         | 
| 469 468 |  | 
| 470 469 | 
             
                  headers.each do |key, value|
         | 
| 471 | 
            -
                     | 
| 470 | 
            +
                    ChefAPI::Log.debug "#{key}: #{value}"
         | 
| 472 471 | 
             
                    request[key] = value
         | 
| 473 472 | 
             
                  end
         | 
| 474 473 | 
             
                end
         | 
| @@ -484,7 +483,7 @@ module ChefAPI | |
| 484 483 | 
             
                # @param [Net::HTTP::Request] request
         | 
| 485 484 | 
             
                #
         | 
| 486 485 | 
             
                def add_signing_headers(verb, path, request)
         | 
| 487 | 
            -
                   | 
| 486 | 
            +
                  ChefAPI::Log.info "Adding signed header authentication..."
         | 
| 488 487 |  | 
| 489 488 | 
             
                  authentication = Authentication.from_options(
         | 
| 490 489 | 
             
                    user: client,
         | 
| @@ -495,7 +494,7 @@ module ChefAPI | |
| 495 494 | 
             
                  )
         | 
| 496 495 |  | 
| 497 496 | 
             
                  authentication.headers.each do |key, value|
         | 
| 498 | 
            -
                     | 
| 497 | 
            +
                    ChefAPI::Log.debug "#{key}: #{value}"
         | 
| 499 498 | 
             
                    request[key] = value
         | 
| 500 499 | 
             
                  end
         | 
| 501 500 |  | 
    
        data/lib/chef-api/log.rb
    ADDED
    
    
    
        data/lib/chef-api/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: chef-infra-api
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.10. | 
| 4 | 
            +
              version: 0.10.5
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Seth Vargo
         | 
| @@ -9,22 +9,28 @@ authors: | |
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date:  | 
| 12 | 
            +
            date: 2020-01-29 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 | 
            -
              name:  | 
| 15 | 
            +
              name: mixlib-log
         | 
| 16 16 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 17 17 | 
             
                requirements:
         | 
| 18 | 
            -
                - - " | 
| 18 | 
            +
                - - ">="
         | 
| 19 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 20 | 
            +
                    version: '1'
         | 
| 21 | 
            +
                - - "<"
         | 
| 19 22 | 
             
                  - !ruby/object:Gem::Version
         | 
| 20 | 
            -
                    version: ' | 
| 23 | 
            +
                    version: '4'
         | 
| 21 24 | 
             
              type: :runtime
         | 
| 22 25 | 
             
              prerelease: false
         | 
| 23 26 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 24 27 | 
             
                requirements:
         | 
| 25 | 
            -
                - - " | 
| 28 | 
            +
                - - ">="
         | 
| 29 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 30 | 
            +
                    version: '1'
         | 
| 31 | 
            +
                - - "<"
         | 
| 26 32 | 
             
                  - !ruby/object:Gem::Version
         | 
| 27 | 
            -
                    version: ' | 
| 33 | 
            +
                    version: '4'
         | 
| 28 34 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 29 35 | 
             
              name: mime-types
         | 
| 30 36 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -57,6 +63,7 @@ files: | |
| 57 63 | 
             
            - lib/chef-api/defaults.rb
         | 
| 58 64 | 
             
            - lib/chef-api/error_collection.rb
         | 
| 59 65 | 
             
            - lib/chef-api/errors.rb
         | 
| 66 | 
            +
            - lib/chef-api/log.rb
         | 
| 60 67 | 
             
            - lib/chef-api/multipart.rb
         | 
| 61 68 | 
             
            - lib/chef-api/resource.rb
         | 
| 62 69 | 
             
            - lib/chef-api/resources/base.rb
         |