chef-api 0.8.0 → 0.10.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/lib/chef-api.rb +19 -20
  3. data/lib/chef-api/aclable.rb +35 -0
  4. data/lib/chef-api/authentication.rb +23 -25
  5. data/lib/chef-api/configurable.rb +14 -14
  6. data/lib/chef-api/connection.rb +68 -67
  7. data/lib/chef-api/defaults.rb +25 -24
  8. data/lib/chef-api/error_collection.rb +1 -1
  9. data/lib/chef-api/errors.rb +3 -3
  10. data/lib/chef-api/log.rb +7 -0
  11. data/lib/chef-api/multipart.rb +17 -17
  12. data/lib/chef-api/resource.rb +17 -15
  13. data/lib/chef-api/resources/base.rb +22 -22
  14. data/lib/chef-api/resources/client.rb +5 -3
  15. data/lib/chef-api/resources/collection_proxy.rb +4 -3
  16. data/lib/chef-api/resources/cookbook.rb +2 -2
  17. data/lib/chef-api/resources/cookbook_version.rb +1 -1
  18. data/lib/chef-api/resources/data_bag.rb +4 -4
  19. data/lib/chef-api/resources/data_bag_item.rb +2 -3
  20. data/lib/chef-api/resources/environment.rb +1 -1
  21. data/lib/chef-api/resources/group.rb +15 -0
  22. data/lib/chef-api/resources/node.rb +11 -8
  23. data/lib/chef-api/resources/organization.rb +2 -2
  24. data/lib/chef-api/resources/partial_search.rb +4 -4
  25. data/lib/chef-api/resources/principal.rb +1 -1
  26. data/lib/chef-api/resources/role.rb +2 -1
  27. data/lib/chef-api/resources/search.rb +6 -6
  28. data/lib/chef-api/resources/user.rb +3 -3
  29. data/lib/chef-api/util.rb +8 -8
  30. data/lib/chef-api/validator.rb +3 -3
  31. data/lib/chef-api/validators/base.rb +3 -3
  32. data/lib/chef-api/validators/required.rb +1 -1
  33. data/lib/chef-api/validators/type.rb +1 -1
  34. data/lib/chef-api/version.rb +1 -1
  35. metadata +25 -58
  36. data/.gitignore +0 -21
  37. data/.travis.yml +0 -18
  38. data/CHANGELOG.md +0 -63
  39. data/Gemfile +0 -12
  40. data/README.md +0 -352
  41. data/Rakefile +0 -11
  42. data/chef-api.gemspec +0 -25
  43. data/spec/integration/resources/client_spec.rb +0 -62
  44. data/spec/integration/resources/environment_spec.rb +0 -8
  45. data/spec/integration/resources/node_spec.rb +0 -8
  46. data/spec/integration/resources/partial_search_spec.rb +0 -23
  47. data/spec/integration/resources/role_spec.rb +0 -8
  48. data/spec/integration/resources/search_spec.rb +0 -21
  49. data/spec/integration/resources/user_spec.rb +0 -8
  50. data/spec/spec_helper.rb +0 -32
  51. data/spec/support/chef_server.rb +0 -198
  52. data/spec/support/cookbook.tar.gz +0 -0
  53. data/spec/support/shared/chef_api_resource.rb +0 -91
  54. data/spec/support/user.pem +0 -27
  55. data/spec/unit/authentication_spec.rb +0 -70
  56. data/spec/unit/defaults_spec.rb +0 -60
  57. data/spec/unit/errors_spec.rb +0 -294
  58. data/spec/unit/resources/base_spec.rb +0 -49
  59. data/spec/unit/resources/client_spec.rb +0 -53
  60. data/spec/unit/resources/connection_spec.rb +0 -53
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2bcf51b085093e35d5a5530be9c9a9cd0cf39f6d1ff91a926ae1cdd769728a47
4
- data.tar.gz: b625563e99b004213a2d122639cf056a1865ca53d5068b2f935f08595589f12e
3
+ metadata.gz: d924ca79422311f6742cb0c5a247faec5384e9dce483e09137011053edcd0e0b
4
+ data.tar.gz: b712903d1f9081794bb836ce4d2109a903fa53ea1ff99b337b91192cef9a16cd
5
5
  SHA512:
