Skip to content
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

Merged
merged 5 commits into from
Nov 1, 2016
Merged

fix reporting files #134

merged 5 commits into from
Nov 1, 2016

Conversation

vjeffrey
Copy link

@vjeffrey vjeffrey commented Oct 29, 2016

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

Victoria Jeffrey added 2 commits October 31, 2016 09:53
@vjeffrey vjeffrey force-pushed the vj/fix-reporting-files branch from c274de7 to 3b24a95 Compare October 31, 2016 13:53
@vjeffrey vjeffrey changed the title wip: fix reporting files fix reporting files Oct 31, 2016
@vjeffrey vjeffrey force-pushed the vj/fix-reporting-files branch 6 times, most recently from 5d76566 to bfed2f2 Compare October 31, 2016 16:01
Signed-off-by: Victoria Jeffrey <vjeffrey@chef.io>
@vjeffrey vjeffrey force-pushed the vj/fix-reporting-files branch from bfed2f2 to d544e1e Compare October 31, 2016 16:27
## 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
Copy link
Contributor

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

@vjeffrey vjeffrey force-pushed the vj/fix-reporting-files branch 2 times, most recently from edda32d to 3c453b5 Compare October 31, 2016 21:20
Signed-off-by: Victoria Jeffrey <vjeffrey@chef.io>
@vjeffrey vjeffrey force-pushed the vj/fix-reporting-files branch from 3c453b5 to 0b466bc Compare October 31, 2016 21:29
@vjeffrey
Copy link
Author

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 :)

@chris-rock
Copy link
Contributor

@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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe just [reporters]

Copy link
Author

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|
Copy link
Contributor

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'
Copy link
Contributor

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.

Copy link
Author

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)
Copy link
Contributor

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...

Copy link
Author

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>
@vjeffrey vjeffrey force-pushed the vj/fix-reporting-files branch from 48beadc to ad07cfa Compare November 1, 2016 11:07
@vjeffrey
Copy link
Author

vjeffrey commented Nov 1, 2016

@chris-rock updated

@chris-rock
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@chris-rock
Copy link
Contributor

Awesome work @vjeffrey

@chris-rock chris-rock merged commit 5628f4e into master Nov 1, 2016
@chris-rock chris-rock deleted the vj/fix-reporting-files branch November 1, 2016 11:18
@chris-rock chris-rock added this to the 2.0 milestone Nov 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

JSON file reporter
3 participants