Skip to content

Commit d49bdf7

Browse files
authored
Add staticcheck to console API (#2883)
1 parent 559a727 commit d49bdf7

24 files changed

+78
-109
lines changed

.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ linters:
2323
- gomodguard
2424
- gofmt
2525
- unused
26+
- staticcheck
2627
- unconvert
27-
- varcheck
2828
- gocritic
2929
- gofumpt
3030
- durationcheck

cmd/console/server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package main
1818

1919
import (
2020
"fmt"
21-
"io/ioutil"
21+
"os"
2222
"path/filepath"
2323
"syscall"
2424

@@ -163,7 +163,7 @@ func loadAllCerts(ctx *cli.Context) error {
163163

164164
// load ca cert from swagger server tls-ca flag
165165
if swaggerServerCACertificate != "" {
166-
caCert, caCertErr := ioutil.ReadFile(swaggerServerCACertificate)
166+
caCert, caCertErr := os.ReadFile(swaggerServerCACertificate)
167167
if caCertErr == nil {
168168
restapi.GlobalRootCAs.AppendCertsFromPEM(caCert)
169169
}

integration/login_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"bytes"
2121
"encoding/json"
2222
"fmt"
23-
"io/ioutil"
23+
"io"
2424
"log"
2525
"net/http"
2626
"testing"
@@ -56,7 +56,7 @@ func TestLoginStrategy(t *testing.T) {
5656
}
5757

5858
if response != nil {
59-
bodyBytes, _ := ioutil.ReadAll(response.Body)
59+
bodyBytes, _ := io.ReadAll(response.Body)
6060

6161
loginDetails := models.LoginDetails{}
6262

integration/policy_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"encoding/base64"
2222
"encoding/json"
2323
"fmt"
24-
"io/ioutil"
24+
"io"
2525
"log"
2626
"net/http"
2727
"testing"
@@ -630,7 +630,7 @@ func Test_PolicyListUsersAPI(t *testing.T) {
630630
return
631631
}
632632
if response != nil {
633-
bodyBytes, _ := ioutil.ReadAll(response.Body)
633+
bodyBytes, _ := io.ReadAll(response.Body)
634634
assert.Equal(tt.expectedStatus, response.StatusCode, tt.name+" Failed")
635635
if response.StatusCode == 200 {
636636
assert.Equal("[\"policyuser4\"]\n", string(bodyBytes))
@@ -709,7 +709,7 @@ func Test_PolicyListGroupsAPI(t *testing.T) {
709709
return
710710
}
711711
if response != nil {
712-
bodyBytes, _ := ioutil.ReadAll(response.Body)
712+
bodyBytes, _ := io.ReadAll(response.Body)
713713
assert.Equal(tt.expectedStatus, response.StatusCode, tt.name+" Failed")
714714
if response.StatusCode == 200 {
715715
assert.Equal("[\"testgroup12345\"]\n", string(bodyBytes))

integration/user_api_bucket_test.go

Lines changed: 31 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"errors"
2626
"fmt"
2727
"io"
28-
"io/ioutil"
2928
"log"
3029
"net/http"
3130
"os"
@@ -777,7 +776,7 @@ func TestPutObjectsLegalholdStatus(t *testing.T) {
777776

778777
// Get versionID
779778
listResponse, _ := ListObjects(bucketName, prefix, "true")
780-
bodyBytes, _ := ioutil.ReadAll(listResponse.Body)
779+
bodyBytes, _ := io.ReadAll(listResponse.Body)
781780
listObjs := models.ListObjectsResponse{}
782781
err := json.Unmarshal(bodyBytes, &listObjs)
783782
if err != nil {
@@ -1058,7 +1057,7 @@ func TestDeleteObjectsRetentionStatus(t *testing.T) {
10581057

10591058
// Get versionID
10601059
listResponse, _ := ListObjects(bucketName, validPrefix, "true")
1061-
bodyBytes, _ := ioutil.ReadAll(listResponse.Body)
1060+
bodyBytes, _ := io.ReadAll(listResponse.Body)
10621061
listObjs := models.ListObjectsResponse{}
10631062
err := json.Unmarshal(bodyBytes, &listObjs)
10641063
if err != nil {
@@ -1226,7 +1225,7 @@ func TestRestoreObjectToASelectedVersion(t *testing.T) {
12261225

12271226
// 3. Get versionID
12281227
listResponse, _ := ListObjects(bucketName, validPrefix, "true")
1229-
bodyBytes, _ := ioutil.ReadAll(listResponse.Body)
1228+
bodyBytes, _ := io.ReadAll(listResponse.Body)
12301229
listObjs := models.ListObjectsResponse{}
12311230
err := json.Unmarshal(bodyBytes, &listObjs)
12321231
if err != nil {
@@ -1443,7 +1442,7 @@ func TestPutObjectsRetentionStatus(t *testing.T) {
14431442

14441443
// Get versionID
14451444
listResponse, _ := ListObjects(bucketName, prefix, "true")
1446-
bodyBytes, _ := ioutil.ReadAll(listResponse.Body)
1445+
bodyBytes, _ := io.ReadAll(listResponse.Body)
14471446
listObjs := models.ListObjectsResponse{}
14481447
err := json.Unmarshal(bodyBytes, &listObjs)
14491448
if err != nil {
@@ -1776,7 +1775,7 @@ func TestDownloadObject(t *testing.T) {
17761775
}
17771776

17781777
// 4. Verify the file was downloaded
1779-
files, err := ioutil.ReadDir(workingDirectory)
1778+
files, err := os.ReadDir(workingDirectory)
17801779
if err != nil {
17811780
log.Fatal(err)
17821781
}
@@ -2169,21 +2168,12 @@ func TestListBuckets(t *testing.T) {
21692168
// 2. List buckets
21702169
listBucketsResponse, listBucketsError := ListBuckets()
21712170
assert.Nil(listBucketsError)
2172-
if listBucketsError != nil {
2173-
log.Println(listBucketsError)
2174-
assert.Fail("Error listing the buckets")
2175-
return
2176-
}
2177-
2171+
assert.NotNil(listBucketsResponse)
2172+
assert.NotNil(listBucketsResponse.Body)
21782173
// 3. Verify list of buckets
2179-
b, err := io.ReadAll(listBucketsResponse.Body)
2180-
if listBucketsResponse != nil {
2181-
if err != nil {
2182-
log.Fatalln(err)
2183-
}
2184-
assert.Equal(200, listBucketsResponse.StatusCode,
2185-
"Status Code is incorrect: "+string(b))
2186-
}
2174+
b, _ := io.ReadAll(listBucketsResponse.Body)
2175+
assert.Equal(200, listBucketsResponse.StatusCode,
2176+
"Status Code is incorrect: "+string(b))
21872177
for i := 1; i <= numberOfBuckets; i++ {
21882178
assert.True(strings.Contains(string(b),
21892179
"testlistbuckets"+strconv.Itoa(i)))
@@ -2215,7 +2205,7 @@ func TestBucketsGet(t *testing.T) {
22152205

22162206
if response != nil {
22172207
assert.Equal(200, response.StatusCode, "Status Code is incorrect")
2218-
bodyBytes, _ := ioutil.ReadAll(response.Body)
2208+
bodyBytes, _ := io.ReadAll(response.Body)
22192209

22202210
listBuckets := models.ListBucketsResponse{}
22212211
err = json.Unmarshal(bodyBytes, &listBuckets)
@@ -2255,7 +2245,7 @@ func TestBucketVersioning(t *testing.T) {
22552245

22562246
if response != nil {
22572247

2258-
bodyBytes, _ := ioutil.ReadAll(response.Body)
2248+
bodyBytes, _ := io.ReadAll(response.Body)
22592249

22602250
sessionResponse := models.SessionResponse{}
22612251
err = json.Unmarshal(bodyBytes, &sessionResponse)
@@ -2292,7 +2282,7 @@ func TestBucketVersioning(t *testing.T) {
22922282
assert.Equal(
22932283
200, getVersioningResult.StatusCode, "Status Code is incorrect")
22942284
}
2295-
bodyBytes, _ := ioutil.ReadAll(getVersioningResult.Body)
2285+
bodyBytes, _ := io.ReadAll(getVersioningResult.Body)
22962286
structBucketRepl := models.BucketVersioningResponse{
22972287
ExcludeFolders: false,
22982288
ExcludedPrefixes: nil,
@@ -2369,7 +2359,7 @@ func TestSetBucketTags(t *testing.T) {
23692359
request.Header.Add("Cookie", fmt.Sprintf("token=%s", token))
23702360
request.Header.Add("Content-Type", "application/json")
23712361

2372-
response, err := client.Do(request)
2362+
_, err = client.Do(request)
23732363
assert.Nil(err)
23742364
if err != nil {
23752365
log.Println(err)
@@ -2387,14 +2377,14 @@ func TestSetBucketTags(t *testing.T) {
23872377
request.Header.Add("Cookie", fmt.Sprintf("token=%s", token))
23882378
request.Header.Add("Content-Type", "application/json")
23892379

2390-
response, err = client.Do(request)
2380+
response, err := client.Do(request)
23912381
assert.Nil(err)
23922382
if err != nil {
23932383
log.Println(err)
23942384
return
23952385
}
23962386

2397-
bodyBytes, _ := ioutil.ReadAll(response.Body)
2387+
bodyBytes, _ := io.ReadAll(response.Body)
23982388

23992389
bucket := models.Bucket{}
24002390
err = json.Unmarshal(bodyBytes, &bucket)
@@ -2847,7 +2837,7 @@ func TestReplication(t *testing.T) {
28472837
}
28482838

28492839
// 3. Get rule ID and status from response's body
2850-
bodyBytes, _ := ioutil.ReadAll(response.Body)
2840+
bodyBytes, _ := io.ReadAll(response.Body)
28512841
structBucketRepl := models.BucketReplicationResponse{}
28522842
err = json.Unmarshal(bodyBytes, &structBucketRepl)
28532843
if err != nil {
@@ -2929,7 +2919,7 @@ func TestReplication(t *testing.T) {
29292919
}
29302920

29312921
// 9. Get rule ID and status from response's body
2932-
bodyBytes, _ = ioutil.ReadAll(response.Body)
2922+
bodyBytes, _ = io.ReadAll(response.Body)
29332923
structBucketRepl = models.BucketReplicationResponse{}
29342924
err = json.Unmarshal(bodyBytes, &structBucketRepl)
29352925
if err != nil {
@@ -2996,7 +2986,7 @@ func TestReturnsTheStatusOfObjectLockingSupportOnTheBucket(t *testing.T) {
29962986
}
29972987

29982988
// 2. Verify the status to be enabled for this bucket
2999-
bodyBytes, _ := ioutil.ReadAll(response.Body)
2989+
bodyBytes, _ := io.ReadAll(response.Body)
30002990
structBucketLocking := models.BucketObLockingResponse{}
30012991
err = json.Unmarshal(bodyBytes, &structBucketLocking)
30022992
if err != nil {
@@ -3077,7 +3067,7 @@ func TestSetBucketVersioning(t *testing.T) {
30773067
assert.Equal(
30783068
200, getVersioningResult.StatusCode, "Status Code is incorrect")
30793069
}
3080-
bodyBytes, _ := ioutil.ReadAll(getVersioningResult.Body)
3070+
bodyBytes, _ := io.ReadAll(getVersioningResult.Body)
30813071
result := models.BucketVersioningResponse{
30823072
ExcludeFolders: false,
30833073
ExcludedPrefixes: nil,
@@ -3160,7 +3150,7 @@ func TestEnableBucketEncryption(t *testing.T) {
31603150
assert.Equal(
31613151
200, resp.StatusCode, "Status Code is incorrect")
31623152
}
3163-
bodyBytes, _ := ioutil.ReadAll(resp.Body)
3153+
bodyBytes, _ := io.ReadAll(resp.Body)
31643154
result := models.BucketEncryptionInfo{}
31653155
err = json.Unmarshal(bodyBytes, &result)
31663156
if err != nil {
@@ -3192,7 +3182,7 @@ func TestEnableBucketEncryption(t *testing.T) {
31923182
assert.Equal(
31933183
404, resp.StatusCode, "Status Code is incorrect")
31943184
}
3195-
bodyBytes, _ = ioutil.ReadAll(resp.Body)
3185+
bodyBytes, _ = io.ReadAll(resp.Body)
31963186
result2 := models.Error{}
31973187
err = json.Unmarshal(bodyBytes, &result2)
31983188
if err != nil {
@@ -3437,7 +3427,7 @@ func TestBucketLifeCycle(t *testing.T) {
34373427
assert.Equal(
34383428
200, resp.StatusCode, "Status Code is incorrect")
34393429
}
3440-
bodyBytes, _ := ioutil.ReadAll(resp.Body)
3430+
bodyBytes, _ := io.ReadAll(resp.Body)
34413431
result := models.BucketLifecycleResponse{}
34423432
err = json.Unmarshal(bodyBytes, &result)
34433433
if err != nil {
@@ -3483,7 +3473,7 @@ func TestBucketLifeCycle(t *testing.T) {
34833473
assert.Equal(
34843474
200, resp.StatusCode, "Status Code is incorrect")
34853475
}
3486-
bodyBytes, _ = ioutil.ReadAll(resp.Body)
3476+
bodyBytes, _ = io.ReadAll(resp.Body)
34873477
result = models.BucketLifecycleResponse{}
34883478
err = json.Unmarshal(bodyBytes, &result)
34893479
if err != nil {
@@ -3643,7 +3633,7 @@ func TestAccessRule(t *testing.T) {
36433633
assert.Equal(
36443634
200, resp.StatusCode, "Status Code is incorrect")
36453635
}
3646-
bodyBytes, _ := ioutil.ReadAll(resp.Body)
3636+
bodyBytes, _ := io.ReadAll(resp.Body)
36473637
result := models.ListAccessRulesResponse{}
36483638
err = json.Unmarshal(bodyBytes, &result)
36493639
if err != nil {
@@ -3681,7 +3671,7 @@ func TestAccessRule(t *testing.T) {
36813671
assert.Equal(
36823672
200, resp.StatusCode, "Status Code is incorrect")
36833673
}
3684-
bodyBytes, _ = ioutil.ReadAll(resp.Body)
3674+
bodyBytes, _ = io.ReadAll(resp.Body)
36853675
result = models.ListAccessRulesResponse{}
36863676
err = json.Unmarshal(bodyBytes, &result)
36873677
if err != nil {
@@ -3950,21 +3940,13 @@ func TestDeleteRemoteBucket(t *testing.T) {
39503940
// 3. Get ARN
39513941
resp, err = GetRemoteBucketARN(sourceBucket)
39523942
assert.Nil(err)
3953-
if err != nil {
3954-
log.Println(err)
3955-
return
3956-
}
3957-
bodyBytes, _ := ioutil.ReadAll(resp.Body)
3943+
assert.NotNil(resp)
3944+
assert.NotNil(resp.Body)
3945+
bodyBytes, _ := io.ReadAll(resp.Body)
39583946
remoteBucket := models.RemoteBucket{}
39593947
err = json.Unmarshal(bodyBytes, &remoteBucket)
3960-
if err != nil {
3961-
log.Println(err)
3962-
assert.Nil(err)
3963-
}
3964-
if resp != nil {
3965-
assert.Equal(
3966-
200, resp.StatusCode, inspectHTTPResponse(resp))
3967-
}
3948+
assert.Nil(err)
3949+
assert.Equal(200, resp.StatusCode, inspectHTTPResponse(resp))
39683950

39693951
// 4. Delete Remote Bucket
39703952
if remoteBucket.RemoteARN != nil {

pkg/auth/idp/oauth2/provider.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,23 +69,23 @@ type DiscoveryDoc struct {
6969
}
7070

7171
func (ac Config) Exchange(ctx context.Context, code string, opts ...xoauth2.AuthCodeOption) (*xoauth2.Token, error) {
72-
return ac.Exchange(ctx, code, opts...)
72+
return ac.Config.Exchange(ctx, code, opts...)
7373
}
7474

7575
func (ac Config) AuthCodeURL(state string, opts ...xoauth2.AuthCodeOption) string {
76-
return ac.AuthCodeURL(state, opts...)
76+
return ac.Config.AuthCodeURL(state, opts...)
7777
}
7878

7979
func (ac Config) PasswordCredentialsToken(ctx context.Context, username, password string) (*xoauth2.Token, error) {
80-
return ac.PasswordCredentialsToken(ctx, username, password)
80+
return ac.Config.PasswordCredentialsToken(ctx, username, password)
8181
}
8282

8383
func (ac Config) Client(ctx context.Context, t *xoauth2.Token) *http.Client {
84-
return ac.Client(ctx, t)
84+
return ac.Config.Client(ctx, t)
8585
}
8686

8787
func (ac Config) TokenSource(ctx context.Context, t *xoauth2.Token) xoauth2.TokenSource {
88-
return ac.TokenSource(ctx, t)
88+
return ac.Config.TokenSource(ctx, t)
8989
}
9090

9191
// Provider is a wrapper of the oauth2 configuration and the oidc provider

pkg/auth/token.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
"errors"
2929
"fmt"
3030
"io"
31-
"io/ioutil"
3231
"net/http"
3332
"strings"
3433
"time"
@@ -295,7 +294,7 @@ func decrypt(ciphertext, associatedData []byte) ([]byte, error) {
295294
return nil, fmt.Errorf("invalid nonce size %d, expected %d", len(nonce), aead.NonceSize())
296295
}
297296

298-
sealedBytes, err := ioutil.ReadAll(r)
297+
sealedBytes, err := io.ReadAll(r)
299298
if err != nil {
300299
return nil, err
301300
}

0 commit comments

Comments
 (0)