e856a6890d
* Add Docker source * Add metrics * Add test * Add debugging, address PR comments, fix path output * review suggestions
39 lines
1.1 KiB
Go
39 lines
1.1 KiB
Go
package engine
|
|
|
|
import (
|
|
"runtime"
|
|
|
|
"github.com/go-errors/errors"
|
|
"google.golang.org/protobuf/types/known/anypb"
|
|
|
|
"github.com/trufflesecurity/trufflehog/v3/pkg/common"
|
|
"github.com/trufflesecurity/trufflehog/v3/pkg/context"
|
|
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/sourcespb"
|
|
"github.com/trufflesecurity/trufflehog/v3/pkg/sources/docker"
|
|
)
|
|
|
|
// ScanDocker scans a given docker connection.
|
|
func (e *Engine) ScanDocker(ctx context.Context, conn *anypb.Any) error {
|
|
dockerSource := docker.Source{}
|
|
|
|
ctx = context.WithValues(ctx,
|
|
"source_type", dockerSource.Type().String(),
|
|
"source_name", "docker",
|
|
)
|
|
err := dockerSource.Init(ctx, "trufflehog - docker", 0, int64(sourcespb.SourceType_SOURCE_TYPE_DOCKER), true, conn, runtime.NumCPU())
|
|
if err != nil {
|
|
return errors.WrapPrefix(err, "could not init docker source", 0)
|
|
}
|
|
|
|
e.sourcesWg.Add(1)
|
|
go func() {
|
|
defer common.RecoverWithExit(ctx)
|
|
defer e.sourcesWg.Done()
|
|
err := dockerSource.Chunks(ctx, e.ChunksChan())
|
|
if err != nil {
|
|
ctx.Logger().Error(err, "error scanning docker image")
|
|
}
|
|
}()
|
|
return nil
|
|
}
|