Skip to content

Commit ec42f44

Browse files
authored
[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
1 parent 67bb639 commit ec42f44

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

pkg/detectors/gcp/gcp.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,9 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
123123
}
124124

125125
if verify {
126-
credentials, err := google.CredentialsFromJSON(ctx, credBytes, "https://www.googleapis.com/auth/cloud-platform")
127-
if err != nil {
128-
continue
129-
}
130-
131-
if _, err = credentials.TokenSource.Token(); err != nil {
132-
continue
133-
}
134-
result.Verified = true
126+
isVerified, verificationErr := verifyMatch(ctx, credBytes)
127+
result.Verified = isVerified
128+
result.SetVerificationError(verificationErr, match)
135129
}
136130

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

137+
func verifyMatch(ctx context.Context, credBytes []byte) (bool, error) {
138+
credentials, err := google.CredentialsFromJSON(ctx, credBytes, "https://www.googleapis.com/auth/cloud-platform")
139+
if err != nil {
140+
return false, err
141+
}
142+
143+
if _, err = credentials.TokenSource.Token(); err != nil {
144+
return false, err
145+
}
146+
return true, nil
147+
}
148+
143149
func (s Scanner) IsFalsePositive(_ detectors.Result) (bool, string) {
144150
return false, ""
145151
}

0 commit comments

Comments
 (0)