[Update] Fixed the Return of the GCP Detector (#3905)

* updated gcp detector; now returns results in case of authentication errors

* reverted unnecessary return values in gcp.go
This commit is contained in:
Nabeel Alam
2025-02-12 15:23:48 -06:00
committed by GitHub
parent 67bb63946a
commit ec42f4437c
+15 -9
View File
@@ -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)
@@ -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, ""
}