Skip to content

Commit

Permalink
[Update] Fixed the Return of the GCP Detector (#3905)
Browse files Browse the repository at this point in the history
* updated gcp detector; now returns results in case of authentication errors

* reverted unnecessary return values in gcp.go
  • Loading branch information
nabeelalam authored Feb 12, 2025
1 parent 67bb639 commit ec42f44
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions pkg/detectors/gcp/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,9 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
}

if verify {
credentials, err := google.CredentialsFromJSON(ctx, credBytes, "https://www.googleapis.com/auth/cloud-platform")
if err != nil {
continue
}

if _, err = credentials.TokenSource.Token(); err != nil {
continue
}
result.Verified = true
isVerified, verificationErr := verifyMatch(ctx, credBytes)
result.Verified = isVerified
result.SetVerificationError(verificationErr, match)
}

results = append(results, result)
Expand All @@ -140,6 +134,18 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
return
}

func verifyMatch(ctx context.Context, credBytes []byte) (bool, error) {
credentials, err := google.CredentialsFromJSON(ctx, credBytes, "https://www.googleapis.com/auth/cloud-platform")
if err != nil {
return false, err
}

if _, err = credentials.TokenSource.Token(); err != nil {
return false, err
}
return true, nil
}

func (s Scanner) IsFalsePositive(_ detectors.Result) (bool, string) {
return false, ""
}
Expand Down

0 comments on commit ec42f44

Please sign in to comment.