Find, verify, and analyze leaked credentials
Go credentialsdevsecopsdynamic-analysisprecommitscanningsecretsecret-managementsecretssecuritysecurity-toolstrufflehogverification
Improve plain output
Dustin Decker87357959b7d1
diff --git a/go.mod b/go.modindex 6ecece3e8..7360b8e0e 100644--- a/go.mod+++ b/go.mod@@ -17,6 +17,7 @@ require (github.com/google/go-github/v41 v41.0.0github.com/h2non/filetype v1.1.3github.com/hashicorp/go-retryablehttp v0.7.0+ github.com/jeremywohl/flatten v1.0.1github.com/joho/godotenv v1.4.0github.com/kylelemons/godebug v1.1.0github.com/mattn/go-colorable v0.1.12diff --git a/go.sum b/go.sumindex 2ac909e25..e130844ba 100644--- a/go.sum+++ b/go.sum@@ -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=diff --git a/main.go b/main.goindex 9790e10ed..566ef4a05 100644--- a/main.go+++ b/main.go@@ -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+}