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

Add option to filter audit results by severity level #969

Merged
merged 1 commit into from
Jun 28, 2023

Conversation

jslivka
Copy link
Contributor

@jslivka jslivka commented Jun 27, 2023

This PR fixes #

Checklist

  • I have signed the CLA
  • I have updated/added any relevant documentation

Description

To address #754, I've chosen to implement verbosity options for displaying audit results in the same manner as log levels. danger is the least verbose option and will only include results of that severity. warning is the medium verbosity option and will only display results of severity warning or danger. By default, all results will be displayed. This will still function with --only-show-failed-tests and behave as expected.

What's the goal of this PR?

Add verbosity options to the audit subcommand in the polaris CLI

What changes did you make?

Low verbosity (danger)

./polaris audit --audit-path=manifests --severity=danger | wc -l


Want more? Automate Polaris for free with Fairwinds Insights!
🚀 https://fairwinds.com/insights-signup/polaris 🚀
     116

Medium verbosity (warning, also implies inclusion of danger)

/polaris audit --audit-path=manifests --severity=warning | wc -l


Want more? Automate Polaris for free with Fairwinds Insights!
🚀 https://fairwinds.com/insights-signup/polaris 🚀
     268

What alternative solution should we consider, if any?

@fairwinds-insights
Copy link

Fairwinds Insights CI Report

View the Full Report

✅ No new Action Items detected!

1 similar comment
@fairwinds-insights
Copy link

Fairwinds Insights CI Report

View the Full Report

✅ No new Action Items detected!

@jslivka jslivka marked this pull request as ready for review June 27, 2023 21:08
@jslivka jslivka requested a review from vitorvezani June 27, 2023 21:08
Copy link
Contributor

@rbren rbren left a comment

Choose a reason for hiding this comment

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

:awesome:

Comment on lines +60 to +71
resCopy := res
resCopy.Results = []Result{}

filteredResults := funk.Map(res.Results, func(auditDataResult Result) Result {
return auditDataResult.filterResultsBySeverityLevel(severityLevel)
}).([]Result)

for _, result := range filteredResults {
if result.isNotEmpty() {
resCopy.Results = append(resCopy.Results, result)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Man 😓 the structure of the polaris output makes this harder than it should be.

Probably not for this PR, but if we wanted to do other kinds of filtering we could probably create a generic AuditData.filter method that takes in a func(Result) bool, so we only have to define the weird "drill into each result" logic in one place.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes that would be great, have some sort of filter function that takes a predicate

@jslivka jslivka merged commit b0d86cd into master Jun 28, 2023
2 checks passed
@jslivka jslivka deleted the jbs/severity-level-filter branch June 28, 2023 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants