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

update linter go version #264

Merged
merged 10 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/actions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
uses: dell/common-github-actions/go-code-tester@main
with:
threshold: 90
skip-list: "karavi-authorization/deploy,karavi-authorization/internal/web,karavi-authorization/internal/tenantsvc,karavi-authorization/cmd/karavictl/cmd,karavi-authorization/cmd/proxy-server,karavi-authorization/cmd/tenant-service,karavi-authorization/internal/proxy,karavi-authorization/internal/tenantsvc,karavi-authorization/internal/token/jwx,karavi-authorization/internal/k8s,karavi-authorization/internal/role-service,karavi-authorization/internal/role-service/validate"
skip-list: "karavi-authorization/deploy,karavi-authorization/internal/web,karavi-authorization/internal/tenantsvc,karavi-authorization/cmd/karavictl/cmd,karavi-authorization/cmd/proxy-server,karavi-authorization/cmd/tenant-service,karavi-authorization/internal/proxy,karavi-authorization/internal/tenantsvc,karavi-authorization/internal/token/jwx,karavi-authorization/internal/k8s,karavi-authorization/internal/role-service,karavi-authorization/internal/role-service/validate,karavi-authorization/internal/storage-service,karavi-authorization/internal/storage-service/middleware,karavi-authorization/internal/token"
env:
# The hostname used to communicate with the Redis service container
REDIS_HOST: redis
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/linters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
steps:
- uses: actions/setup-go@v5
with:
go-version: "1.21"
go-version: "1.22"
cache: false
- name: Checkout the code
uses: actions/checkout@v4
Expand Down
3 changes: 0 additions & 3 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
run:
timeout: 20m
issue-exit-code: 0 # we will change this later
tests: true
skip-dirs-use-default: true
modules-download-mode: readonly
Expand All @@ -26,8 +25,6 @@ linters:
enable:
# A stricter replacement for gofmt.
- gofumpt
# Inspects source code for security problems.
- gosec
# Check for correctness of programs.
- govet
# Drop-in replacement of golint.
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,7 @@ package:
.PHONY: download-csm-common
download-csm-common:
curl -O -L https://raw.githubusercontent.com/dell/csm/main/config/csm-common.mk

.PHONY: lint
lint:
golangci-lint run --fix
2 changes: 1 addition & 1 deletion cmd/karavictl/cmd/cluster_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func NewClusterInfoCmd() *cobra.Command {
Use: "cluster-info",
Short: "Display the state of resources within the cluster",
Long: `Prints table of resources within the cluster, including their readiness`,
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
cmdArgs := []string{"kubectl", "get", "deploy", "-n", "karavi"}
if v, _ := cmd.Flags().GetBool("watch"); v {
cmdArgs = append(cmdArgs, "--watch")
Expand Down
2 changes: 1 addition & 1 deletion cmd/karavictl/cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func NewGenerateCmd() *cobra.Command {
Use: "generate",
Short: "Generate resources for use with Karavi",
Long: `Generates resources for use with Karavi`,
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
err := cmd.Usage()
if err != nil {
reportErrorAndExit(JSONOutput, os.Stderr, err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/karavictl/cmd/generate_admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func NewAdminCmd() *cobra.Command {
Use: "admin",
Short: "Generate admin token for use with CSM Authorization",
Long: `Generate admin token for use with CSM Authorization`,
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
err := cmd.Usage()
if err != nil {
reportErrorAndExit(JSONOutput, os.Stderr, err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/karavictl/cmd/generate_admin_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func NewAdminTokenCmd() *cobra.Command {
Use: "token",
Short: "Generate tokens for an admin.",
Long: `Generates tokens for an admin.`,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, _ []string) error {
adminName, err := cmd.Flags().GetString("name")
if err != nil {
reportErrorAndExit(JSONOutput, cmd.ErrOrStderr(), err)
Expand Down
4 changes: 2 additions & 2 deletions cmd/karavictl/cmd/generate_admin_token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ func TestGenerateAdminToken(t *testing.T) {
}
t.Run("it requests creation of admin token", func(t *testing.T) {
defer afterFn()
JSONOutput = func(w io.Writer, _ interface{}) error {
JSONOutput = func(_ io.Writer, _ interface{}) error {
return nil
}
osExit = func(code int) {
osExit = func(_ int) {
}
var gotOutput bytes.Buffer

Expand Down
2 changes: 1 addition & 1 deletion cmd/karavictl/cmd/generate_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func NewGenerateTokenCmd() *cobra.Command {
Use: "token",
Short: "Generate tokens for a tenant.",
Long: `Generates tokens for a tenant.`,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, _ []string) error {
addr, err := cmd.Flags().GetString("addr")
if err != nil {
reportErrorAndExit(JSONOutput, cmd.ErrOrStderr(), err)
Expand Down
5 changes: 1 addition & 4 deletions cmd/karavictl/cmd/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func NewRoleCmd() *cobra.Command {
Use: "role",
Short: "Manage roles",
Long: `Manage roles`,
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
if err := cmd.Usage(); err != nil {
reportErrorAndExit(JSONOutput, cmd.ErrOrStderr(), fmt.Errorf("error: %+v", err))
}
Expand Down Expand Up @@ -192,7 +192,6 @@ func validatePowerFlexPool(storageSystemDetails System, storageSystemID string,
Username: storageSystemDetails.User,
Password: storageSystemDetails.Password,
})

if err != nil {
return fmt.Errorf("powerflex authentication failed: %+v", err)
}
Expand Down Expand Up @@ -377,7 +376,6 @@ func createRoleServiceClient(addr string, insecure bool) (pb.RoleServiceClient,
})
}),
grpc.WithInsecure())

if err != nil {
log.Fatal(err)
}
Expand All @@ -392,7 +390,6 @@ func createRoleServiceClient(addr string, insecure bool) (pb.RoleServiceClient,
conn, err = grpc.Dial(addr,
grpc.WithTransportCredentials(creds),
grpc.WithTimeout(10*time.Second))

if err != nil {
log.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/karavictl/cmd/role_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func NewRoleCreateCmd() *cobra.Command {
Use: "create",
Short: "Create one or more CSM roles",
Long: `Creates one or more CSM roles`,
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
outFormat := "failed to create role: %+v\n"

// parse flags
Expand Down
20 changes: 10 additions & 10 deletions cmd/karavictl/cmd/role_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,21 @@ func TestRoleCreateHandler(t *testing.T) {
t.Run("it requests creation of a role", func(t *testing.T) {
defer afterFn()
var gotCalled bool
CreateHTTPClient = func(addr string, insecure bool) (api.Client, error) {
CreateHTTPClient = func(_ string, _ bool) (api.Client, error) {
return &mocks.FakeClient{
PostFn: func(ctx context.Context, path string, headers map[string]string, query url.Values, body, resp interface{}) error {
PostFn: func(_ context.Context, _ string, _ map[string]string, _ url.Values, _, _ interface{}) error {
gotCalled = true
return nil
},
}, nil
}
ReadAccessAdminToken = func(afile string) (string, string, error) {
ReadAccessAdminToken = func(_ string) (string, string, error) {
return "AUnumberTokenIsNotWorkingman", "AUnumberTokenIsNotWorkingman", nil
}
JSONOutput = func(w io.Writer, _ interface{}) error {
JSONOutput = func(_ io.Writer, _ interface{}) error {
return nil
}
osExit = func(code int) {
osExit = func(_ int) {
}
var gotOutput bytes.Buffer

Expand All @@ -70,10 +70,10 @@ func TestRoleCreateHandler(t *testing.T) {
})
t.Run("it requires a valid role server connection", func(t *testing.T) {
defer afterFn()
CreateHTTPClient = func(addr string, insecure bool) (api.Client, error) {
CreateHTTPClient = func(_ string, _ bool) (api.Client, error) {
return nil, errors.New("failed to create role: test server error")
}
ReadAccessAdminToken = func(afile string) (string, string, error) {
ReadAccessAdminToken = func(_ string) (string, string, error) {
return "AUnumberTokenIsNotWorkingman", "AUnumberTokenIsNotWorkingman", nil
}
var gotCode int
Expand Down Expand Up @@ -106,14 +106,14 @@ func TestRoleCreateHandler(t *testing.T) {
})
t.Run("it handles server errors", func(t *testing.T) {
defer afterFn()
CreateHTTPClient = func(addr string, insecure bool) (api.Client, error) {
CreateHTTPClient = func(_ string, _ bool) (api.Client, error) {
return &mocks.FakeClient{
PostFn: func(ctx context.Context, path string, headers map[string]string, query url.Values, body, resp interface{}) error {
PostFn: func(_ context.Context, _ string, _ map[string]string, _ url.Values, _, _ interface{}) error {
return errors.New("failed to create role: test error")
},
}, nil
}
ReadAccessAdminToken = func(afile string) (string, string, error) {
ReadAccessAdminToken = func(_ string) (string, string, error) {
return "AUnumberTokenIsNotWorkingman", "AUnumberTokenIsNotWorkingman", nil
}
var gotCode int
Expand Down
2 changes: 1 addition & 1 deletion cmd/karavictl/cmd/role_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func NewRoleDeleteCmd() *cobra.Command {
Use: "delete",
Short: "Delete one or more CSM roles",
Long: `Delete one or mroe CSM roles`,
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

Expand Down
20 changes: 10 additions & 10 deletions cmd/karavictl/cmd/role_delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,20 @@ func TestRoleDeleteHandler(t *testing.T) {
t.Run("it requests creation of a role", func(t *testing.T) {
defer afterFn()
var gotCalled bool
CreateHTTPClient = func(addr string, insecure bool) (api.Client, error) {
CreateHTTPClient = func(_ string, _ bool) (api.Client, error) {
return &mocks.FakeClient{
DeleteFn: func(ctx context.Context, path string, headers map[string]string, query url.Values, body, resp interface{}) error {
DeleteFn: func(_ context.Context, _ string, _ map[string]string, _ url.Values, _, _ interface{}) error {
gotCalled = true
return nil
},
}, nil
}
JSONOutput = func(w io.Writer, _ interface{}) error {
JSONOutput = func(_ io.Writer, _ interface{}) error {
return nil
}
osExit = func(code int) {
osExit = func(_ int) {
}
ReadAccessAdminToken = func(afile string) (string, string, error) {
ReadAccessAdminToken = func(_ string) (string, string, error) {
return "AUnumberTokenIsNotWorkingman", "AUnumberTokenIsNotWorkingman", nil
}
var gotOutput bytes.Buffer
Expand All @@ -72,7 +72,7 @@ func TestRoleDeleteHandler(t *testing.T) {

t.Run("it requires a valid role server connection", func(t *testing.T) {
defer afterFn()
CreateHTTPClient = func(addr string, insecure bool) (api.Client, error) {
CreateHTTPClient = func(_ string, _ bool) (api.Client, error) {
return nil, errors.New("failed to delete role: test server error")
}
var gotCode int
Expand All @@ -82,7 +82,7 @@ func TestRoleDeleteHandler(t *testing.T) {
done <- struct{}{}
done <- struct{}{} // we can't let this function return
}
ReadAccessAdminToken = func(afile string) (string, string, error) {
ReadAccessAdminToken = func(_ string) (string, string, error) {
return "AUnumberTokenIsNotWorkingman", "AUnumberTokenIsNotWorkingman", nil
}
var gotOutput bytes.Buffer
Expand All @@ -109,9 +109,9 @@ func TestRoleDeleteHandler(t *testing.T) {

t.Run("it handles server errors", func(t *testing.T) {
defer afterFn()
CreateHTTPClient = func(addr string, insecure bool) (api.Client, error) {
CreateHTTPClient = func(_ string, _ bool) (api.Client, error) {
return &mocks.FakeClient{
DeleteFn: func(ctx context.Context, path string, headers map[string]string, query url.Values, body, resp interface{}) error {
DeleteFn: func(_ context.Context, _ string, _ map[string]string, _ url.Values, _, _ interface{}) error {
return errors.New("failed to delete role: test error")
},
}, nil
Expand All @@ -123,7 +123,7 @@ func TestRoleDeleteHandler(t *testing.T) {
done <- struct{}{}
done <- struct{}{} // we can't let this function return
}
ReadAccessAdminToken = func(afile string) (string, string, error) {
ReadAccessAdminToken = func(_ string) (string, string, error) {
return "AUnumberTokenIsNotWorkingman", "AUnumberTokenIsNotWorkingman", nil
}
var gotOutput bytes.Buffer
Expand Down
2 changes: 1 addition & 1 deletion cmd/karavictl/cmd/role_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func NewRoleGetCmd() *cobra.Command {
Use: "get",
Short: "Get CSM role",
Long: `Get CSM role`,
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

Expand Down
18 changes: 9 additions & 9 deletions cmd/karavictl/cmd/role_get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ func TestRoleGetHandler(t *testing.T) {
t.Fatal(err)
}

CreateHTTPClient = func(addr string, insecure bool) (api.Client, error) {
CreateHTTPClient = func(_ string, _ bool) (api.Client, error) {
return &mocks.FakeClient{
GetFn: func(ctx context.Context, path string, headers map[string]string, query url.Values, resp interface{}) error {
GetFn: func(_ context.Context, _ string, _ map[string]string, _ url.Values, resp interface{}) error {
b64Content := base64.StdEncoding.EncodeToString([]byte(b))
jsonStr := fmt.Sprintf(`{"role": "%s"}`, b64Content)
err = json.Unmarshal([]byte(jsonStr), resp)
Expand All @@ -71,9 +71,9 @@ func TestRoleGetHandler(t *testing.T) {
}, nil
}

osExit = func(code int) {
osExit = func(_ int) {
}
ReadAccessAdminToken = func(afile string) (string, string, error) {
ReadAccessAdminToken = func(_ string) (string, string, error) {
return "AUnumberTokenIsNotWorkingman", "AUnumberTokenIsNotWorkingman", nil
}
var gotOutput bytes.Buffer
Expand All @@ -94,7 +94,7 @@ func TestRoleGetHandler(t *testing.T) {

t.Run("it requires a valid role server connection", func(t *testing.T) {
defer afterFn()
CreateHTTPClient = func(addr string, insecure bool) (api.Client, error) {
CreateHTTPClient = func(_ string, _ bool) (api.Client, error) {
return nil, errors.New("failed to get role: test server error")
}

Expand All @@ -105,7 +105,7 @@ func TestRoleGetHandler(t *testing.T) {
done <- struct{}{}
done <- struct{}{} // we can't let this function return
}
ReadAccessAdminToken = func(afile string) (string, string, error) {
ReadAccessAdminToken = func(_ string) (string, string, error) {
return "AUnumberTokenIsNotWorkingman", "AUnumberTokenIsNotWorkingman", nil
}
var gotOutput bytes.Buffer
Expand All @@ -132,14 +132,14 @@ func TestRoleGetHandler(t *testing.T) {

t.Run("it handles server errors", func(t *testing.T) {
defer afterFn()
CreateHTTPClient = func(addr string, insecure bool) (api.Client, error) {
CreateHTTPClient = func(_ string, _ bool) (api.Client, error) {
return &mocks.FakeClient{
GetFn: func(ctx context.Context, path string, headers map[string]string, query url.Values, resp interface{}) error {
GetFn: func(_ context.Context, _ string, _ map[string]string, _ url.Values, _ interface{}) error {
return errors.New("failed to get role: test error")
},
}, nil
}
ReadAccessAdminToken = func(afile string) (string, string, error) {
ReadAccessAdminToken = func(_ string) (string, string, error) {
return "AUnumberTokenIsNotWorkingman", "AUnumberTokenIsNotWorkingman", nil
}
var gotCode int
Expand Down
2 changes: 1 addition & 1 deletion cmd/karavictl/cmd/role_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func NewRoleListCmd() *cobra.Command {
Use: "list",
Short: "List CSM roles",
Long: `List CSM roles`,
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

Expand Down
Loading
Loading