-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
updated buildkite detectors #3611
updated buildkite detectors #3611
Conversation
} | ||
isVerified, verificationErr := VerifyBuildKite(ctx, client, resMatch) | ||
s1.Verified = isVerified | ||
if verificationErr != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check already happens in SetVerificationError
.
res, err := client.Do(req) | ||
if err == nil { | ||
defer res.Body.Close() | ||
if res.StatusCode >= 200 && res.StatusCode < 300 { | ||
return true, nil | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This old pattern is pretty lax. A better implementation is to (i) check the error, (ii) defer the drain + close of the body, (iii) check for a specific status code.
trufflehog/pkg/detectors/alchemy/alchemy.go
Lines 78 to 81 in a6e2b99
defer func() { | |
_, _ = io.Copy(io.Discard, res.Body) | |
_ = res.Body.Close() | |
}() |
6a9bd56
to
3f3113b
Compare
}() | ||
|
||
if res.StatusCode == http.StatusOK { | ||
return true, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's worth including the scopes
in extraData. https://buildkite.com/docs/apis/rest-api/access-token#get-the-current-token
Also, I would explicitly highlight which status code means "bad" and return an error if an unusual one is encountered.
return false, nil, fmt.Errorf("unexpected HTTP response status %d", res.StatusCode) |
Description:
Merged BuiltKite detector in one package with
v1
andv2
versionCreated one verification func to be used in both as both are calling same API
Tested locally with secrets and both are working fine.
JIRA Ticket:
OSS-55
Checklist:
make test-community
)?make lint
this requires golangci-lint)?