chef 16.8.9 → 16.8.14

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: c13a95870faf2ddc93377295ea1821d3ee962c422af54147a9a5852266ef9abc
4
- data.tar.gz: 06d9ed38997dd63cef3a9d54cf7ffb064c5ca13b668cbea8ee42173ba757d880
3
+ metadata.gz: 6124227fa2dd345401b335be52a9d261458f5d8fe7a75de8478f66e2c4f9a493
4
+ data.tar.gz: a0ce3f48fe7d680d1fe36f69684e20efbacf7ee4ce20ff7adeb7f251a002b25a
5
5
  SHA512:
6
- metadata.gz: ed8ed48612596fdd94dfab56edda9b66ba3adff6bcca4475bf4d4a9b5ab9dc51f59b3db9d54aa6f468ab33aa4a8f2821a5ab9942379c0d70f641a04f8bfb48d0
7
- data.tar.gz: 8f1ebbbdbfe60ed00c66edab06a41821f5d8e9f62ab74d4c322b187b75e4f894e0f59cdf90c61b034a8496ece30e0a6eb71c3c91336a40e966fb6f9001e26d9a
6
+ metadata.gz: 208c095249a456996ea54930f11bad6d6402c3a47208c1bf62eaff0eed6e9bc54783cd2af48f92885ab1bd34dcdc5e58863bbd3bce9badb57ea1cecb571b113d
7
+ data.tar.gz: 053ae58aa1d72aa1bdede2fe27d6bfb5cd4d56e0123fe0d52e6fed5ac7478847741476e8fbb18da8f530a9639a057d9e0ad27f3845606572511de3c7c17639bb
@@ -7,6 +7,8 @@ class Chef
7
7
  # Used to send inspec reports to Chef Automate server via Chef Server
8
8
  #
9
9
  class ChefServerAutomate < Chef::Compliance::Reporter::Automate
10
+ attr_reader :url
11
+
10
12
  def initialize(opts)
11
13
  @entity_uuid = opts[:entity_uuid]
12
14
  @run_id = opts[:run_id]
@@ -178,6 +178,8 @@ class Chef
178
178
 
179
179
  # extracts relevant node data
180
180
  def node_info
181
+ chef_server_uri = URI(Chef::Config[:chef_server_url])
182
+
181
183
  runlist_roles = node.run_list.select { |item| item.type == :role }.map(&:name)
182
184
  runlist_recipes = node.run_list.select { |item| item.type == :recipe }.map(&:name)
183
185
  {
@@ -199,52 +201,61 @@ class Chef
199
201
  }
200
202
  end
201
203
 
202
- def send_report(reporter, report)
203
- logger.info "Reporting to #{reporter}"
204
+ def send_report(reporter_type, report)
205
+ logger.info "Reporting to #{reporter_type}"
206
+
207
+ reporter = reporter(reporter_type)
204
208
 
205
- insecure = node["audit"]["insecure"]
206
- run_time_limit = node["audit"]["run_time_limit"]
207
- control_results_limit = node["audit"]["control_results_limit"]
209
+ reporter.send_report(report) if reporter
210
+ end
208
211
 
209
- case reporter
212
+ def reporter(reporter_type)
213
+ case reporter_type
210
214
  when "chef-automate"
211
215
  opts = {
216
+ control_results_limit: node["audit"]["control_results_limit"],
212
217
  entity_uuid: node["chef_guid"],
213
- run_id: run_id,
218
+ insecure: node["audit"]["insecure"],
214
219
  node_info: node_info,
215
- insecure: insecure,
216
- run_time_limit: run_time_limit,
217
- control_results_limit: control_results_limit,
220
+ run_id: run_id,
221
+ run_time_limit: node["audit"]["run_time_limit"],
218
222
  }
219
- Chef::Compliance::Reporter::Automate.new(opts).send_report(report)
223
+ Chef::Compliance::Reporter::Automate.new(opts)
220
224
  when "chef-server-automate"
221
- chef_url = node["audit"]["server"] || base_chef_server_url
222
- chef_org = Chef::Config[:chef_server_url].split("/").last
223
- if chef_url
224
- url = construct_url(chef_url, File.join("organizations", chef_org, "data-collector"))
225
- opts = {
226
- entity_uuid: node["chef_guid"],
227
- run_id: run_id,
228
- node_info: node_info,
229
- insecure: insecure,
230
- url: url,
231
- run_time_limit: run_time_limit,
232
- control_results_limit: control_results_limit,
233
- }
234
- Chef::Compliance::Reporter::ChefServer.new(opts).send_report(report)
235
- else
236
- logger.warn "Unable to determine #{ChefUtils::Dist::Server::PRODUCT} url required by #{Inspec::Dist::PRODUCT_NAME} report collector '#{reporter}'. Skipping..."
237
- end
225
+ opts = {
226
+ control_results_limit: node["audit"]["control_results_limit"],
227
+ entity_uuid: node["chef_guid"],
228
+ insecure: node["audit"]["insecure"],
229
+ node_info: node_info,
230
+ run_id: run_id,
231
+ run_time_limit: node["audit"]["run_time_limit"],
232
+ url: chef_server_automate_url,
233
+ }
234
+ Chef::Compliance::Reporter::ChefServerAutomate.new(opts)
238
235
  when "json-file"
