Find, verify, and analyze leaked credentials
Go credentialsdevsecopsdynamic-analysisprecommitscanningsecretsecret-managementsecretssecuritysecurity-toolstrufflehogverification
[chore] - Use config struct instead of pointer for engine scans. (#709)
ahrav73f9d3f0a080
diff --git a/main.go b/main.goindex 452dd8ad9..a7dfb1a9f 100644--- a/main.go+++ b/main.go@@ -192,7 +192,7 @@ func run(state overseer.State) {defer os.RemoveAll(repoPath)}- g := func(c *sources.Config) {+ g := func(c sources.Config) {c.RepoPath = repoPathc.HeadRef = *gitScanBranchc.BaseRef = *gitScanSinceCommit@@ -208,7 +208,7 @@ func run(state overseer.State) {log.Fatal("You must specify at least one organization or repository.")}- github := func(c *sources.Config) {+ github := func(c sources.Config) {c.Endpoint = *githubScanEndpointc.Repos = *githubScanReposc.Orgs = *githubScanOrgs@@ -222,7 +222,7 @@ func run(state overseer.State) {logrus.WithError(err).Fatal("Failed to scan Github.")}case gitlabScan.FullCommand():- gitlab := func(c *sources.Config) {+ gitlab := func(c sources.Config) {c.Endpoint = *gitlabScanEndpointc.Token = *gitlabScanTokenc.Repos = *gitlabScanRepos@@ -232,7 +232,7 @@ func run(state overseer.State) {logrus.WithError(err).Fatal("Failed to scan GitLab.")}case filesystemScan.FullCommand():- fs := func(c *sources.Config) {+ fs := func(c sources.Config) {c.Directories = *filesystemDirectories}@@ -240,7 +240,7 @@ func run(state overseer.State) {logrus.WithError(err).Fatal("Failed to scan filesystem")}case s3Scan.FullCommand():- s3 := func(c *sources.Config) {+ s3 := func(c sources.Config) {c.Key = *s3ScanKeyc.Secret = *s3ScanSecretc.Buckets = *s3ScanBuckets@@ -250,7 +250,7 @@ func run(state overseer.State) {logrus.WithError(err).Fatal("Failed to scan S3.")}case syslogScan.FullCommand():- syslog := func(c *sources.Config) {+ syslog := func(c sources.Config) {c.Address = *syslogAddressc.Protocol = *syslogProtocolc.CertPath = *syslogTLSCertdiff --git a/pkg/engine/filesystem.go b/pkg/engine/filesystem.goindex 5b3f3e46e..22eb45452 100644--- a/pkg/engine/filesystem.go+++ b/pkg/engine/filesystem.go@@ -15,11 +15,7 @@ import ()// ScanFileSystem scans a given file system.-func (e *Engine) ScanFileSystem(ctx context.Context, c *sources.Config) error {- if c == nil {- return errors.New("nil config provided to ScanFileSystem")- }-+func (e *Engine) ScanFileSystem(ctx context.Context, c sources.Config) error {connection := &sourcespb.Filesystem{Directories: c.Directories,}diff --git a/pkg/engine/git.go b/pkg/engine/git.goindex f18ac416d..d4fed1e68 100644--- a/pkg/engine/git.go+++ b/pkg/engine/git.go@@ -18,11 +18,7 @@ import ()// ScanGit scans any git source.-func (e *Engine) ScanGit(ctx context.Context, c *sources.Config) error {- if c == nil {- return errors.New("nil config for ScanGit")- }-+func (e *Engine) ScanGit(ctx context.Context, c sources.Config) error {logOptions := &gogit.LogOptions{}opts := []git.ScanOption{git.ScanOptionFilter(c.Filter),diff --git a/pkg/engine/git_test.go b/pkg/engine/git_test.goindex 8ef368019..2d841f894 100644--- a/pkg/engine/git_test.go+++ b/pkg/engine/git_test.go@@ -64,7 +64,7 @@ func TestGitEngine(t *testing.T) {MaxDepth: tTest.maxDepth,Filter: tTest.filter,}- if err := e.ScanGit(ctx, &cfg); err != nil {+ if err := e.ScanGit(ctx, cfg); err != nil {return}go e.Finish()@@ -118,7 +118,7 @@ func BenchmarkGitEngine(b *testing.B) {RepoPath: path,Filter: common.FilterEmpty(),}- if err := e.ScanGit(ctx, &cfg); err != nil {+ if err := e.ScanGit(ctx, cfg); err != nil {return}}diff --git a/pkg/engine/github.go b/pkg/engine/github.goindex 4a8b3e434..f8f8d8480 100644--- a/pkg/engine/github.go+++ b/pkg/engine/github.go@@ -3,7 +3,6 @@ package engineimport ("context"- "github.com/go-errors/errors""github.com/sirupsen/logrus""google.golang.org/protobuf/proto""google.golang.org/protobuf/types/known/anypb"@@ -14,11 +13,7 @@ import ()// ScanGitHub scans Github with the provided options.-func (e *Engine) ScanGitHub(ctx context.Context, c *sources.Config) error {- if c == nil {- return errors.New("nil config provided for ScanGitHub")- }-+func (e *Engine) ScanGitHub(ctx context.Context, c sources.Config) error {source := github.Source{}connection := sourcespb.GitHub{Endpoint: c.Endpoint,diff --git a/pkg/engine/gitlab.go b/pkg/engine/gitlab.goindex fd508fdb1..1ae0f6272 100644--- a/pkg/engine/gitlab.go+++ b/pkg/engine/gitlab.go@@ -16,11 +16,7 @@ import ()// ScanGitLab scans GitLab with the provided configuration.-func (e *Engine) ScanGitLab(ctx context.Context, c *sources.Config) error {- if c == nil {- return errors.New("config is nil for ScanGitlab")- }-+func (e *Engine) ScanGitLab(ctx context.Context, c sources.Config) error {connection := &sourcespb.GitLab{}switch {diff --git a/pkg/engine/s3.go b/pkg/engine/s3.goindex de25b8f39..5295e2748 100644--- a/pkg/engine/s3.go+++ b/pkg/engine/s3.go@@ -17,11 +17,7 @@ import ()// ScanS3 scans S3 buckets.-func (e *Engine) ScanS3(ctx context.Context, c *sources.Config) error {- if c == nil {- return errors.New("nil config provided for ScanS3")- }-+func (e *Engine) ScanS3(ctx context.Context, c sources.Config) error {connection := &sourcespb.S3{Credential: &sourcespb.S3_Unauthenticated{},}diff --git a/pkg/engine/syslog.go b/pkg/engine/syslog.goindex 8fc874d34..3b0ffbd5b 100644--- a/pkg/engine/syslog.go+++ b/pkg/engine/syslog.go@@ -15,11 +15,7 @@ import ()// ScanSyslog is a source that scans syslog files.-func (e *Engine) ScanSyslog(ctx context.Context, c *sources.Config) error {- if c == nil {- return errors.New("nil config provided for ScanSyslog")- }-+func (e *Engine) ScanSyslog(ctx context.Context, c sources.Config) error {connection := &sourcespb.Syslog{Protocol: c.Protocol,ListenAddress: c.Address,diff --git a/pkg/sources/sources.go b/pkg/sources/sources.goindex 7e2eb4669..9a323883d 100644--- a/pkg/sources/sources.go+++ b/pkg/sources/sources.go@@ -96,8 +96,8 @@ type Config struct {}// NewConfig returns a new Config with optional values.-func NewConfig(opts ...func(*Config)) *Config {- c := &Config{}+func NewConfig(opts ...func(Config)) Config {+ c := Config{}for _, opt := range opts {opt(c)}