summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPete Higgins <pete@peterhiggins.org>2020-11-23 17:31:49 -0800
committerPete Higgins <pete@peterhiggins.org>2020-12-01 16:12:04 -0800
commit647123ac6e1972551e33bb83be4fe059337d6a94 (patch)
treea22570f31839c7d211294cc067795057c0cae58c
parenta71e2caee77c44a77b7ce358cbcfe6f157f2a059 (diff)
downloadchef-647123ac6e1972551e33bb83be4fe059337d6a94.tar.gz
Stop saving inspec json reports relative to where the cookbook is.
Signed-off-by: Pete Higgins <pete@peterhiggins.org>
-rw-r--r--lib/chef/audit/default_attributes.rb11
-rw-r--r--lib/chef/audit/reporter/json_file.rb2
2 files changed, 9 insertions, 4 deletions
diff --git a/lib/chef/audit/default_attributes.rb b/lib/chef/audit/default_attributes.rb
index 7c71d07eaf..a55c0da4e6 100644
--- a/lib/chef/audit/default_attributes.rb
+++ b/lib/chef/audit/default_attributes.rb
@@ -14,6 +14,7 @@
# limitations under the License.
require "chef/node/attribute_collections" # for VividMash
+require "chef/util/path_helper"
class Chef
module Audit
@@ -53,10 +54,12 @@ class Chef
"json_file" => {
# The location of the json-file output:
- # <chef_cache_path>/cookbooks/audit/inspec-<timestamp>.json
- # TODO: ^^ comment is wrong
- # TODO: Does this path work?
- "location" => File.expand_path(Time.now.utc.strftime("../../../inspec-%Y%m%d%H%M%S.json"), __dir__),
+ # <chef_cache_path>/audit_reports/audit-<timestamp>.json
+ "location" => Chef::Util::PathHelper.join(
+ Chef::Config[:cache_path],
+ "audit_reports",
+ Time.now.utc.strftime("audit-%Y%m%d%H%M%S.json")
+ ),
},
# Control results that have a `run_time` below this limit will
diff --git a/lib/chef/audit/reporter/json_file.rb b/lib/chef/audit/reporter/json_file.rb
index 7eccea216a..e570189df7 100644
--- a/lib/chef/audit/reporter/json_file.rb
+++ b/lib/chef/audit/reporter/json_file.rb
@@ -9,6 +9,8 @@ class Chef
end
def send_report(report)
+ FileUtils.mkdir_p(File.dirname(@path), mode: 0700)
+
File.write(@path, Chef::JSONCompat.to_json(report))
end
end