6
- metadata.gz: abc470931db747708c4f10b42c5481a0648e671f9121468cedad898b6305444f7e4131e8104c6ef49d168bdcb57dee5a36a5e4adc1d5c471627d430530f27d81
7
- data.tar.gz: 25baa85de8cc2c1145028c83b61bc8cbaf53a9ef994e22676c334befcee145f9c715e52e4f94bc2d8943fdd4b37df83918071a96ab18931557b423715303b161
6
+ metadata.gz: a16fd64fa33993a05a5e2e28dbfa98558103417ba2ea2d6f75743d4ed3bc1e4d6d626ba9b130ecf655d3142185da45a420e126152f44f67c8477dd1c412f998a
7
+ data.tar.gz: 5c2f16382bb8086d9998f3f20edcac97df9600459b4c18f06e74b82c003c161f4c980875a8f3be9c098f4794779d5a571e32041acac6f65b891ba9061f784af8
@@ -1,21 +1,21 @@
1
- require 'json'
2
- require 'logify'
3
- require 'pathname'
4
- require 'chef-api/version'
1
+ require "json"
2
+ require "pathname"
3
+ require_relative "chef-api/log"
4
+ require_relative "chef-api/version"
5
5
 
6
6
  module ChefAPI
7
- autoload :Authentication, 'chef-api/authentication'
8
- autoload :Boolean, 'chef-api/boolean'
9
- autoload :Configurable, 'chef-api/configurable'
10
- autoload :Connection, 'chef-api/connection'
11
- autoload :Defaults, 'chef-api/defaults'
12
- autoload :Error, 'chef-api/errors'
13
- autoload :ErrorCollection, 'chef-api/error_collection'
14
- autoload :Multipart, 'chef-api/multipart'
15
- autoload :Resource, 'chef-api/resource'
16
- autoload :Schema, 'chef-api/schema'
17
- autoload :Util, 'chef-api/util'
18
- autoload :Validator, 'chef-api/validator'
7
+ autoload :Authentication, "chef-api/authentication"
8
+ autoload :Boolean, "chef-api/boolean"
9
+ autoload :Configurable, "chef-api/configurable"
10
+ autoload :Connection, "chef-api/connection"
11
+ autoload :Defaults, "chef-api/defaults"
12
+ autoload :Error, "chef-api/errors"
13
+ autoload :ErrorCollection, "chef-api/error_collection"
14
+ autoload :Multipart, "chef-api/multipart"
15
+ autoload :Resource, "chef-api/resource"
16
+ autoload :Schema, "chef-api/schema"
17
+ autoload :Util, "chef-api/util"
18
+ autoload :Validator, "chef-api/validator"
19
19
 
20
20
  #
21
21
  # @todo Document this and why it's important
@@ -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
  #
@@ -54,7 +54,7 @@ module ChefAPI
54
54
  # @return [Pathname]
55
55
  #
56
56
  def root
57
- @root ||= Pathname.new(File.expand_path('../../', __FILE__))
57
+ @root ||= Pathname.new(File.expand_path("../../", __FILE__))
58
58
  end
59
59
 
60
60
  #
@@ -93,4 +93,3 @@ end
93
93
 
94
94
  # Load the initial default values
95
95
  ChefAPI.setup
96
-
@@ -0,0 +1,35 @@
1
+ module ChefAPI
2
+ module AclAble
3
+ def acl_path
4
+ resource_path + "/_acl"
5
+ end
6
+
7
+ def load_acl
8
+ data = self.class.connection.get(acl_path)
9
+ # make deep copy
10
+ @orig_acl_data = Marshal.load(Marshal.dump(data))
11
+ data.freeze
12
+ @acl = data
13
+ end
14
+
15
+ def acl
16
+ unless @acl
17
+ load_acl
18
+ end
19
+ @acl
20
+ end
21
+
22
+ def save!
23
+ super
24
+ if @acl != @orig_acl_data
25
+ %w{create update grant read delete}.each { |action|
26
+ if @acl[action] != @orig_acl_data[action]
27
+ url = "#{acl_path}/#{action}"
28
+ self.class.connection.put(url, { action => @acl[action] }.to_json)
29
+ end
30
+ }
31
+ end
32
+ end
33
+ end
34
+
35
+ end
@@ -1,7 +1,7 @@
1
- require 'base64'
2
- require 'digest'
3
- require 'openssl'
4
- require 'time'
1
+ require "base64"
2
+ require "digest"
3
+ require "openssl"
4
+ require "time"
5
5
 
