2022-03-15 00:04:19 +00:00
|
|
|
package engine
|
|
|
|
|
|
|
|
import (
|
2022-05-25 16:35:44 +00:00
|
|
|
"runtime"
|
|
|
|
|
2022-03-15 00:04:19 +00:00
|
|
|
"google.golang.org/protobuf/proto"
|
|
|
|
"google.golang.org/protobuf/types/known/anypb"
|
2022-08-10 17:11:13 +00:00
|
|
|
|
2022-08-29 18:45:37 +00:00
|
|
|
"github.com/trufflesecurity/trufflehog/v3/pkg/context"
|
2022-08-10 17:11:13 +00:00
|
|
|
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/sourcespb"
|
|
|
|
"github.com/trufflesecurity/trufflehog/v3/pkg/sources"
|
|
|
|
"github.com/trufflesecurity/trufflehog/v3/pkg/sources/filesystem"
|
2022-03-15 00:04:19 +00:00
|
|
|
)
|
|
|
|
|
2022-08-10 17:11:13 +00:00
|
|
|
// ScanFileSystem scans a given file system.
|
2023-02-10 20:43:00 +00:00
|
|
|
func (e *Engine) ScanFileSystem(ctx context.Context, c sources.FilesystemConfig) error {
|
2022-03-15 00:04:19 +00:00
|
|
|
connection := &sourcespb.Filesystem{
|
2024-01-11 23:41:50 +00:00
|
|
|
Paths: c.Paths,
|
|
|
|
IncludePathsFile: c.IncludePathsFile,
|
|
|
|
ExcludePathsFile: c.ExcludePathsFile,
|
2022-03-15 00:04:19 +00:00
|
|
|
}
|
|
|
|
var conn anypb.Any
|
|
|
|
err := anypb.MarshalFrom(&conn, connection, proto.MarshalOptions{})
|
|
|
|
if err != nil {
|
2023-02-09 22:55:19 +00:00
|
|
|
ctx.Logger().Error(err, "failed to marshal filesystem connection")
|
2022-03-15 00:04:19 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-09-12 23:58:38 +00:00
|
|
|
sourceName := "trufflehog - filesystem"
|
2023-09-13 00:23:25 +00:00
|
|
|
sourceID, jobID, _ := e.sourceManager.GetIDs(ctx, sourceName, filesystem.SourceType)
|
2023-09-12 23:58:38 +00:00
|
|
|
|
|
|
|
fileSystemSource := &filesystem.Source{}
|
2023-09-14 18:28:24 +00:00
|
|
|
if err := fileSystemSource.Init(ctx, sourceName, jobID, sourceID, true, &conn, runtime.NumCPU()); err != nil {
|
2023-08-03 18:36:30 +00:00
|
|
|
return err
|
2022-03-15 00:04:19 +00:00
|
|
|
}
|
2023-09-12 23:58:38 +00:00
|
|
|
_, err = e.sourceManager.Run(ctx, sourceName, fileSystemSource)
|
2023-08-03 18:36:30 +00:00
|
|
|
return err
|
2022-03-15 00:04:19 +00:00
|
|
|
}
|