chef-infra-api 0.9.1 → 0.10.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/chef-api.rb +19 -20
- data/lib/chef-api/aclable.rb +6 -6
- data/lib/chef-api/authentication.rb +23 -25
- data/lib/chef-api/configurable.rb +14 -14
- data/lib/chef-api/connection.rb +69 -70
- data/lib/chef-api/defaults.rb +25 -24
- data/lib/chef-api/error_collection.rb +1 -1
- data/lib/chef-api/errors.rb +3 -3
- data/lib/chef-api/log.rb +7 -0
- data/lib/chef-api/multipart.rb +17 -17
- data/lib/chef-api/resource.rb +17 -17
- data/lib/chef-api/resources/base.rb +25 -23
- data/lib/chef-api/resources/client.rb +4 -3
- data/lib/chef-api/resources/collection_proxy.rb +4 -3
- data/lib/chef-api/resources/cookbook.rb +2 -2
- data/lib/chef-api/resources/cookbook_version.rb +1 -1
- data/lib/chef-api/resources/data_bag.rb +3 -3
- data/lib/chef-api/resources/data_bag_item.rb +2 -3
- data/lib/chef-api/resources/environment.rb +1 -1
- data/lib/chef-api/resources/group.rb +1 -2
- data/lib/chef-api/resources/node.rb +2 -2
- data/lib/chef-api/resources/organization.rb +2 -2
- data/lib/chef-api/resources/partial_search.rb +4 -4
- data/lib/chef-api/resources/principal.rb +1 -1
- data/lib/chef-api/resources/role.rb +1 -1
- data/lib/chef-api/resources/search.rb +6 -6
- data/lib/chef-api/resources/user.rb +5 -3
- data/lib/chef-api/util.rb +8 -8
- data/lib/chef-api/validator.rb +3 -3
- data/lib/chef-api/validators/base.rb +3 -3
- data/lib/chef-api/validators/required.rb +1 -1
- data/lib/chef-api/validators/type.rb +1 -1
- data/lib/chef-api/version.rb +1 -1
- metadata +18 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8ca98919801b5c0d0baf4ef0e2b4523efb24b3ee2aa65e04fc9d5473ec6c373
|
4
|
+
data.tar.gz: eff96d984676e726e4a4c0a5b67b9dca76800a4e373d71b8e50b0e5f0fec9b58
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1647ff4a3dda7b6e8179417cfbb0c7ba1c56cc0707848e8d65ea4046d6c212c3c0c2e4331e2560a9773e64f261b56c35c93a4c8bf3de1a1e98611333719d25ef
|
7
|
+
data.tar.gz: c6f799df264a08315a6688887be7da5a2c5b516e4b24645fc54d22470c3faac7e1669002b6ae286a073efe6a70a0571ade14c63e585c20d9dcab87a412381c32
|
data/lib/chef-api.rb
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
|
4
|
-
|
1
|
+
require "json" unless defined?(JSON)
|
2
|
+
require "pathname" unless defined?(Pathname)
|
3
|
+
require_relative "chef-api/log"
|
4
|
+
require_relative "chef-api/version"
|
5
5
|
|
6
6
|
module ChefAPI
|
7
|
-
autoload :Authentication,
|
8
|
-
autoload :Boolean,
|
9
|
-
autoload :Configurable,
|
10
|
-
autoload :Connection,
|
11
|
-
autoload :Defaults,
|
12
|
-
autoload :Error,
|
13
|
-
autoload :ErrorCollection,
|
14
|
-
autoload :Multipart,
|
15
|
-
autoload :Resource,
|
16
|
-
autoload :Schema,
|
17
|
-
autoload :Util,
|
18
|
-
autoload :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
|
-
|
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
|
#
|
@@ -54,7 +54,7 @@ module ChefAPI
|
|
54
54
|
# @return [Pathname]
|
55
55
|
#
|
56
56
|
def root
|
57
|
-
@root ||= Pathname.new(File.expand_path(
|
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
|
-
|
data/lib/chef-api/aclable.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module ChefAPI
|
2
2
|
module AclAble
|
3
3
|
def acl_path
|
4
|
-
|
4
|
+
resource_path + "/_acl"
|
5
5
|
end
|
6
6
|
|
7
7
|
def load_acl
|
@@ -14,7 +14,7 @@ module ChefAPI
|
|
14
14
|
|
15
15
|
def acl
|
16
16
|
unless @acl
|
17
|
-
|
17
|
+
load_acl
|
18
18
|
end
|
19
19
|
@acl
|
20
20
|
end
|
@@ -22,14 +22,14 @@ module ChefAPI
|
|
22
22
|
def save!
|
23
23
|
super
|
24
24
|
if @acl != @orig_acl_data
|
25
|
-
%w
|
25
|
+
%w{create update grant read delete}.each { |action|
|
26
26
|
if @acl[action] != @orig_acl_data[action]
|
27
|
-
url = "#{
|
28
|
-
self.class.connection.put(url, {action => @acl[action]}.to_json)
|
27
|
+
url = "#{acl_path}/#{action}"
|
28
|
+
self.class.connection.put(url, { action => @acl[action] }.to_json)
|
29
29
|
end
|
30
30
|
}
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require "base64" unless defined?(Base64)
|
2
|
+
require "digest" unless defined?(Digest)
|
3
|
+
require "openssl" unless defined?(OpenSSL)
|
4
|
+
require "time" unless defined?(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 =
|
19
|
+
SIGNATURE = "algorithm=sha1;version=1.0;".freeze
|
21
20
|
|
22
21
|
# Headers
|
23
|
-
X_OPS_SIGN =
|
24
|
-
X_OPS_USERID =
|
25
|
-
X_OPS_TIMESTAMP =
|
26
|
-
X_OPS_CONTENT_HASH =
|
27
|
-
X_OPS_AUTHORIZATION =
|
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
|
100
|
-
X_OPS_USERID
|
101
|
-
X_OPS_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 ||
|
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 ||
|
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
|
-
|
150
|
+
ChefAPI::Log.info "Parsing private key..."
|
152
151
|
|
153
152
|
if @key.nil?
|
154
|
-
|
155
|
-
raise
|
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
|
-
|
158
|
+
ChefAPI::Log.debug "Detected private key is an OpenSSL Ruby object"
|
160
159
|
@canonical_key = @key
|
161
|
-
elsif @key =~ /(.+)\.pem$/ || File.
|
162
|
-
|
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
|
-
|
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(
|
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
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
|
data/lib/chef-api/connection.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require "net/http" unless defined?(Net::HTTP)
|
2
|
+
require "openssl" unless defined?(OpenSSL)
|
3
|
+
require "uri" unless defined?(URI)
|
4
|
+
require "cgi" unless defined?(CGI)
|
5
5
|
|
6
6
|
module ChefAPI
|
7
7
|
#
|
@@ -34,22 +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,
|
41
|
-
proxy :cookbooks,
|
42
|
-
proxy :data_bags,
|
43
|
-
proxy :data_bag_item,
|
44
|
-
proxy :environments,
|
45
|
-
proxy :groups,
|
46
|
-
proxy :nodes,
|
47
|
-
proxy :partial_search,
|
48
|
-
proxy :principals,
|
49
|
-
proxy :roles,
|
50
|
-
proxy :search,
|
51
|
-
proxy :users,
|
52
|
-
proxy :organizations,
|
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"
|
53
52
|
|
54
53
|
#
|
55
54
|
# Create a new ChefAPI Connection with the given options. Any options
|
@@ -75,9 +74,9 @@ module ChefAPI
|
|
75
74
|
# Use any options given, but fall back to the defaults set on the module
|
76
75
|
ChefAPI::Configurable.keys.each do |key|
|
77
76
|
value = if options[key].nil?
|
78
|
-
|
79
|
-
|
80
|
-
|
77
|
+
ChefAPI.instance_variable_get(:"@#{key}")
|
78
|
+
else
|
79
|
+
options[key]
|
81
80
|
end
|
82
81
|
|
83
82
|
instance_variable_set(:"@#{key}", value)
|
@@ -198,11 +197,11 @@ 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
|
-
if
|
204
|
+
if %i{delete get}.include?(verb)
|
206
205
|
uri = build_uri(verb, path, data)
|
207
206
|
else
|
208
207
|
uri = build_uri(verb, path, params)
|
@@ -213,38 +212,38 @@ module ChefAPI
|
|
213
212
|
add_request_headers(request)
|
214
213
|
|
215
214
|
# Setup PATCH/POST/PUT
|
216
|
-
if
|
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
|
@@ -261,7 +260,7 @@ module ChefAPI
|
|
261
260
|
connection.read_timeout = read_timeout if read_timeout
|
262
261
|
|
263
262
|
# Apply SSL, if applicable
|
264
|
-
if uri.scheme ==
|
263
|
+
if uri.scheme == "https"
|
265
264
|
# Turn on SSL
|
266
265
|
connection.use_ssl = true
|
267
266
|
|
@@ -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
|
-
redirect = URI.parse(response[
|
299
|
-
|
297
|
+
redirect = URI.parse(response["location"]).to_s
|
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,14 +327,14 @@ 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
|
-
|
338
|
-
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("?")
|
339
338
|
end
|
340
339
|
|
341
340
|
# Parse the URI
|
@@ -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
|
|
@@ -377,8 +376,8 @@ module ChefAPI
|
|
377
376
|
#
|
378
377
|
def to_query_string(hash)
|
379
378
|
hash.map do |key, value|
|
380
|
-
"#{
|
381
|
-
end.join(
|
379
|
+
"#{CGI.escape(key.to_s)}=#{CGI.escape(value.to_s)}"
|
380
|
+
end.join("&")[/.+/]
|
382
381
|
end
|
383
382
|
|
384
383
|
private
|
@@ -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
|
-
case response[
|
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
|
-
case response[
|
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,19 +455,19 @@ 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
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
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",
|
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,18 +483,18 @@ 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,
|
491
490
|
key: key,
|
492
491
|
verb: verb,
|
493
492
|
path: path,
|
494
|
-
body: request.body || request.body_stream
|
493
|
+
body: request.body || request.body_stream
|
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
|
|