Skip to content

Commit

Permalink
Add summary line to secret scan (#1167)
Browse files Browse the repository at this point in the history
  • Loading branch information
johannesHarness authored and Harness committed Mar 29, 2024
1 parent e4db4dc commit 594cb3b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
2 changes: 0 additions & 2 deletions app/api/controller/githook/pre_receive_scan_secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ func (c *Controller) scanSecrets(

// pretty print output
printScanSecretsFindings(output, scanResult.findings)
output.Messages = append(output.Messages, "", "")
output.Error = ptr.String("Changes blocked by security scan results")

return nil
}
Expand Down
21 changes: 19 additions & 2 deletions app/api/controller/githook/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,24 @@ import (
"github.com/harness/gitness/git/hook"

"github.com/fatih/color"
"github.com/gotidy/ptr"
)

var (
colorScanHeaderFound = color.New(color.BgRed, color.FgHiWhite, color.Bold)
colorScanHeader = color.New(color.BgRed, color.FgHiWhite, color.Bold)
colorScanSummary = color.New(color.FgHiRed, color.Bold)
)

func printScanSecretsFindings(out *hook.Output, findings []api.Finding) {
findingsCnt := len(findings)
out.Messages = append(
out.Messages,
colorScanHeaderFound.Sprintf(
colorScanHeader.Sprintf(
" Detected leaked %s ",
stringSecretOrSecrets(findingsCnt > 1),
),
)

for _, finding := range findings {
out.Messages = append(
out.Messages,
Expand Down Expand Up @@ -63,6 +66,20 @@ func printScanSecretsFindings(out *hook.Output, findings []api.Finding) {
"",
)
}

out.Messages = append(out.Messages, "")

out.Messages = append(
out.Messages,
colorScanSummary.Sprintf(
"%d %s found",
findingsCnt,
stringSecretOrSecrets(findingsCnt > 1),
),
)

// block the commit
out.Error = ptr.String("Changes blocked by security scan results")
}

func stringSecretOrSecrets(plural bool) string {
Expand Down

0 comments on commit 594cb3b

Please sign in to comment.