Find, verify, and analyze leaked credentials
Go credentialsdevsecopsdynamic-analysisprecommitscanningsecretsecret-managementsecretssecuritysecurity-toolstrufflehogverification
[chore] Remove logrus from engine package (#1085)
Miccah58e8c1e4ac9e
diff --git a/main.go b/main.goindex 49f207064..d23548230 100644--- a/main.go+++ b/main.go@@ -182,7 +182,11 @@ func run(state overseer.State) {}}()}- logger, sync := log.New("trufflehog", log.WithConsoleSink(os.Stderr))+ logFormat := log.WithConsoleSink+ if *jsonOut {+ logFormat = log.WithJSONSink+ }+ logger, sync := log.New("trufflehog", logFormat(os.Stderr))context.SetDefaultLogger(logger)defer func() { _ = sync() }()diff --git a/pkg/engine/circleci.go b/pkg/engine/circleci.goindex a15afb7c8..8d30c0e1f 100644--- a/pkg/engine/circleci.go+++ b/pkg/engine/circleci.go@@ -4,7 +4,6 @@ import ("runtime""github.com/go-errors/errors"- "github.com/sirupsen/logrus""google.golang.org/protobuf/proto""google.golang.org/protobuf/types/known/anypb"@@ -25,7 +24,7 @@ func (e *Engine) ScanCircleCI(ctx context.Context, token string) error {var conn anypb.Anyerr := anypb.MarshalFrom(&conn, connection, proto.MarshalOptions{})if err != nil {- logrus.WithError(err).Error("failed to marshal Circle CI connection")+ ctx.Logger().Error(err, "failed to marshal Circle CI connection")return err}@@ -41,7 +40,7 @@ func (e *Engine) ScanCircleCI(ctx context.Context, token string) error {defer e.sourcesWg.Done()err := circleSource.Chunks(ctx, e.ChunksChan())if err != nil {- logrus.WithError(err).Error("error scanning Circle CI")+ ctx.Logger().Error(err, "error scanning Circle CI")}}()return nildiff --git a/pkg/engine/engine.go b/pkg/engine/engine.goindex 053d937eb..3b31a39e8 100644--- a/pkg/engine/engine.go+++ b/pkg/engine/engine.go@@ -2,13 +2,13 @@ package engineimport ("bytes"+ "reflect""runtime""strings""sync""sync/atomic""time"- "github.com/sirupsen/logrus""google.golang.org/protobuf/proto""github.com/trufflesecurity/trufflehog/v3/pkg/common"@@ -88,10 +88,10 @@ func Start(ctx context.Context, options ...EngineOption) *Engine {if e.concurrency == 0 {numCPU := runtime.NumCPU()- logrus.Warn("No concurrency specified, defaulting to ", numCPU)+ ctx.Logger().Info("No concurrency specified, defaulting to max", "cpu", numCPU)e.concurrency = numCPU}- logrus.Debugf("running with up to %d workers", e.concurrency)+ ctx.Logger().V(2).Info("engine started", "workers", e.concurrency)if len(e.decoders) == 0 {e.decoders = decoders.DefaultDecoders()@@ -103,11 +103,12 @@ func Start(ctx context.Context, options ...EngineOption) *Engine {e.detectors[false] = []detectors.Detector{}}- logrus.Debugf("loaded %d decoders", len(e.decoders))- logrus.Debugf("loaded %d detectors total, %d with verification enabled. %d with verification disabled",- len(e.detectors[true])+len(e.detectors[false]),- len(e.detectors[true]),- len(e.detectors[false]))+ ctx.Logger().V(2).Info("loaded decoders", "count", len(e.decoders))+ ctx.Logger().V(2).Info("loaded detectors",+ "total", len(e.detectors[true])+len(e.detectors[false]),+ "verification_enabled", len(e.detectors[true]),+ "verification_disabled", len(e.detectors[false]),+ )// start the workersfor i := 0; i < e.concurrency; i++ {@@ -159,17 +160,18 @@ func (e *Engine) BytesScanned() uint64 {}func (e *Engine) DetectorAvgTime() map[string][]time.Duration {+ logger := context.Background().Logger()avgTime := map[string][]time.Duration{}e.detectorAvgTime.Range(func(k, v interface{}) bool {key, ok := k.(string)if !ok {- logrus.Warnf("expected DetectorAvgTime key to be a string")+ logger.Info("expected DetectorAvgTime key to be a string")return true}value, ok := v.([]time.Duration)if !ok {- logrus.Warnf("expected DetectorAvgTime value to be []time.Duration")+ logger.Info("expected DetectorAvgTime value to be []time.Duration")return true}avgTime[key] = value@@ -190,7 +192,7 @@ func (e *Engine) detectorWorker(ctx context.Context) {case *decoders.Base64:decoderType = detectorspb.DecoderType_BASE64default:- logrus.Warnf("unknown decoder type: %T", decoder)+ ctx.Logger().Info("unknown decoder type", "type", reflect.TypeOf(decoder).String())decoderType = detectorspb.DecoderType_UNKNOWN}decoded := decoder.FromChunk(chunk)@@ -219,10 +221,10 @@ func (e *Engine) detectorWorker(ctx context.Context) {return detector.FromData(ctx, verify, decoded.Data)}()if err != nil {- logrus.WithFields(logrus.Fields{- "source_type": decoded.SourceType.String(),- "metadata": decoded.SourceMetadata,- }).WithError(err).Error("could not scan chunk")+ ctx.Logger().Error(err, "could not scan chunk",+ "source_type", decoded.SourceType.String(),+ "metadata", decoded.SourceMetadata,+ )continue}diff --git a/pkg/engine/filesystem.go b/pkg/engine/filesystem.goindex b1110bdc3..59ec8cf9d 100644--- a/pkg/engine/filesystem.go+++ b/pkg/engine/filesystem.go@@ -4,7 +4,6 @@ import ("runtime""github.com/go-errors/errors"- "github.com/sirupsen/logrus""google.golang.org/protobuf/proto""google.golang.org/protobuf/types/known/anypb"@@ -23,7 +22,7 @@ func (e *Engine) ScanFileSystem(ctx context.Context, c sources.Config) error {var conn anypb.Anyerr := anypb.MarshalFrom(&conn, connection, proto.MarshalOptions{})if err != nil {- logrus.WithError(err).Error("failed to marshal filesystem connection")+ ctx.Logger().Error(err, "failed to marshal filesystem connection")return err}@@ -39,7 +38,7 @@ func (e *Engine) ScanFileSystem(ctx context.Context, c sources.Config) error {defer e.sourcesWg.Done()err := fileSystemSource.Chunks(ctx, e.ChunksChan())if err != nil {- logrus.WithError(err).Error("error scanning filesystem")+ ctx.Logger().Error(err, "error scanning filesystem")}}()return nildiff --git a/pkg/engine/git.go b/pkg/engine/git.goindex aebba9b3e..59cb4f1a4 100644--- a/pkg/engine/git.go+++ b/pkg/engine/git.go@@ -5,7 +5,6 @@ import ("runtime"gogit "github.com/go-git/go-git/v5"- "github.com/sirupsen/logrus""github.com/trufflesecurity/trufflehog/v3/pkg/common""github.com/trufflesecurity/trufflehog/v3/pkg/context"@@ -61,7 +60,7 @@ func (e *Engine) ScanGit(ctx context.Context, c sources.Config) error {defer e.sourcesWg.Done()err := gitSource.ScanRepo(ctx, repo, c.RepoPath, scanOptions, e.ChunksChan())if err != nil {- logrus.WithError(err).Fatal("could not scan repo")+ ctx.Logger().Error(err, "could not scan repo")}}()return nildiff --git a/pkg/engine/github.go b/pkg/engine/github.goindex e59b3fe4a..3de4004ba 100644--- a/pkg/engine/github.go+++ b/pkg/engine/github.go@@ -1,7 +1,6 @@package engineimport (- "github.com/sirupsen/logrus""google.golang.org/protobuf/proto""google.golang.org/protobuf/types/known/anypb"@@ -35,12 +34,12 @@ func (e *Engine) ScanGitHub(ctx context.Context, c sources.Config) error {var conn anypb.Anyerr := anypb.MarshalFrom(&conn, &connection, proto.MarshalOptions{})if err != nil {- logrus.WithError(err).Error("failed to marshal github connection")+ ctx.Logger().Error(err, "failed to marshal github connection")return err}err = source.Init(ctx, "trufflehog - github", 0, 0, false, &conn, c.Concurrency)if err != nil {- logrus.WithError(err).Error("failed to initialize github source")+ ctx.Logger().Error(err, "failed to initialize github source")return err}@@ -50,7 +49,7 @@ func (e *Engine) ScanGitHub(ctx context.Context, c sources.Config) error {defer e.sourcesWg.Done()err := source.Chunks(ctx, e.ChunksChan())if err != nil {- logrus.WithError(err).Fatal("could not scan github")+ ctx.Logger().Error(err, "could not scan github")}}()return nildiff --git a/pkg/engine/gitlab.go b/pkg/engine/gitlab.goindex f6274d583..3ae377085 100644--- a/pkg/engine/gitlab.go+++ b/pkg/engine/gitlab.go@@ -6,7 +6,6 @@ import ("github.com/go-errors/errors"gogit "github.com/go-git/go-git/v5"- "github.com/sirupsen/logrus""google.golang.org/protobuf/proto""google.golang.org/protobuf/types/known/anypb"@@ -49,7 +48,7 @@ func (e *Engine) ScanGitLab(ctx context.Context, c sources.Config) error {var conn anypb.Anyerr := anypb.MarshalFrom(&conn, connection, proto.MarshalOptions{})if err != nil {- logrus.WithError(err).Error("failed to marshal gitlab connection")+ ctx.Logger().Error(err, "failed to marshal gitlab connection")return err}@@ -66,7 +65,7 @@ func (e *Engine) ScanGitLab(ctx context.Context, c sources.Config) error {defer e.sourcesWg.Done()err := gitlabSource.Chunks(ctx, e.ChunksChan())if err != nil {- logrus.WithError(err).Error("error scanning GitLab")+ ctx.Logger().Error(err, "error scanning GitLab")}}()return nildiff --git a/pkg/engine/s3.go b/pkg/engine/s3.goindex 900670e1f..88329a0a4 100644--- a/pkg/engine/s3.go+++ b/pkg/engine/s3.go@@ -5,7 +5,6 @@ import ("runtime""github.com/go-errors/errors"- "github.com/sirupsen/logrus""google.golang.org/protobuf/proto""google.golang.org/protobuf/types/known/anypb"@@ -42,7 +41,7 @@ func (e *Engine) ScanS3(ctx context.Context, c sources.Config) error {var conn anypb.Anyerr := anypb.MarshalFrom(&conn, connection, proto.MarshalOptions{})if err != nil {- logrus.WithError(err).Error("failed to marshal S3 connection")+ ctx.Logger().Error(err, "failed to marshal S3 connection")return err}@@ -58,7 +57,7 @@ func (e *Engine) ScanS3(ctx context.Context, c sources.Config) error {defer e.sourcesWg.Done()err := s3Source.Chunks(ctx, e.ChunksChan())if err != nil {- logrus.WithError(err).Error("error scanning S3")+ ctx.Logger().Error(err, "error scanning S3")}}()return nildiff --git a/pkg/engine/syslog.go b/pkg/engine/syslog.goindex 361f3cfe9..2868b5818 100644--- a/pkg/engine/syslog.go+++ b/pkg/engine/syslog.go@@ -4,7 +4,6 @@ import ("os""github.com/go-errors/errors"- "github.com/sirupsen/logrus""google.golang.org/protobuf/proto""google.golang.org/protobuf/types/known/anypb"@@ -46,7 +45,7 @@ func (e *Engine) ScanSyslog(ctx context.Context, c sources.Config) error {err = source.Init(ctx, "trufflehog - syslog", 0, 0, false, &conn, c.Concurrency)source.InjectConnection(connection)if err != nil {- logrus.WithError(err).Error("failed to initialize syslog source")+ ctx.Logger().Error(err, "failed to initialize syslog source")return err}@@ -56,7 +55,7 @@ func (e *Engine) ScanSyslog(ctx context.Context, c sources.Config) error {defer e.sourcesWg.Done()err := source.Chunks(ctx, e.ChunksChan())if err != nil {- logrus.WithError(err).Fatal("could not scan syslog")+ ctx.Logger().Error(err, "could not scan syslog")}}()return nil