Skip to content
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

Merged

Conversation

kashifkhan0771
Copy link
Contributor

@kashifkhan0771 kashifkhan0771 commented Nov 15, 2024

Description:

Merged BuiltKite detector in one package with v1 and v2 version
Created 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:

  • Tests passing (make test-community)?
  • Lint passing (make lint this requires golangci-lint)?

@kashifkhan0771 kashifkhan0771 requested review from a team as code owners November 15, 2024 06:23
}
isVerified, verificationErr := VerifyBuildKite(ctx, client, resMatch)
s1.Verified = isVerified
if verificationErr != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 86 to 96
res, err := client.Do(req)
if err == nil {
defer res.Body.Close()
if res.StatusCode >= 200 && res.StatusCode < 300 {
return true, nil
}
}
Copy link
Contributor

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.

defer func() {
_, _ = io.Copy(io.Discard, res.Body)
_ = res.Body.Close()
}()

@kashifkhan0771 kashifkhan0771 force-pushed the update/buildkite-detectors branch from 6a9bd56 to 3f3113b Compare November 18, 2024 06:25
@kashifkhan0771 kashifkhan0771 requested a review from rgmz November 18, 2024 08:32
}()

if res.StatusCode == http.StatusOK {
return true, nil
Copy link
Contributor

@rgmz rgmz Nov 18, 2024

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)

@kashifkhan0771 kashifkhan0771 requested a review from rgmz November 19, 2024 05:29
@kashifkhan0771 kashifkhan0771 requested a review from a team as a code owner November 20, 2024 05:41
@kashifkhan0771 kashifkhan0771 requested review from abmussani, zricethezav, nabeelalam and rgmz and removed request for rgmz November 20, 2024 05:41
@zricethezav zricethezav merged commit e494eaf into trufflesecurity:main Nov 21, 2024
13 checks passed
@kashifkhan0771 kashifkhan0771 deleted the update/buildkite-detectors branch November 22, 2024 08:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants