chef-infra-api 0.10.2 → 0.10.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0e7529a9909181d5243fbd14738a245a4085da4218280f8bc37257b720c10dbd
4
- data.tar.gz: 151bc6f26f6d83c97fa9b2455bfe524984c56009abbccd196e7d19a610250331
3
+ metadata.gz: bfaf820214bff244dc5bbb0141182eeabd4ff439253b7a927657f147ca9eac85
4
+ data.tar.gz: 00711733d13ca6c69da8e13394f5843756939e7c2b2c1bd4e19404ae70864bcc
5
5
  SHA512:
6
- metadata.gz: b84a9c599cb2944fcbacfa88083f9f41947f5ea7dcd2f32cd4010ff886dfc85bb2b73affc6b670467e13195f6856879d46429013b68609f5efe29f5047dc526b
7
- data.tar.gz: 05015b9d844d6f9e2c76d52e08a9cb793953416e0aed3f241c0abcb343b5209d9fa375f73c49c9dece739dfec32452914405a1fedd9cc3a47a1a469bad26df8e
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
- Logify.level = level
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
- Logify.level
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
- log.info "Parsing private key..."
150
+ ChefAPI::Log.info "Parsing private key..."
152
151
 
153
152
  if @key.nil?
154
- log.warn "No private key given!"
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
- log.debug "Detected private key is an OpenSSL Ruby object"
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
- log.debug "Detected private key is the path to a file"
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
- log.debug "Detected private key was the literal string key"
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
 
@@ -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
- log.info "#{verb.to_s.upcase} #{path}..."
202
- log.debug "Chef flavor: #{flavor.inspect}"
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
- log.info "Detected file/io presence"
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
- log.info "Detected multipart body"
223
+ ChefAPI::Log.info "Detected multipart body"
225
224
 
226
225
  multipart = Multipart::Body.new(data)
227
226
 
228
- log.debug "Content-Type: #{multipart.content_type}"
229
- log.debug "Content-Length: #{multipart.content_length}"
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
- log.info "Detected form data"
235
+ ChefAPI::Log.info "Detected form data"
237
236
  request.form_data = data
238
237
  end
239
238
  else
240
- log.info "Detected regular body"
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
- log.info "Skipping signed header authentication (user requested)..."
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
- log.warn "Disabling SSL verification..."
280
- log.warn "Neither ChefAPI nor the maintainers are responsible for " \
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
- log.debug "Raw response:"
294
- log.debug response.body
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
- log.debug "Performing HTTP redirect to #{redirect}"
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
- log.warn "Unable to reach the Chef Server"
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
- log.info "Building URI..."
330
+ ChefAPI::Log.info "Building URI..."
332
331
 
333
332
  # Add any query string parameters
334
333
  if querystring = to_query_string(params)
335
- log.debug "Detected verb deserves a querystring"
336
- log.debug "Building querystring using #{params.inspect}"
337
- log.debug "Compiled querystring is #{querystring.inspect}"
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
- log.debug "Detected URI is relative"
347
- log.debug "Appending #{path} to #{endpoint}"
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
- log.info "Parsing response as success..."
397
+ ChefAPI::Log.info "Parsing response as success..."
399
398
 
400
399
  case response["Content-Type"]
401
400
  when /json/
402
- log.debug "Detected response as JSON"
403
- log.debug "Parsing response body as JSON"
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
- log.debug "Detected response as text/plain"
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
- log.info "Parsing response as error..."
418
+ ChefAPI::Log.info "Parsing response as error..."
420
419
 
421
420
  case response["Content-Type"]
422
421
  when /json/
423
- log.debug "Detected error response as JSON"
424
- log.debug "Parsing error response as JSON"
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
- log.debug "Detected response as text/plain"
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
- log.info "Adding request headers..."
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
- log.debug "#{key}: #{value}"
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
- log.info "Adding signed header authentication..."
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
- log.debug "#{key}: #{value}"
497
+ ChefAPI::Log.debug "#{key}: #{value}"
499
498
  request[key] = value
500
499
  end
501
500
 
@@ -0,0 +1,7 @@
1
+ require "mixlib/log"
2
+
3
+ module ChefAPI
4
+ class Log
5
+ extend Mixlib::Log
6
+ end
7
+ end
@@ -1,3 +1,3 @@
1
1
  module ChefAPI
2
- VERSION = "0.10.2".freeze
2
+ VERSION = "0.10.5".freeze
3
3
  end
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.2
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: 2019-12-21 00:00:00.000000000 Z
12
+ date: 2020-01-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: logify
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: '0.1'
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: '0.1'
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