239
236
  path = node["audit"]["json_file"]["location"]
240
237
  logger.info "Writing compliance report to #{path}"
241
- Chef::Compliance::Reporter::JsonFile.new(file: path).send_report(report)
238
+ Chef::Compliance::Reporter::JsonFile.new(file: path)
242
239
  when "audit-enforcer"
243
- Chef::Compliance::Reporter::ComplianceEnforcer.new.send_report(report)
240
+ Chef::Compliance::Reporter::ComplianceEnforcer.new
244
241
  else
245
- logger.warn "#{reporter} is not a supported #{Inspec::Dist::PRODUCT_NAME} report collector"
242
+ raise "'#{reporter_type}' is not a supported reporter for Compliance Phase."
246
243
  end
247
244
  end
245
+
246
+ def chef_server_automate_url
247
+ url = if node["audit"]["server"]
248
+ URI(node["audit"]["server"])
249
+ else
250
+ URI(Chef::Config[:chef_server_url]).tap do |u|
251
+ u.path = ""
252
+ end
253
+ end
254
+
255
+ org = Chef::Config[:chef_server_url].split("/").last
256
+ url.path = File.join(url.path, "organizations/#{org}/data-collector")
257
+ url
258
+ end
248
259
  end
249
260
  end
250
261
  end
@@ -385,6 +385,8 @@ class Chef
385
385
  end
386
386
 
387
387
  ch.on_extended_data do |_, _type, data|
388
+ raise ArgumentError if data.eql?("sudo: no tty present and no askpass program specified\n")
389
+
388
390
  stderr += data
389
391
  end
390
392
 
@@ -23,7 +23,7 @@ require_relative "version_string"
23
23
 
24
24
  class Chef
25
25
  CHEF_ROOT = File.expand_path("..", __dir__)
26
- VERSION = Chef::VersionString.new("16.8.9")
26
+ VERSION = Chef::VersionString.new("16.8.14")
27
27
  end
28
28
 
29
29
  #
@@ -110,4 +110,31 @@ describe Chef::Compliance::Runner do
110
110
  runner.warn_for_deprecated_config_values!
111
111
  end
112
112
  end
113
+
114
+ describe "#reporter" do
115
+ context "chef-server-automate reporter" do
116
+ it "uses the correct URL when 'server' attribute is set" do
117
+ Chef::Config[:chef_server_url] = "https://chef_config_url.example.com/my_org"
118
+ node.normal["audit"]["server"] = "https://server_attribute_url.example.com/application/sub_application"
119
+
120
+ reporter = runner.reporter("chef-server-automate")
121
+
122
+ expect(reporter).to be_kind_of(Chef::Compliance::Reporter::ChefServerAutomate)
123
+ expect(reporter.url).to eq(URI("https://server_attribute_url.example.com/application/sub_application/organizations/my_org/data-collector"))
124
+ end
125
+
126
+ it "falls back to chef_server_url for URL when 'server' attribute is not set" do
127
+ Chef::Config[:chef_server_url] = "https://chef_config_url.example.com/my_org"
128
+
129
+ reporter = runner.reporter("chef-server-automate")
130
+
131
+ expect(reporter).to be_kind_of(Chef::Compliance::Reporter::ChefServerAutomate)
132
+ expect(reporter.url).to eq(URI("https://chef_config_url.example.com/organizations/my_org/data-collector"))
133
+ end
134
+ end
135
+
136
+ it "fails with unexpected reporter value" do
137
+ expect { runner.reporter("tacos") }.to raise_error(/'tacos' is not a supported reporter for Compliance Phase/)
138
+ end
139
+ end
113
140
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef
3
3
  version: !ruby/object:Gem::Version
4
- version: 16.8.9
4
+ version: 16.8.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Jacob
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-10 00:00:00.000000000 Z
11
+ date: 2020-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef-config
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 16.8.9
19
+ version: 16.8.14
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 16.8.9
26
+ version: 16.8.14
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: chef-utils
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 16.8.9
33
+ version: 16.8.14
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 16.8.9
40
+ version: 16.8.14
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: train-core
43
43
  requirement: !ruby/object:Gem::Requirement