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

[cleanup] - Implement config struct for source Init #2403

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
21 changes: 16 additions & 5 deletions pkg/engine/circleci.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package engine

import (
"runtime"

"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/anypb"

"github.com/trufflesecurity/trufflehog/v3/pkg/context"
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/sourcespb"
"github.com/trufflesecurity/trufflehog/v3/pkg/sources"
"github.com/trufflesecurity/trufflehog/v3/pkg/sources/circleci"
)

Expand All @@ -29,10 +28,22 @@ func (e *Engine) ScanCircleCI(ctx context.Context, token string) error {
sourceName := "trufflehog - Circle CI"
sourceID, jobID, _ := e.sourceManager.GetIDs(ctx, sourceName, circleci.SourceType)

circleSource := &circleci.Source{}
if err := circleSource.Init(ctx, "trufflehog - Circle CI", jobID, sourceID, true, &conn, runtime.NumCPU()); err != nil {
src := &circleci.Source{}
err = src.Init(
ctx,
sources.NewConfig(
&conn,
sources.WithName(sourceName),
sources.WithSourceID(sourceID),
sources.WithJobID(jobID),
sources.WithVerify(e.verify),
sources.WithConcurrency(int(e.concurrency)),
),
)
if err != nil {
return err
}
_, err = e.sourceManager.Run(ctx, sourceName, circleSource)

_, err = e.sourceManager.Run(ctx, sourceName, src)
return err
}
21 changes: 16 additions & 5 deletions pkg/engine/docker.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package engine

import (
"runtime"

"google.golang.org/protobuf/types/known/anypb"

"github.com/trufflesecurity/trufflehog/v3/pkg/context"
"github.com/trufflesecurity/trufflehog/v3/pkg/sources"
"github.com/trufflesecurity/trufflehog/v3/pkg/sources/docker"
)

Expand All @@ -14,10 +13,22 @@ func (e *Engine) ScanDocker(ctx context.Context, conn *anypb.Any) error {
sourceName := "trufflehog - docker"
sourceID, jobID, _ := e.sourceManager.GetIDs(ctx, sourceName, docker.SourceType)

dockerSource := &docker.Source{}
if err := dockerSource.Init(ctx, sourceName, jobID, sourceID, true, conn, runtime.NumCPU()); err != nil {
src := &docker.Source{}
err := src.Init(
ctx,
sources.NewConfig(
conn,
sources.WithName(sourceName),
sources.WithSourceID(sourceID),
sources.WithJobID(jobID),
sources.WithVerify(e.verify),
sources.WithConcurrency(int(e.concurrency)),
),
)
if err != nil {
return err
}
_, err := e.sourceManager.Run(ctx, sourceName, dockerSource)

_, err = e.sourceManager.Run(ctx, sourceName, src)
return err
}
20 changes: 15 additions & 5 deletions pkg/engine/filesystem.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package engine

import (
"runtime"

"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/anypb"

Expand All @@ -29,10 +27,22 @@ func (e *Engine) ScanFileSystem(ctx context.Context, c sources.FilesystemConfig)
sourceName := "trufflehog - filesystem"
sourceID, jobID, _ := e.sourceManager.GetIDs(ctx, sourceName, filesystem.SourceType)

fileSystemSource := &filesystem.Source{}
if err := fileSystemSource.Init(ctx, sourceName, jobID, sourceID, true, &conn, runtime.NumCPU()); err != nil {
src := &filesystem.Source{}
err = src.Init(
ctx,
sources.NewConfig(
&conn,
sources.WithName(sourceName),
sources.WithSourceID(sourceID),
sources.WithJobID(jobID),
sources.WithVerify(e.verify),
sources.WithConcurrency(int(e.concurrency)),
),
)
if err != nil {
return err
}
_, err = e.sourceManager.Run(ctx, sourceName, fileSystemSource)

_, err = e.sourceManager.Run(ctx, sourceName, src)
return err
}
18 changes: 15 additions & 3 deletions pkg/engine/gcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,23 @@ func (e *Engine) ScanGCS(ctx context.Context, c sources.GCSConfig) error {
sourceName := "trufflehog - gcs"
sourceID, jobID, _ := e.sourceManager.GetIDs(ctx, sourceName, gcs.SourceType)

gcsSource := &gcs.Source{}
if err := gcsSource.Init(ctx, sourceName, jobID, sourceID, true, &conn, int(c.Concurrency)); err != nil {
src := &gcs.Source{}
err = src.Init(
ctx,
sources.NewConfig(
&conn,
sources.WithName(sourceName),
sources.WithSourceID(sourceID),
sources.WithJobID(jobID),
sources.WithVerify(e.verify),
sources.WithConcurrency(int(e.concurrency)),
),
)
if err != nil {
return err
}
_, err = e.sourceManager.Run(ctx, sourceName, gcsSource)

_, err = e.sourceManager.Run(ctx, sourceName, src)
return err
}

Expand Down
19 changes: 14 additions & 5 deletions pkg/engine/git.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package engine

import (
"runtime"

"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/anypb"

Expand Down Expand Up @@ -34,11 +32,22 @@ func (e *Engine) ScanGit(ctx context.Context, c sources.GitConfig) error {
sourceName := "trufflehog - git"
sourceID, jobID, _ := e.sourceManager.GetIDs(ctx, sourceName, git.SourceType)

gitSource := &git.Source{}
if err := gitSource.Init(ctx, sourceName, jobID, sourceID, true, &conn, runtime.NumCPU()); err != nil {
src := &git.Source{}
err := src.Init(
ctx,
sources.NewConfig(
&conn,
sources.WithName(sourceName),
sources.WithSourceID(sourceID),
sources.WithJobID(jobID),
sources.WithVerify(e.verify),
sources.WithConcurrency(int(e.concurrency)),
),
)
if err != nil {
return err
}

_, err := e.sourceManager.Run(ctx, sourceName, gitSource)
_, err = e.sourceManager.Run(ctx, sourceName, src)
return err
}
30 changes: 21 additions & 9 deletions pkg/engine/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,33 @@ func (e *Engine) ScanGitHub(ctx context.Context, c sources.GithubConfig) error {
return err
}

sourceName := "trufflehog - github"
sourceID, jobID, _ := e.sourceManager.GetIDs(ctx, sourceName, github.SourceType)

src := &github.Source{}
err = src.Init(
ctx,
sources.NewConfig(
&conn,
sources.WithName(sourceName),
sources.WithSourceID(sourceID),
sources.WithJobID(jobID),
sources.WithVerify(e.verify),
sources.WithConcurrency(int(e.concurrency)),
),
)
if err != nil {
return err
}

logOptions := &gogit.LogOptions{}
opts := []git.ScanOption{
git.ScanOptionFilter(c.Filter),
git.ScanOptionLogOptions(logOptions),
}
scanOptions := git.NewScanOptions(opts...)
src.WithScanOptions(scanOptions)

sourceName := "trufflehog - github"
sourceID, jobID, _ := e.sourceManager.GetIDs(ctx, sourceName, github.SourceType)

githubSource := &github.Source{}
if err := githubSource.Init(ctx, sourceName, jobID, sourceID, true, &conn, c.Concurrency); err != nil {
return err
}
githubSource.WithScanOptions(scanOptions)
_, err = e.sourceManager.Run(ctx, sourceName, githubSource)
_, err = e.sourceManager.Run(ctx, sourceName, src)
return err
}
35 changes: 23 additions & 12 deletions pkg/engine/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package engine

import (
"fmt"
"runtime"

gogit "github.com/go-git/go-git/v5"
"google.golang.org/protobuf/proto"
Expand All @@ -17,13 +16,6 @@ import (

// ScanGitLab scans GitLab with the provided configuration.
func (e *Engine) ScanGitLab(ctx context.Context, c sources.GitlabConfig) error {
logOptions := &gogit.LogOptions{}
opts := []git.ScanOption{
git.ScanOptionFilter(c.Filter),
git.ScanOptionLogOptions(logOptions),
}
scanOptions := git.NewScanOptions(opts...)

connection := &sourcespb.GitLab{SkipBinaries: c.SkipBinaries}

switch {
Expand Down Expand Up @@ -53,11 +45,30 @@ func (e *Engine) ScanGitLab(ctx context.Context, c sources.GitlabConfig) error {
sourceName := "trufflehog - gitlab"
sourceID, jobID, _ := e.sourceManager.GetIDs(ctx, sourceName, gitlab.SourceType)

gitlabSource := &gitlab.Source{}
if err := gitlabSource.Init(ctx, sourceName, jobID, sourceID, true, &conn, runtime.NumCPU()); err != nil {
src := &gitlab.Source{}
err = src.Init(
ctx,
sources.NewConfig(
&conn,
sources.WithName(sourceName),
sources.WithSourceID(sourceID),
sources.WithJobID(jobID),
sources.WithVerify(e.verify),
sources.WithConcurrency(int(e.concurrency)),
),
)
if err != nil {
return err
}
gitlabSource.WithScanOptions(scanOptions)
_, err = e.sourceManager.Run(ctx, sourceName, gitlabSource)

logOptions := &gogit.LogOptions{}
opts := []git.ScanOption{
git.ScanOptionFilter(c.Filter),
git.ScanOptionLogOptions(logOptions),
}
scanOptions := git.NewScanOptions(opts...)
src.WithScanOptions(scanOptions)

_, err = e.sourceManager.Run(ctx, sourceName, src)
return err
}
19 changes: 15 additions & 4 deletions pkg/engine/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package engine

import (
"fmt"
"runtime"

"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/anypb"
Expand Down Expand Up @@ -61,10 +60,22 @@ func (e *Engine) ScanS3(ctx context.Context, c sources.S3Config) error {
sourceName := "trufflehog - s3"
sourceID, jobID, _ := e.sourceManager.GetIDs(ctx, sourceName, s3.SourceType)

s3Source := &s3.Source{}
if err := s3Source.Init(ctx, sourceName, jobID, sourceID, true, &conn, runtime.NumCPU()); err != nil {
src := &s3.Source{}
err = src.Init(
ctx,
sources.NewConfig(
&conn,
sources.WithName(sourceName),
sources.WithSourceID(sourceID),
sources.WithJobID(jobID),
sources.WithVerify(e.verify),
sources.WithConcurrency(int(e.concurrency)),
),
)
if err != nil {
return err
}
_, err = e.sourceManager.Run(ctx, sourceName, s3Source)

_, err = e.sourceManager.Run(ctx, sourceName, src)
return err
}
19 changes: 15 additions & 4 deletions pkg/engine/syslog.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,23 @@ func (e *Engine) ScanSyslog(ctx context.Context, c sources.SyslogConfig) error {

sourceName := "trufflehog - syslog"
sourceID, jobID, _ := e.sourceManager.GetIDs(ctx, sourceName, syslog.SourceType)
syslogSource := &syslog.Source{}
if err := syslogSource.Init(ctx, sourceName, jobID, sourceID, true, &conn, c.Concurrency); err != nil {

src := &syslog.Source{}
err = src.Init(
ctx,
sources.NewConfig(
&conn,
sources.WithName(sourceName),
sources.WithSourceID(sourceID),
sources.WithJobID(jobID),
sources.WithVerify(e.verify),
sources.WithConcurrency(int(e.concurrency)),
),
)
if err != nil {
return err
}
syslogSource.InjectConnection(connection)

_, err = e.sourceManager.Run(ctx, sourceName, syslogSource)
_, err = e.sourceManager.Run(ctx, sourceName, src)
return err
}
21 changes: 16 additions & 5 deletions pkg/engine/travisci.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package engine

import (
"runtime"

"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/anypb"

"github.com/trufflesecurity/trufflehog/v3/pkg/context"
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/sourcespb"
"github.com/trufflesecurity/trufflehog/v3/pkg/sources"
"github.com/trufflesecurity/trufflehog/v3/pkg/sources/travisci"
)

Expand All @@ -29,10 +28,22 @@ func (e *Engine) ScanTravisCI(ctx context.Context, token string) error {
sourceName := "trufflehog - Travis CI"
sourceID, jobID, _ := e.sourceManager.GetIDs(ctx, sourceName, travisci.SourceType)

travisSource := &travisci.Source{}
if err := travisSource.Init(ctx, sourceName, jobID, sourceID, true, &conn, runtime.NumCPU()); err != nil {
src := &travisci.Source{}
err = src.Init(
ctx,
sources.NewConfig(
&conn,
sources.WithName(sourceName),
sources.WithSourceID(sourceID),
sources.WithJobID(jobID),
sources.WithVerify(e.verify),
sources.WithConcurrency(int(e.concurrency)),
),
)
if err != nil {
return err
}
_, err = e.sourceManager.Run(ctx, sourceName, travisSource)

_, err = e.sourceManager.Run(ctx, sourceName, src)
return err
}
Loading
Loading