Skip to content
10 changes: 10 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ var (
stdinInputScan = cli.Command("stdin", "Find credentials from stdin.")
multiScanScan = cli.Command("multi-scan", "Find credentials in multiple sources defined in configuration.")

jsonEnumeratorScan = cli.Command("json-enumerator", "Find credentials from a JSON enumerator input.")
jsonEnumeratorPaths = jsonEnumeratorScan.Arg("path", "Path to JSON enumerator file to scan.").Strings()

analyzeCmd = analyzer.Command(cli)
usingTUI = false
)
Expand Down Expand Up @@ -1104,6 +1107,13 @@ func runSingleScan(ctx context.Context, cmd string, cfg engine.Config) (metrics,
} else {
refs = []sources.JobProgressRef{ref}
}
case jsonEnumeratorScan.FullCommand():
cfg := sources.JSONEnumeratorConfig{Paths: *jsonEnumeratorPaths}
if ref, err := eng.ScanJSONEnumeratorInput(ctx, cfg); err != nil {
return scanMetrics, fmt.Errorf("failed to scan JSON enumerator input: %v", err)
} else {
refs = []sources.JobProgressRef{ref}
}
default:
return scanMetrics, fmt.Errorf("invalid command: %s", cmd)
}
Expand Down
43 changes: 43 additions & 0 deletions pkg/engine/json_enumerator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
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/json_enumerator"
)

// ScanJSONEnumeratorInput scans input that is in JSON Enumerator format
func (e *Engine) ScanJSONEnumeratorInput(
ctx context.Context,
c sources.JSONEnumeratorConfig,
) (sources.JobProgressRef, error) {
connection := &sourcespb.JSONEnumerator{
Paths: c.Paths,
}
var conn anypb.Any
err := anypb.MarshalFrom(&conn, connection, proto.MarshalOptions{})
if err != nil {
ctx.Logger().Error(err, "failed to marshal JSON enumerator connection")
return sources.JobProgressRef{}, err
}

sourceName := "trufflehog - JSON enumerator"
sourceID, jobID, err := e.sourceManager.GetIDs(ctx, sourceName, json_enumerator.SourceType)
if err != nil {
ctx.Logger().Error(err, "failed to get IDs from source manager")
return sources.JobProgressRef{}, err
}

source := &json_enumerator.Source{}
err = source.Init(ctx, sourceName, jobID, sourceID, true, &conn, runtime.NumCPU())
if err != nil {
return sources.JobProgressRef{}, err
}
return e.sourceManager.EnumerateAndScan(ctx, sourceName, source)
}
419 changes: 251 additions & 168 deletions pkg/pb/source_metadatapb/source_metadata.pb.go

Large diffs are not rendered by default.

143 changes: 143 additions & 0 deletions pkg/pb/source_metadatapb/source_metadata.pb.validate.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading