Skip to content

Commit

Permalink
Move DecoderType into ResultWithMetadata #3502
Browse files Browse the repository at this point in the history
Result.DecoderType is only ever used by ResultWithMetadata (via its embedded Result). This unnecessarily complicates the relationship between the types and adds some warts to #3457, so this PR moves DecoderType directly into the only struct which actually uses it.
  • Loading branch information
rosecodym authored Oct 28, 2024
1 parent 97fac39 commit ad15888
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions pkg/detectors/detectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ type Result struct {
DetectorType detectorspb.DetectorType
// DetectorName is the name of the Detector. Used for custom detectors.
DetectorName string
// DecoderType is the type of Decoder.
DecoderType detectorspb.DecoderType
Verified bool
Verified bool
// Raw contains the raw secret identifier data. Prefer IDs over secrets since it is used for deduping after hashing.
Raw []byte
// RawV2 contains the raw secret identifier that is a combination of both the ID and the secret.
Expand Down Expand Up @@ -168,6 +166,8 @@ type ResultWithMetadata struct {
Result
// Data from the sources.Chunk which this result was emitted for
Data []byte
// DecoderType is the type of decoder that was used to generate this result's data.
DecoderType detectorspb.DecoderType
}

// CopyMetadata returns a detector result with included metadata from the source chunk.
Expand Down
4 changes: 2 additions & 2 deletions pkg/output/github_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type GitHubActionsPrinter struct{ mu sync.Mutex }
func (p *GitHubActionsPrinter) Print(_ context.Context, r *detectors.ResultWithMetadata) error {
out := gitHubActionsOutputFormat{
DetectorType: r.Result.DetectorType.String(),
DecoderType: r.Result.DecoderType.String(),
DecoderType: r.DecoderType.String(),
Verified: r.Result.Verified,
}

Expand Down Expand Up @@ -60,7 +60,7 @@ func (p *GitHubActionsPrinter) Print(_ context.Context, r *detectors.ResultWithM
dedupeCache[key] = struct{}{}

message := fmt.Sprintf("Found %s %s result 🐷🔑\n", verifiedStatus, out.DetectorType)
if r.Result.DecoderType != detectorspb.DecoderType_PLAIN {
if r.DecoderType != detectorspb.DecoderType_PLAIN {
message = fmt.Sprintf("Found %s %s result with %s encoding 🐷🔑\n", verifiedStatus, out.DetectorType, out.DecoderType)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/output/plain.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type PlainPrinter struct{ mu sync.Mutex }
func (p *PlainPrinter) Print(_ context.Context, r *detectors.ResultWithMetadata) error {
out := outputFormat{
DetectorType: r.Result.DetectorType.String(),
DecoderType: r.Result.DecoderType.String(),
DecoderType: r.DecoderType.String(),
Verified: r.Result.Verified,
VerificationError: r.Result.VerificationError(),
MetaData: r.SourceMetadata,
Expand Down

0 comments on commit ad15888

Please sign in to comment.