6
6
  #
7
7
  # DEBUG steps:
@@ -11,20 +11,19 @@ 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.
18
17
  SIGN_FULL_BODY = false
19
18
 
20
- SIGNATURE = 'algorithm=sha1;version=1.0;'.freeze
19
+ SIGNATURE = "algorithm=sha1;version=1.0;".freeze
21
20
 
22
21
  # Headers
23
- X_OPS_SIGN = 'X-Ops-Sign'.freeze
24
- X_OPS_USERID = 'X-Ops-Userid'.freeze
25
- X_OPS_TIMESTAMP = 'X-Ops-Timestamp'.freeze
26
- X_OPS_CONTENT_HASH = 'X-Ops-Content-Hash'.freeze
27
- X_OPS_AUTHORIZATION = 'X-Ops-Authorization'.freeze
22
+ X_OPS_SIGN = "X-Ops-Sign".freeze
23
+ X_OPS_USERID = "X-Ops-Userid".freeze
24
+ X_OPS_TIMESTAMP = "X-Ops-Timestamp".freeze
25
+ X_OPS_CONTENT_HASH = "X-Ops-Content-Hash".freeze
26
+ X_OPS_AUTHORIZATION = "X-Ops-Authorization".freeze
28
27
 
29
28
  class << self
30
29
  #
@@ -96,9 +95,9 @@ module ChefAPI
96
95
  #
97
96
  def headers
98
97
  {
99
- X_OPS_SIGN => SIGNATURE,
100
- X_OPS_USERID => @user,
101
- X_OPS_TIMESTAMP => canonical_timestamp,
98
+ X_OPS_SIGN => SIGNATURE,
99
+ X_OPS_USERID => @user,
100
+ X_OPS_TIMESTAMP => canonical_timestamp,
102
101
  X_OPS_CONTENT_HASH => content_hash,
103
102
  }.merge(signature_lines)
104
103
  end
@@ -114,7 +113,7 @@ module ChefAPI
114
113
  return @content_hash if @content_hash
115
114
 
116
115
  if SIGN_FULL_BODY
117
- @content_hash = hash(@body || '').chomp
116
+ @content_hash = hash(@body || "").chomp
118
117
  else
119
118
  if @body.is_a?(Multipart::MultiIO)
120
119
  filepart = @body.ios.find { |io| io.is_a?(Multipart::MultiIO) }
@@ -122,7 +121,7 @@ module ChefAPI
122
121
 
123
122
  @content_hash = hash(file).chomp
124
123
  else
125
- @content_hash = hash(@body || '').chomp
124
+ @content_hash = hash(@body || "").chomp
126
125
  end
127
126
  end
128
127
 
@@ -148,29 +147,28 @@ 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!"
155
- raise 'No private key given!'
153
+ ChefAPI::Log.warn "No private key given!"
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
- elsif @key =~ /(.+)\.pem$/ || File.exists?(File.expand_path(@key))
162
- log.debug "Detected private key is the path to a file"
160
+ elsif @key =~ /(.+)\.pem$/ || File.exist?(File.expand_path(@key))
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
 
170
169
  @canonical_key
171
170
  end
172
171
 
173
-
174
172
  #
175
173
  # The canonical path, with duplicate and trailing slashes removed. This
176
174
  # value is then hashed.
@@ -181,7 +179,7 @@ module ChefAPI
181
179
  # @return [String]
182
180
  #
183
181
  def canonical_path
184
- @canonical_path ||= hash(@path.squeeze('/').gsub(/(\/)+$/,'')).chomp
182
+ @canonical_path ||= hash(@path.squeeze("/").gsub(%r{(/)+$}, "")).chomp
185
183
  end
186
184
 
187
185
  #
@@ -11,20 +11,20 @@ module ChefAPI
11
11
  # @return [Array<Symbol>]
12
12
  #
13
13
  def keys
