[THOG-336] Use the string version of the Detector Type. (#538)

* Use the string version of the Detector Type.

* Only modify the output for json.

* reorder import.

* Fix imports.

* Add DetectorName in addition to DetectorType to the json output.
This commit is contained in:
ahrav 2022-05-13 16:02:33 +00:00 committed by GitHub
parent b0d79180f6
commit 928b3b4d28
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

39
main.go
View file

@ -26,6 +26,9 @@ import (
"github.com/trufflesecurity/trufflehog/v3/pkg/decoders"
"github.com/trufflesecurity/trufflehog/v3/pkg/engine"
"github.com/trufflesecurity/trufflehog/v3/pkg/output"
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb"
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/source_metadatapb"
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/sourcespb"
"github.com/trufflesecurity/trufflehog/v3/pkg/sources/git"
)
@ -246,7 +249,41 @@ func run(state overseer.State) {
os.RemoveAll(repoPath)
}
case *jsonOut:
out, err := json.Marshal(r)
v := &struct {
// SourceMetadata contains source-specific contextual information.
SourceMetadata *source_metadatapb.MetaData
// SourceID is the ID of the source that the API uses to map secrets to specific sources.
SourceID int64
// SourceType is the type of Source.
SourceType sourcespb.SourceType
// SourceName is the name of the Source.
SourceName string
// DetectorType is the type of Detector.
DetectorType detectorspb.DetectorType
// DetectorName is the string name of the DetectorType.
DetectorName string
Verified bool
// Raw contains the raw secret identifier data. Prefer IDs over secrets since it is used for deduping after hashing.
Raw []byte
// Redacted contains the redacted version of the raw secret identification data for display purposes.
// A secret ID should be used if available.
Redacted string
ExtraData map[string]string
StructuredData *detectorspb.StructuredData
}{
SourceMetadata: r.SourceMetadata,
SourceID: r.SourceID,
SourceType: r.SourceType,
SourceName: r.SourceName,
DetectorType: r.DetectorType,
DetectorName: r.DetectorType.String(),
Verified: r.Verified,
Raw: r.Raw,
Redacted: r.Redacted,
ExtraData: r.ExtraData,
StructuredData: r.StructuredData,
}
out, err := json.Marshal(v)
if err != nil {
logrus.WithError(err).Fatal("could not marshal result")
}