Improve plain output

This commit is contained in:
Dustin Decker 2022-01-20 09:43:37 -08:00
parent 03ead2f7ed
commit 87357959b7
3 changed files with 38 additions and 3 deletions

1
go.mod
View file

@ -17,6 +17,7 @@ require (
github.com/google/go-github/v41 v41.0.0
github.com/h2non/filetype v1.1.3
github.com/hashicorp/go-retryablehttp v0.7.0
github.com/jeremywohl/flatten v1.0.1
github.com/joho/godotenv v1.4.0
github.com/kylelemons/godebug v1.1.0
github.com/mattn/go-colorable v0.1.12

2
go.sum
View file

@ -258,6 +258,8 @@ github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU=
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
github.com/jeremywohl/flatten v1.0.1 h1:LrsxmB3hfwJuE+ptGOijix1PIfOoKLJ3Uee/mzbgtrs=
github.com/jeremywohl/flatten v1.0.1/go.mod h1:4AmD/VxjWcI5SRB0n6szE2A6s2fsNHDLO0nAlMHgfLQ=
github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=

38
main.go
View file

@ -15,6 +15,7 @@ import (
"github.com/trufflesecurity/trufflehog/pkg/common"
"github.com/trufflesecurity/trufflehog/pkg/decoders"
"github.com/trufflesecurity/trufflehog/pkg/engine"
"github.com/trufflesecurity/trufflehog/pkg/pb/source_metadatapb"
"github.com/trufflesecurity/trufflehog/pkg/sources/git"
)
@ -114,19 +115,50 @@ func main() {
log.Fatal("s3 not implemented")
}
// deal with the results from e.ResultsChan()
stdoutLogger := logrus.New()
stdoutLogger.SetOutput(os.Stdout)
stdoutLogger.SetFormatter(&logrus.TextFormatter{})
for r := range e.ResultsChan() {
type outputFormat struct {
DetectorType string
SourceType string
Verified bool
*source_metadatapb.MetaData
}
output := outputFormat{
DetectorType: r.Result.DetectorType.String(),
SourceType: r.SourceType.String(),
Verified: r.Result.Verified,
MetaData: r.SourceMetadata,
}
if *jsonOut {
// todo - add parity to trufflehog's existing output for git
// source
out, err := json.Marshal(r)
out, err := json.Marshal(output)
if err != nil {
logrus.WithError(err).Fatal("could not marshal result")
}
fmt.Println(string(out))
} else {
fmt.Printf("%+v\n", r)
out, err := structToFields(output)
if err != nil {
logrus.WithError(err).Fatal("could not marshal result")
}
stdoutLogger.WithFields(out).Info("found secret")
}
}
logrus.Infof("scanned %d chunks", e.ChunksScanned())
}
func structToFields(obj interface{}) (fields logrus.Fields, err error) {
data, err := json.Marshal(obj)
if err != nil {
return
}
err = json.Unmarshal(data, &fields)
return
}