Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
feat:print PAC identifier in verbose mode (#931)
Browse files Browse the repository at this point in the history
  • Loading branch information
Meyazhagan authored May 1, 2023
1 parent 9ba67d4 commit c5ff84d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/evaluation/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,14 +346,17 @@ func parseToPrinterWarnings(results *EvaluationResults, invalidYamlFiles []*extr
for _, ruleUniqueName := range rulesUniqueNames {
rule := rules[ruleUniqueName]
var fixLink string
var PACIdentifier string
if verbose {
fixLink = rule.DocumentationUrl
PACIdentifier = rule.Identifier
}
failedRule := printer.FailedRule{
Name: rule.Name,
DocumentationUrl: fixLink,
Suggestion: rule.MessageOnFailure,
Occurrences: rule.GetFailedOccurrencesCount(),
PACIdentifier: PACIdentifier,
OccurrencesDetails: []printer.OccurrenceDetails{},
}
skippedRule := failedRule
Expand Down
11 changes: 11 additions & 0 deletions pkg/printer/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type FailedRule struct {
Occurrences int
Suggestion string
DocumentationUrl string
PACIdentifier string
OccurrencesDetails []OccurrenceDetails
}

Expand Down Expand Up @@ -177,6 +178,11 @@ func (p *Printer) GetWarningsText(warnings []Warning, quiet bool) string {

sb.WriteString(fmt.Sprintf("%v %v\n", p.Theme.Emoji.Skip, ruleName))

if skippedRule.PACIdentifier != "" {
PACIdentifier := p.Theme.Colors.Cyan.Sprint(skippedRule.PACIdentifier)
sb.WriteString(fmt.Sprintf(" Policy as code identifier: %v\n", PACIdentifier))
}

if skippedRule.DocumentationUrl != "" {
howToFix := p.Theme.Colors.Cyan.Sprint(skippedRule.DocumentationUrl)
sb.WriteString(fmt.Sprintf(" How to fix: %v\n", howToFix))
Expand Down Expand Up @@ -207,6 +213,11 @@ func (p *Printer) GetWarningsText(warnings []Warning, quiet bool) string {

sb.WriteString(fmt.Sprintf("%v %v %v\n", p.Theme.Emoji.Error, ruleName, occurrences))

if failedRule.PACIdentifier != "" {
PACIdentifier := p.Theme.Colors.Cyan.Sprint(failedRule.PACIdentifier)
sb.WriteString(fmt.Sprintf(" Policy as code identifier: %v\n", PACIdentifier))
}

if failedRule.DocumentationUrl != "" {
howToFix := p.Theme.Colors.Cyan.Sprint(failedRule.DocumentationUrl)
sb.WriteString(fmt.Sprintf(" How to fix: %v\n", howToFix))
Expand Down

0 comments on commit c5ff84d

Please sign in to comment.