summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPete Higgins <pete@peterhiggins.org>2020-11-30 13:31:24 -0800
committerPete Higgins <pete@peterhiggins.org>2020-12-01 16:12:04 -0800
commit59d5ae6941533799649eeee9b28f46ac010e516e (patch)
tree8d15a13934551be9c8af4aa1262c1ad98b7eab67
parent25e803ad07ae58185ac0f4b858b4acdd0f52a4c8 (diff)
downloadchef-59d5ae6941533799649eeee9b28f46ac010e516e.tar.gz
Replace hardcoded product references with the generic versions.
Signed-off-by: Pete Higgins <pete@peterhiggins.org>
-rw-r--r--lib/chef/audit/fetcher/automate.rb4
-rw-r--r--lib/chef/audit/fetcher/chef_server.rb8
-rw-r--r--lib/chef/audit/reporter/audit_enforcer.rb2
-rw-r--r--lib/chef/audit/reporter/automate.rb11
-rw-r--r--lib/chef/audit/reporter/chef_server_automate.rb11
-rw-r--r--lib/chef/audit/runner.rb12
-rw-r--r--spec/unit/audit/runner_spec.rb2
7 files changed, 24 insertions, 26 deletions
diff --git a/lib/chef/audit/fetcher/automate.rb b/lib/chef/audit/fetcher/automate.rb
index ea13a18389..b68b96b60a 100644
--- a/lib/chef/audit/fetcher/automate.rb
+++ b/lib/chef/audit/fetcher/automate.rb
@@ -51,7 +51,7 @@ class Chef
"No data-collector token set, which is required by the chef-automate fetcher. " \
"Set the `data_collector.token` configuration parameter in your client.rb " \
'or use the "chef-server-automate" reporter which does not require any ' \
- "data-collector settings and uses Chef Server to fetch profiles."
+ "data-collector settings and uses #{ChefUtils::Dist::Server::PRODUCT} to fetch profiles."
end
end
@@ -61,7 +61,7 @@ class Chef
end
def to_s
- "Chef Automate for Chef Solo Fetcher"
+ "#{ChefUtils::Dist::Automate::PRODUCT} for #{ChefUtils::Dist::Solo::PRODUCT} Fetcher"
end
end
end
diff --git a/lib/chef/audit/fetcher/chef_server.rb b/lib/chef/audit/fetcher/chef_server.rb
index f88e4b74ad..d227634ed9 100644
--- a/lib/chef/audit/fetcher/chef_server.rb
+++ b/lib/chef/audit/fetcher/chef_server.rb
@@ -73,7 +73,7 @@ class Chef
if archive.nil?
path = @target.respond_to?(:path) ? @target.path : path
- raise Inspec::FetcherFailure, "Unable to find requested profile on path: '#{path}' on the Automate system."
+ raise Inspec::FetcherFailure, "Unable to find requested profile on path: '#{path}' on the #{ChefUtils::Dist::Automate::PRODUCT} system."
end
Inspec::Log.debug("Archive stored at temporary location: #{archive.path}")
@@ -99,9 +99,9 @@ class Chef
when /404/
Chef::Log.error "Object does not exist on remote server."
when /413/
- Chef::Log.error "You most likely hit the erchef request size in Chef Server that defaults to ~2MB. To increase this limit see audit cookbook TROUBLESHOOTING.md OR https://docs.chef.io/config_rb_server.html"
+ Chef::Log.error "You most likely hit the erchef request size in #{ChefUtils::Dist::Server::PRODUCT} that defaults to ~2MB. To increase this limit see audit cookbook TROUBLESHOOTING.md OR https://docs.chef.io/config_rb_server.html"
when /429/
- Chef::Log.error "This error typically means the data sent was larger than Automate's limit (4 MB). Run InSpec locally to identify any controls producing large diffs."
+ Chef::Log.error "This error typically means the data sent was larger than #{ChefUtils::Dist::Automate::PRODUCT}'s limit (4 MB). Run InSpec locally to identify any controls producing large diffs."
end
msg = "Received HTTP error #{code}"
Chef::Log.error msg
@@ -109,7 +109,7 @@ class Chef
end
def to_s
- "Chef Server/Compliance Profile Loader"
+ "#{ChefUtils::Dist::Server::PRODUCT}/Compliance Profile Loader"
end
CHEF_SERVER_REPORTERS = %w{chef-server chef-server-compliance chef-server-visibility chef-server-automate}.freeze
diff --git a/lib/chef/audit/reporter/audit_enforcer.rb b/lib/chef/audit/reporter/audit_enforcer.rb
index 2ee5e3b1f3..291e72d236 100644
--- a/lib/chef/audit/reporter/audit_enforcer.rb
+++ b/lib/chef/audit/reporter/audit_enforcer.rb
@@ -8,7 +8,7 @@ class Chef
report.fetch(:profiles, []).each do |profile|
profile.fetch(:controls, []).each do |control|
control.fetch(:results, []).each do |result|
- raise ControlFailure, "Audit #{control[:id]} has failed. Aborting chef-client run." if result[:status] == "failed"
+ raise ControlFailure, "Audit #{control[:id]} has failed. Aborting #{ChefUtils::Dist::Infra::CLIENT} run." if result[:status] == "failed"
end
end
end
diff --git a/lib/chef/audit/reporter/automate.rb b/lib/chef/audit/reporter/automate.rb
index 9921faf7b7..f91bbbf1e5 100644
--- a/lib/chef/audit/reporter/automate.rb
+++ b/lib/chef/audit/reporter/automate.rb
@@ -31,7 +31,7 @@ class Chef
# Method used in order to send the inspec report to the data_collector server
def send_report(report)
unless @entity_uuid && @run_id
- Chef::Log.error "entity_uuid(#{@entity_uuid}) or run_id(#{@run_id}) can't be nil, not sending report to Chef Automate"
+ Chef::Log.error "entity_uuid(#{@entity_uuid}) or run_id(#{@run_id}) can't be nil, not sending report to #{ChefUtils::Dist::Automate::PRODUCT}"
return false
end
@@ -57,8 +57,7 @@ class Chef
# Automate GRPC currently has a message limit of ~4MB
# https://github.com/chef/automate/issues/1417#issuecomment-541908157
if json_report.bytesize > 4 * 1024 * 1024
- Chef::Log.warn "Compliance report size is #{(json_report.bytesize / (1024 * 1024.0)).round(2)} MB."
- Chef::Log.warn "Automate has an internal 4MB limit that is not currently configurable."
+ Chef::Log.warn "Generated report size is #{(json_report.bytesize / (1024 * 1024.0)).round(2)} MB. #{ChefUtils::Dist::Automate::PRODUCT} has an internal 4MB limit that is not currently configurable."
end
unless json_report
@@ -67,7 +66,7 @@ class Chef
end
begin
- Chef::Log.info "Report to Chef Automate: #{@url}"
+ Chef::Log.info "Report to #{ChefUtils::Dist::Automate::PRODUCT}: #{@url}"
Chef::Log.debug "Audit Report: #{json_report}"
http_client.post(nil, json_report, headers)
true
@@ -149,13 +148,13 @@ class Chef
# Contacts the metasearch Automate API to check which of the inspec profile sha256 ids
# passed in via `report_shas` are missing from the Automate profiles metadata database.
def missing_automate_profiles(headers, report_shas)
- Chef::Log.debug "Checking the Automate profiles metadata for: #{report_shas}"
+ Chef::Log.debug "Checking the #{ChefUtils::Dist::Automate::PRODUCT} profiles metadata for: #{report_shas}"
meta_url = URI(@url)
meta_url.path = "/compliance/profiles/metasearch"
response_str = http_client(meta_url.to_s).post(nil, "{\"sha256\": #{report_shas}}", headers)
missing_shas = Chef::JSONCompat.parse(response_str)["missing_sha256"]
unless missing_shas.empty?
- Chef::Log.info "Automate is missing metadata for the following profile ids: #{missing_shas}"
+ Chef::Log.info "#{ChefUtils::Dist::Automate::PRODUCT} is missing metadata for the following profile ids: #{missing_shas}"
end
missing_shas
rescue => e
diff --git a/lib/chef/audit/reporter/chef_server_automate.rb b/lib/chef/audit/reporter/chef_server_automate.rb
index c8053a4ddf..afd8c617b1 100644
--- a/lib/chef/audit/reporter/chef_server_automate.rb
+++ b/lib/chef/audit/reporter/chef_server_automate.rb
@@ -29,7 +29,7 @@ class Chef
def send_report(report)
unless @entity_uuid && @run_id
- Chef::Log.error "entity_uuid(#{@entity_uuid}) or run_id(#{@run_id}) can't be nil, not sending report to Chef Automate"
+ Chef::Log.error "entity_uuid(#{@entity_uuid}) or run_id(#{@run_id}) can't be nil, not sending report to #{ChefUtils::Dist::Automate::PRODUCT}"
return false
end
@@ -38,11 +38,10 @@ class Chef
report_size = Chef::JSONCompat.to_json(automate_report, validate_utf8: false).bytesize
# this is set to slightly less than the oc_erchef limit
if report_size > 900 * 1024
- Chef::Log.warn "Compliance report size is #{(report_size / (1024 * 1024.0)).round(2)} MB."
- Chef::Log.warn "Infra Server < 13.0 defaults to a limit of ~1MB, 13.0+ defaults to a limit of ~2MB."
+ Chef::Log.warn "Generated report size is #{(report_size / (1024 * 1024.0)).round(2)} MB. #{ChefUtils::Dist::Server::PRODUCT} < 13.0 defaults to a limit of ~1MB, 13.0+ defaults to a limit of ~2MB."
end
- Chef::Log.info "Report to Chef Automate via Chef Server: #{@url}"
+ Chef::Log.info "Report to #{ChefUtils::Dist::Automate::PRODUCT} via #{ChefUtils::Dist::Server::PRODUCT}: #{@url}"
with_http_rescue do
http_client.post(@url, automate_report)
return true
@@ -79,9 +78,9 @@ class Chef
when /404/
Chef::Log.error "Object does not exist on remote server."
when /413/
- Chef::Log.error "You most likely hit the erchef request size in Chef Server that defaults to ~2MB. To increase this limit see audit cookbook TROUBLESHOOTING.md OR https://docs.chef.io/config_rb_server.html"
+ Chef::Log.error "You most likely hit the erchef request size in #{ChefUtils::Dist::Server::PRODUCT} that defaults to ~2MB. To increase this limit see audit cookbook TROUBLESHOOTING.md OR https://docs.chef.io/config_rb_server.html"
when /429/
- Chef::Log.error "This error typically means the data sent was larger than Automate's limit (4 MB). Run InSpec locally to identify any controls producing large diffs."
+ Chef::Log.error "This error typically means the data sent was larger than #{ChefUtils::Dist::Automate::PRODUCT}'s limit (4 MB). Run InSpec locally to identify any controls producing large diffs."
end
msg = "Received HTTP error #{code}"
Chef::Log.error msg
diff --git a/lib/chef/audit/runner.rb b/lib/chef/audit/runner.rb
index 02e4e64b04..0d5e05d905 100644
--- a/lib/chef/audit/runner.rb
+++ b/lib/chef/audit/runner.rb
@@ -18,7 +18,7 @@ class Chef
def enabled?
audit_cookbook_present = recipes.include?("audit::default")
- logger.info("#{self.class}##{__method__}: inspec profiles? #{inspec_profiles.any?}")
+ logger.info("#{self.class}##{__method__}: #{Inspec::Dist::PRODUCT_NAME} profiles? #{inspec_profiles.any?}")
logger.info("#{self.class}##{__method__}: audit cookbook? #{audit_cookbook_present}")
inspec_profiles.any? && !audit_cookbook_present
@@ -75,7 +75,7 @@ class Chef
if deprecated_config_values.any?
values = deprecated_config_values.sort.map { |v| "'#{v}'" }.join(", ")
- logger.warn "audit-cookbook config values #{values} are not supported in Chef Infra's audit mode."
+ logger.warn "audit-cookbook config values #{values} are not supported in #{ChefUtils::Dist::Infra::PRODUCT}'s audit mode."
end
end
@@ -111,7 +111,7 @@ class Chef
# TODO: Custom exception class here?
unless profiles.respond_to?(:map) && profiles.all? { |_, p| p.respond_to?(:transform_keys) && p.respond_to?(:update) }
- raise "Inspec profiles specified in an unrecognized format, expected a hash of hashes."
+ raise "#{Inspec::Dist::PRODUCT_NAME} profiles specified in an unrecognized format, expected a hash of hashes."
end
profiles.map do |name, profile|
@@ -159,7 +159,7 @@ class Chef
# In case InSpec raises a runtime exception without providing a valid report,
# we make one up and add two new fields to it: `status` and `status_message`
def failed_report(err)
- logger.error "InSpec has raised a runtime exception. Generating a minimal failed report."
+ logger.error "#{Inspec::Dist::PRODUCT_NAME} has raised a runtime exception. Generating a minimal failed report."
logger.error err
{
"platform": {
@@ -233,7 +233,7 @@ class Chef
}
Chef::Audit::Reporter::ChefServer.new(opts).send_report(report)
else
- logger.warn "unable to determine chef-server url required by inspec report collector '#{reporter}'. Skipping..."
+ logger.warn "Unable to determine #{ChefUtils::Dist::Server::PRODUCT} url required by #{Inspec::Dist::PRODUCT_NAME} report collector '#{reporter}'. Skipping..."
end
when "json-file"
path = node["audit"]["json_file"]["location"]
@@ -242,7 +242,7 @@ class Chef
when "audit-enforcer"
Chef::Audit::Reporter::AuditEnforcer.new.send_report(report)
else
- logger.warn "#{reporter} is not a supported InSpec report collector"
+ logger.warn "#{reporter} is not a supported #{Inspec::Dist::PRODUCT_NAME} report collector"
end
end
end
diff --git a/spec/unit/audit/runner_spec.rb b/spec/unit/audit/runner_spec.rb
index 56ea247d95..7e62ffa398 100644
--- a/spec/unit/audit/runner_spec.rb
+++ b/spec/unit/audit/runner_spec.rb
@@ -85,7 +85,7 @@ describe Chef::Audit::Runner do
},
]
- expect { runner.inspec_profiles }.to raise_error(/Inspec profiles specified in an unrecognized format, expected a hash of hashes./)
+ expect { runner.inspec_profiles }.to raise_error(/profiles specified in an unrecognized format, expected a hash of hashes./)
end
end