-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix reporting files #134
fix reporting files #134
Conversation
ee68c33
to
c274de7
Compare
Signed-off-by: Victoria Jeffrey <vjeffrey@chef.io>
c274de7
to
3b24a95
Compare
5d76566
to
bfed2f2
Compare
Signed-off-by: Victoria Jeffrey <vjeffrey@chef.io>
bfed2f2
to
d544e1e
Compare
## Write to file | ||
|
||
If you would like to write the json report to a file on disk, you can enable the write to file attribute. | ||
Note: If write to file is enabled, interval timing may not be enabled. This is because when we write |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we just touch a file to change its timestamp? Interval handling should not depend on json reporter
edda32d
to
3c453b5
Compare
Signed-off-by: Victoria Jeffrey <vjeffrey@chef.io>
3c453b5
to
0b466bc
Compare
i know we said we werent' doing multiple reporters yet, but while i was refactoring i thought i could try an idea really quick, and it worked....if we just set the collector as an array, we can stick a line in the audit report after load needed dependencies/before login to compliance that iterates through the collectors....i'm gonna push up a commit with that work in a bit, just in case we decide we want to enable that functionality. can always drop the commit if we dont :) |
@vjeffrey Sounds great. It should not hurt to support that |
return reporters if reporters.is_a? Array | ||
new_array = [] | ||
new_array.push(reporters) | ||
new_array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe just [reporters]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, ha! silly me :)
# ensure authentication for Chef Compliance is in place | ||
login_to_compliance(server, user, token, refresh_token) if reporter == 'chef-compliance' | ||
# iterate through reporters | ||
reporters.each do |reporter| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would be perfect to iterate only over send_report(reporter, server, user, profiles)
, but we need json-min
for Chef Compliance ... so it looks like we need to iterate over the scan as well for now
end | ||
|
||
def write_to_file(report, profiles, timestamp) | ||
filename = extract_profile_names(profiles) << '-' << timestamp << '.json' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would just use inspec-timestamp.json
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
file.close | ||
content | ||
# returns string of profile names separated with underscore | ||
def extract_profile_names(profiles) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we do not need this function...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Signed-off-by: Victoria Jeffrey <vjeffrey@chef.io>
48beadc
to
ad07cfa
Compare
@chris-rock updated |
nice @vjeffrey |
tests = tests_for_runner(profiles) | ||
tests.each { |target| runner.add_target(target, opts) } | ||
|
||
Chef::Log.info "Running tests from: #{tests.inspect}" | ||
runner.run | ||
runner.report.to_json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
Awesome work @vjeffrey |
This commit changes the default behavior to save the json report to a variable that we send over to the collector.
It also enables writing the json report to a file if the interval settings are enabled or the user sets the new default attribute write to file to true
In #126 it was specified that the filename we write to should be created with name and timestamp... this is being done when the write_to_file attribute is set to true, but not when the interval is enabled (for filename-matching purposes)
fixes #126 & #132
also does some cleanup