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: Improve reporting service for different outputs #24

Merged
merged 8 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,18 @@ func execute(cmd *cobra.Command, args []string) {

for _, item := range items {
secrets := secrets.Detect(item.Content)
report.Results[item.ID] = append(report.Results[item.ID], secrets...)
if len(secrets) > 0 {
joaopedrocsilva marked this conversation as resolved.
Show resolved Hide resolved
report.TotalSecretsFound = report.TotalSecretsFound + len(secrets)
report.Results[item.ID] = append(report.Results[item.ID], secrets...)
}
}
report.TotalItemsScanned = len(items)

// -------------------------------------
// Show Report

reporting.ShowReport(report)
if len(items) > 0 {
reporting.ShowReport(report)
} else {
log.Info().Msg("no plugin was loaded")
cx-monicac marked this conversation as resolved.
Show resolved Hide resolved
cx-monicac marked this conversation as resolved.
Show resolved Hide resolved
}
}
1 change: 1 addition & 0 deletions plugins/confluence.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func (p *ConfluencePlugin) Initialize(cmd *cobra.Command) error {
flags := cmd.Flags()
confluenceUrl, _ := flags.GetString(argConfluence)
if confluenceUrl == "" {
log.Info().Msg("no confluence url was given")
cx-monicac marked this conversation as resolved.
Show resolved Hide resolved
return nil
}

Expand Down
10 changes: 7 additions & 3 deletions reporting/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ func ShowReport(report Report) {
fmt.Println("Summary:")
fmt.Printf("- Total items scanned: %d\n", report.TotalItemsScanned)
fmt.Printf("- Total items with secrets: %d\n", len(report.Results))
fmt.Println("Detailed Report:")
generateResultsReport(report.Results)
if len(report.Results) > 0 {
fmt.Printf("- Total secrets found: %d\n", report.TotalSecretsFound)
fmt.Println("Detailed Report:")
generateResultsReport(report.Results)
}

}

Expand All @@ -22,7 +25,7 @@ func generateResultsReport(results map[string][]Secret) {
fmt.Println(" - Secrets:")
for _, secret := range secrets {
fmt.Printf(" - Type: %s\n", secret.Description)
fmt.Printf(" - Location: %d-%d\n", secret.StartLine, secret.EndLine)
fmt.Printf(" - Location: %d-%d\n", secret.StartColumn, secret.EndColumn)
fmt.Printf(" - Value: %.40s\n", secret.Value)
}
}
Expand All @@ -37,6 +40,7 @@ func getItemId(fullPath string) string {
type Report struct {
Results map[string][]Secret
TotalItemsScanned int
TotalSecretsFound int
}

type Secret struct {
Expand Down
20 changes: 18 additions & 2 deletions reporting/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,25 @@ import (
)

func TestAddSecretToFile(t *testing.T) {
secretValue := "-----BEGIN RSA PRIVATE KEY-----\nMIICWwIBAAKBgQCKLwIHewTIhcpH3WLnxZ61xBAk2lnkdahFxjHYi+khrENzbGr8\nEeJDZ1FMUDDYGeLtjlROLHT41ovicFbsmgIU0QQVFewIAwvKIw5hBtq0TtO9CsXe\nBaNmzw8ZduXJ/clOpdOF7/1ro485a+v956ZAhB2ohbk6qRqGyg3kaxclOQIDAQAB\nAoGAV7z5QN6vbtLkWTUMc7VazHas+Xla0mCSc5sgUyqi4CqMuWEBnQON8tZLHHVe\nThhBqixRA0HfE5DGSQSjbJ9s6fD+Sjt0Qj2yer70FuEiR0uGM4tOAE7WbX+Ny7PT\ngmDiWOITe7v0yzIgZzbLgPhg5SlCmiy8Nv2Zf/v54yLVPLECQQDbwpsuu6beMDip\nkRB/msCAEEAstdfSPY8L9QySYxskkJvtWpWBu5trnRatiGoLYWvnsBzcL4xWGrs8\nTpr4hTirAkEAoPiRDHrVbkKAgrmLW/TrSDiOG8uXSTuvz4iFgzCG6Cd8bp7mDKhJ\nl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pdNGjI4kLWvZwJAJt8Qnbc2ZfS0ianwphoOdB0EwOMKNygjnYx7VoqR9/h1
4Xgur9w/aLZrLM3DSatR+kL+cVTyDTtgCt9Dc8k48Q==
-----END RSA PRIVATE KEY-----`)

results := map[string][]Secret{}
report := Report{results, 1}
report := Report{results, 1, 1}
secret := Secret{Description: "bla", StartLine: 0, StartColumn: 0, EndLine: 0, EndColumn: 0, Value: secretValue}
source := "directory\\rawStringAsFile.txt"

Expand Down
3 changes: 0 additions & 3 deletions secrets/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package secrets

import (
"github.com/checkmarx/2ms/reporting"
"github.com/rs/zerolog/log"
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/rules"
"github.com/zricethezav/gitleaks/v8/config"
"github.com/zricethezav/gitleaks/v8/detect"
Expand Down Expand Up @@ -69,8 +68,6 @@ func (s *Secrets) Detect(content string) []reporting.Secret {
secrets = append(secrets, secret)
}

log.Info().Msgf("Total of %d secrets detected", len(secrets))

return secrets
}

Expand Down