Skip to content

Commit 64a0e95

Browse files
committed
chore(bitbucketapppassword): introduce io.Discard, body.Close on res call in verify func
1 parent b27eb6e commit 64a0e95

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

pkg/detectors/bitbucketapppassword/bitbucketapppassword.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"encoding/base64"
66
"fmt"
7+
"io"
78
"net/http"
89
"regexp"
910
"strings"
@@ -41,6 +42,14 @@ func (s *Scanner) Keywords() []string {
4142
return []string{"bitbucket", "ATBB"}
4243
}
4344

45+
func (s *Scanner) Type() detectorspb.DetectorType {
46+
return detectorspb.DetectorType_BitbucketAppPassword
47+
}
48+
49+
func (s *Scanner) Description() string {
50+
return "Bitbucket is a Git repository hosting service by Atlassian. Bitbucket App Passwords are used to authenticate to the Bitbucket API."
51+
}
52+
4453
// FromData will find and optionally verify Bitbucket App Password secrets in a given set of bytes.
4554
func (s *Scanner) FromData(ctx context.Context, verify bool, data []byte) (results []detectors.Result, err error) {
4655
dataStr := string(data)
@@ -93,7 +102,10 @@ func (s *Scanner) verify(ctx context.Context, username, password string) (bool,
93102
if err != nil {
94103
return false, err
95104
}
96-
defer res.Body.Close()
105+
defer func() {
106+
_, _ = io.Copy(io.Discard, res.Body)
107+
_ = res.Body.Close()
108+
}()
97109

98110
switch res.StatusCode {
99111
case http.StatusOK:
@@ -107,11 +119,3 @@ func (s *Scanner) verify(ctx context.Context, username, password string) (bool,
107119
return false, fmt.Errorf("unexpected status code: %d", res.StatusCode)
108120
}
109121
}
110-
111-
func (s *Scanner) Type() detectorspb.DetectorType {
112-
return detectorspb.DetectorType_BitbucketAppPassword
113-
}
114-
115-
func (s *Scanner) Description() string {
116-
return "Bitbucket is a Git repository hosting service by Atlassian. Bitbucket App Passwords are used to authenticate to the Bitbucket API."
117-
}

0 commit comments

Comments
 (0)