14
- @keys ||= [
15
- :endpoint,
16
- :flavor,
17
- :client,
18
- :key,
19
- :proxy_address,
20
- :proxy_password,
21
- :proxy_port,
22
- :proxy_username,
23
- :ssl_pem_file,
24
- :ssl_verify,
25
- :user_agent,
26
- :read_timeout,
27
- ]
14
+ @keys ||= %i{
15
+ endpoint
16
+ flavor
17
+ client
18
+ key
19
+ proxy_address
20
+ proxy_password
21
+ proxy_port
22
+ proxy_username
23
+ ssl_pem_file
24
+ ssl_verify
25
+ user_agent
26
+ read_timeout
27
+ }
28
28
  end
29
29
  end
30
30
 
@@ -1,7 +1,7 @@
1
- require 'net/http'
2
- require 'net/https'
3
- require 'openssl'
4
- require 'uri'
1
+ require "net/http"
2
+ require "net/https"
3
+ require "openssl"
4
+ require "uri"
5
5
 
6
6
  module ChefAPI
7
7
  #
@@ -34,20 +34,21 @@ module ChefAPI
34
34
  end
35
35
  end
36
36
 
37
- include Logify
38
37
  include ChefAPI::Configurable
39
38
 
40
- proxy :clients, 'Resource::Client'
41
- proxy :cookbooks, 'Resource::Cookbook'
42
- proxy :data_bags, 'Resource::DataBag'
43
- proxy :environments, 'Resource::Environment'
44
- proxy :nodes, 'Resource::Node'
45
- proxy :partial_search, 'Resource::PartialSearch'
46
- proxy :principals, 'Resource::Principal'
47
- proxy :roles, 'Resource::Role'
48
- proxy :search, 'Resource::Search'
49
- proxy :users, 'Resource::User'
50
- proxy :organizations, 'Resource::Organization'
39
+ proxy :clients, "Resource::Client"
40
+ proxy :cookbooks, "Resource::Cookbook"
41
+ proxy :data_bags, "Resource::DataBag"
42
+ proxy :data_bag_item, "Resource::DataBagItem"
43
+ proxy :environments, "Resource::Environment"
44
+ proxy :groups, "Resource::Group"
45
+ proxy :nodes, "Resource::Node"
46
+ proxy :partial_search, "Resource::PartialSearch"
47
+ proxy :principals, "Resource::Principal"
48
+ proxy :roles, "Resource::Role"
49
+ proxy :search, "Resource::Search"
50
+ proxy :users, "Resource::User"
51
+ proxy :organizations, "Resource::Organization"
51
52
 
52
53
  #
53
54
  # Create a new ChefAPI Connection with the given options. Any options
@@ -73,9 +74,9 @@ module ChefAPI
73
74
  # Use any options given, but fall back to the defaults set on the module
74
75
  ChefAPI::Configurable.keys.each do |key|
75
76
  value = if options[key].nil?
76
- ChefAPI.instance_variable_get(:"@#{key}")
77
- else
78
- options[key]
77
+ ChefAPI.instance_variable_get(:"@#{key}")
78
+ else
79
+ options[key]
79
80
  end
80
81
 
81
82
  instance_variable_set(:"@#{key}", value)
@@ -196,11 +197,11 @@ module ChefAPI
196
197
  # the response body
197
198
  #
198
199
  def request(verb, path, data = {}, params = {}, request_options = {})
199
- log.info "#{verb.to_s.upcase} #{path}..."
200
- log.debug "Chef flavor: #{flavor.inspect}"
200
+ ChefAPI::Log.info "#{verb.to_s.upcase} #{path}..."
201
+ ChefAPI::Log.debug "Chef flavor: #{flavor.inspect}"
201
202
 
202
203
  # Build the URI and request object from the given information
203
- if [:delete, :get].include?(verb)
204
+ if %i{delete get}.include?(verb)
204
205
  uri = build_uri(verb, path, data)
205
206
  else
206
207
  uri = build_uri(verb, path, params)
@@ -211,38 +212,38 @@ module ChefAPI
211
212
  add_request_headers(request)
212
213
 
213
214
  # Setup PATCH/POST/PUT
214
- if [:patch, :post, :put].include?(verb)
215
+ if %i{patch post put}.include?(verb)
215
216
  if data.respond_to?(:read)
216
- log.info "Detected file/io presence"
217
+ ChefAPI::Log.info "Detected file/io presence"
217
218
  request.body_stream = data
218
219
  elsif data.is_a?(Hash)
219
220
  # If any of the values in the hash are File-like, assume this is a
220
221
  # multi-part post
221
222
  if data.values.any? { |value| value.respond_to?(:read) }
222
- log.info "Detected multipart body"
223
+ ChefAPI::Log.info "Detected multipart body"
223
224
 
224
225
  multipart = Multipart::Body.new(data)
225
226
 
226
- log.debug "Content-Type: #{multipart.content_type}"
227
- 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}"
228
229
 
229
230
  request.content_length = multipart.content_length
230
231
  request.content_type = multipart.content_type
231
232
 
232
233
  request.body_stream = multipart.stream
233
234
  else
234
- log.info "Detected form data"
235
+ ChefAPI::Log.info "Detected form data"
235
236
  request.form_data = data
236
237
  end
237
238
  else
238
- log.info "Detected regular body"
239
+ ChefAPI::Log.info "Detected regular body"
239
240
  request.body = data
240
241
  end
241
242
  end
242
243
 
243
244
  # Sign the request
244
245
  if request_options[:sign] == false
245
- log.info "Skipping signed header authentication (user requested)..."
246
+ ChefAPI::Log.info "Skipping signed header authentication (user requested)..."
246
247
  else
247
248
  add_signing_headers(verb, uri.path, request)
248
249
  end
@@ -259,7 +260,7 @@ module ChefAPI
259
260
  connection.read_timeout = read_timeout if read_timeout
260
261
 
261
262
  # Apply SSL, if applicable
262
- if uri.scheme == 'https'
263
+ if uri.scheme == "https"
263
264
  # Turn on SSL
264
265
  connection.use_ssl = true
265
266
 
@@ -274,8 +275,8 @@ module ChefAPI
274
275
  # Naughty, naughty, naughty! Don't blame when when someone hops in
275
276
  # and executes a MITM attack!
276
277
  unless ssl_verify
277
- log.warn "Disabling SSL verification..."
278
- 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 " \
279
280
  "damages incurred as a result of disabling SSL verification. " \
280
281
  "Please use this with extreme caution, or consider specifying " \
281
282
  "a custom certificate using `config.ssl_pem_file'."
@@ -288,13 +289,13 @@ module ChefAPI
288
289
  connection.start do |http|
289
290
  response = http.request(request)
290
291
 
291
- log.debug "Raw response:"
292
- log.debug response.body
292
+ ChefAPI::Log.debug "Raw response:"
293
+ ChefAPI::Log.debug response.body
293
294
 
294
295
  case response
295
296
  when Net::HTTPRedirection
296
- redirect = URI.parse(response['location']).to_s
297
- log.debug "Performing HTTP redirect to #{redirect}"
297
+ redirect = URI.parse(response["location"]).to_s
298
+ ChefAPI::Log.debug "Performing HTTP redirect to #{redirect}"
298
299
  request(verb, redirect, data)
299
300
  when Net::HTTPSuccess
300
301
  success(response)
@@ -303,7 +304,7 @@ module ChefAPI
303
304
  end
304
305
  end
305
306
  rescue SocketError, Errno::ECONNREFUSED, EOFError
306
- log.warn "Unable to reach the Chef Server"
307
+ ChefAPI::Log.warn "Unable to reach the Chef Server"
307
308
  raise Error::HTTPServerUnavailable.new
308
309
  end
309
310
 
@@ -326,14 +327,14 @@ module ChefAPI
326
327
  # @return [URI]
327
328
  #
328
329
  def build_uri(verb, path, params = {})
329
- log.info "Building URI..."
330
+ ChefAPI::Log.info "Building URI..."
330
331
 
331
332
  # Add any query string parameters
332
333
  if querystring = to_query_string(params)
333
- log.debug "Detected verb deserves a querystring"
334
- log.debug "Building querystring using #{params.inspect}"
335
- log.debug "Compiled querystring is #{querystring.inspect}"
336
- path = [path, querystring].compact.join('?')
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}"
337
+ path = [path, querystring].compact.join("?")
337
338
  end
338
339
 
339
340
  # Parse the URI
@@ -341,8 +342,8 @@ module ChefAPI
341
342
 
342
343
  # Don't merge absolute URLs
