Add staticcheck to console API (#2883)

This commit is contained in:
Javier Adriel
2023-06-14 21:35:00 -06:00
committed by GitHub
parent 559a7278a0
commit d49bdf7d49
24 changed files with 78 additions and 109 deletions

View File

@@ -304,11 +304,11 @@ func importConfigResponse(session *models.Principal, params cfgApi.PostConfigsIm
return nil, ErrorWithContext(ctx, err)
}
file, _, err := params.HTTPRequest.FormFile("file")
defer file.Close()
if err != nil {
return nil, ErrorWithContext(ctx, err)
}
defer file.Close()
err = mAdmin.SetConfig(ctx, file)
if err != nil {
return nil, ErrorWithContext(ctx, err)

View File

@@ -227,7 +227,7 @@ func TestHeal(t *testing.T) {
req = &http.Request{
URL: u,
}
opts, err = getHealOptionsFromReq(req)
_, err = getHealOptionsFromReq(req)
if assert.Error(err) {
assert.Equal("strconv.ParseBool: parsing \"nonbool\": invalid syntax", err.Error())
}
@@ -236,7 +236,7 @@ func TestHeal(t *testing.T) {
req = &http.Request{
URL: u,
}
opts, err = getHealOptionsFromReq(req)
_, err = getHealOptionsFromReq(req)
if assert.Error(err) {
assert.Equal("strconv.ParseBool: parsing \"nonbool\": invalid syntax", err.Error())
}
@@ -245,7 +245,7 @@ func TestHeal(t *testing.T) {
req = &http.Request{
URL: u,
}
opts, err = getHealOptionsFromReq(req)
_, err = getHealOptionsFromReq(req)
if assert.Error(err) {
assert.Equal("strconv.ParseBool: parsing \"nonbool\": invalid syntax", err.Error())
}
@@ -254,7 +254,7 @@ func TestHeal(t *testing.T) {
req = &http.Request{
URL: u,
}
opts, err = getHealOptionsFromReq(req)
_, err = getHealOptionsFromReq(req)
if assert.Error(err) {
assert.Equal("strconv.ParseBool: parsing \"nonbool\": invalid syntax", err.Error())
}
@@ -263,7 +263,7 @@ func TestHeal(t *testing.T) {
req = &http.Request{
URL: u,
}
opts, err = getHealOptionsFromReq(req)
_, err = getHealOptionsFromReq(req)
if assert.Error(err) {
assert.Equal("strconv.ParseBool: parsing \"nonbool\": invalid syntax", err.Error())
}

View File

@@ -32,7 +32,7 @@ type objectsListOpts struct {
}
type ObjectsRequest struct {
Mode string `json:"mode,nonempty"`
Mode string `json:"mode,omitempty"`
BucketName string `json:"bucket_name"`
Prefix string `json:"prefix"`
Date string `json:"date"`
@@ -40,7 +40,7 @@ type ObjectsRequest struct {
}
type WSResponse struct {
RequestID int64 `json:"request_id,nonempty"`
RequestID int64 `json:"request_id,omitempty"`
Error string `json:"error,omitempty"`
RequestEnd bool `json:"request_end,omitempty"`
Prefix string `json:"prefix,omitempty"`
@@ -49,10 +49,10 @@ type WSResponse struct {
}
type ObjectResponse struct {
Name string `json:"name,nonempty"`
LastModified string `json:"last_modified,nonempty"`
Size int64 `json:"size,nonempty"`
VersionID string `json:"version_id,nonempty"`
Name string `json:"name,omitempty"`
LastModified string `json:"last_modified,omitempty"`
Size int64 `json:"size,omitempty"`
VersionID string `json:"version_id,omitempty"`
DeleteMarker bool `json:"delete_flag,omitempty"`
IsLatest bool `json:"is_latest,omitempty"`
}

View File

@@ -351,7 +351,7 @@ func getListUsersForPolicyResponse(session *models.Principal, params policyApi.L
}
func getUserPolicyResponse(ctx context.Context, session *models.Principal) (string, *models.Error) {
ctx, cancel := context.WithCancel(context.Background())
ctx, cancel := context.WithCancel(ctx)
defer cancel()
// serialize output
if session == nil {

View File

@@ -18,7 +18,7 @@ package restapi
import (
"context"
"io/ioutil"
"io"
"net/http"
"github.com/minio/console/models"
@@ -55,7 +55,7 @@ func startProfiling(ctx context.Context, conn WSConn, client MinioAdmin, pOpts *
if err != nil {
return err
}
message, err := ioutil.ReadAll(zippedData)
message, err := io.ReadAll(zippedData)
if err != nil {
return err
}

View File

@@ -64,10 +64,6 @@ func getSpeedtestOptionsFromReq(req *http.Request) (*madmin.SpeedtestOpts, error
return nil, fmt.Errorf("unable to parse object size")
}
if size < 0 {
return nil, fmt.Errorf("size is expected to be atleast 0 bytes")
}
optionsSet.Size = int(size)
paramConcurrent := queryPairs.Get("concurrent")

View File

@@ -59,7 +59,7 @@ func TestAddServiceAccount(t *testing.T) {
minioAddServiceAccountMock = func(ctx context.Context, policy *iampolicy.Policy, user string, accessKey string, secretKey string) (madmin.Credentials, error) {
return mockResponse, nil
}
saCreds, err = createServiceAccount(ctx, client, policyDefinition)
_, err = createServiceAccount(ctx, client, policyDefinition)
assert.Error(err)
// Test-3: if an error occurs on server while creating service account (valid policy), handle it

View File

@@ -184,7 +184,7 @@ type VersionState string
const (
VersionEnable VersionState = "enable"
VersionSuspend = "suspend"
VersionSuspend VersionState = "suspend"
)
// removeBucket deletes a bucket
@@ -210,7 +210,7 @@ func setBucketVersioningResponse(session *models.Principal, params bucketApi.Set
// defining the client to be used
amcClient := mcClient{client: s3Client}
var versioningState VersionState = VersionSuspend
versioningState := VersionSuspend
if params.Body.Versioning {
versioningState = VersionEnable

View File

@@ -56,6 +56,7 @@ func registerSessionHandlers(api *operations.ConsoleAPI) {
func getClaimsFromToken(sessionToken string) (map[string]interface{}, error) {
jp := new(jwtgo.Parser)
// nolint:staticcheck // ignore SA1019
jp.ValidMethods = []string{
"RS256", "RS384", "RS512", "ES256", "ES384", "ES512",
"RS3256", "RS3384", "RS3512", "ES3256", "ES3384", "ES3512",

View File

@@ -291,10 +291,10 @@ func TestWatch(t *testing.T) {
}
// Test-9: getWatchOptionsFromReq invalid url
u, err = url.Parse("http://localhost/api/v1/wach/bucket2?prefix=&suffix=")
u, _ = url.Parse("http://localhost/api/v1/wach/bucket2?prefix=&suffix=")
req = &http.Request{
URL: u,
}
opts, err = getWatchOptionsFromReq(req)
_, err = getWatchOptionsFromReq(req)
assert.Error(err)
}