343
344
  unless uri.absolute?
344
- log.debug "Detected URI is relative"
345
- log.debug "Appending #{path} to #{endpoint}"
345
+ ChefAPI::Log.debug "Detected URI is relative"
346
+ ChefAPI::Log.debug "Appending #{path} to #{endpoint}"
346
347
  uri = URI.parse(File.join(endpoint, path))
347
348
  end
348
349
 
@@ -376,7 +377,7 @@ module ChefAPI
376
377
  def to_query_string(hash)
377
378
  hash.map do |key, value|
378
379
  "#{URI.escape(key.to_s)}=#{URI.escape(value.to_s)}"
379
- end.join('&')[/.+/]
380
+ end.join("&")[/.+/]
380
381
  end
381
382
 
382
383
  private
@@ -393,15 +394,15 @@ module ChefAPI
393
394
  # the parsed response, as an object
394
395
  #
395
396
  def success(response)
396
- log.info "Parsing response as success..."
397
+ ChefAPI::Log.info "Parsing response as success..."
397
398
 
398
- case response['Content-Type']
399
+ case response["Content-Type"]
399
400
  when /json/
400
- log.debug "Detected response as JSON"
401
- log.debug "Parsing response body as JSON"
401
+ ChefAPI::Log.debug "Detected response as JSON"
402
+ ChefAPI::Log.debug "Parsing response body as JSON"
402
403
  JSON.parse(response.body)
403
404
  else
404
- log.debug "Detected response as text/plain"
405
+ ChefAPI::Log.debug "Detected response as text/plain"
405
406
  response.body
406
407
  end
407
408
  end
@@ -414,15 +415,15 @@ module ChefAPI
414
415
  # the response object from the request
415
416
  #
416
417
  def error(response)
417
- log.info "Parsing response as error..."
418
+ ChefAPI::Log.info "Parsing response as error..."
418
419
 
419
- case response['Content-Type']
420
+ case response["Content-Type"]
420
421
  when /json/
421
- log.debug "Detected error response as JSON"
422
- 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"
423
424
  message = JSON.parse(response.body)
424
425
  else
425
- log.debug "Detected response as text/plain"
426
+ ChefAPI::Log.debug "Detected response as text/plain"
426
427
  message = response.body
427
428
  end
428
429
 
@@ -454,19 +455,19 @@ module ChefAPI
454
455
  # @param [Net::HTTP::Request] request
455
456
  #
456
457
  def add_request_headers(request)
457
- log.info "Adding request headers..."
458
+ ChefAPI::Log.info "Adding request headers..."
458
459
 
459
460
  headers = {
460
- 'Accept' => 'application/json',
461
- 'Content-Type' => 'application/json',
462
- 'Connection' => 'keep-alive',
463
- 'Keep-Alive' => '30',
464
- 'User-Agent' => user_agent,
465
- 'X-Chef-Version' => '11.4.0',
461
+ "Accept" => "application/json",
462
+ "Content-Type" => "application/json",
463
+ "Connection" => "keep-alive",
464
+ "Keep-Alive" => "30",
465
+ "User-Agent" => user_agent,
466
+ "X-Chef-Version" => "11.4.0",
466
467
  }
467
468
 
468
469
  headers.each do |key, value|
469
- log.debug "#{key}: #{value}"
470
+ ChefAPI::Log.debug "#{key}: #{value}"
470
471
  request[key] = value
471
472
  end
472
473
  end
@@ -482,18 +483,18 @@ module ChefAPI
482
483
  # @param [Net::HTTP::Request] request
483
484
  #
484
485
  def add_signing_headers(verb, path, request)
485
- log.info "Adding signed header authentication..."
486
+ ChefAPI::Log.info "Adding signed header authentication..."
486
487
 
487
488
  authentication = Authentication.from_options(
488
489
  user: client,
489
490
  key: key,
490
491
  verb: verb,
491
492
  path: path,
492
- body: request.body || request.body_stream,
493
+ body: request.body || request.body_stream
493
494
  )
494
495
 
495
496
  authentication.headers.each do |key, value|
496
- log.debug "#{key}: #{value}"
497
+ ChefAPI::Log.debug "#{key}: #{value}"
497
498
  request[key] = value
498
499
  end
499
500