Skip to content

Commit

Permalink
Fix lint issues (#257)
Browse files Browse the repository at this point in the history
* Fix lint issues

* Ignore go mod libraries

* Fixed more lint errors

* Update linter version

* Set linter version to latest
  • Loading branch information
KerryKovacevic authored Jan 10, 2024
1 parent 3d8eadc commit 0767ae2
Show file tree
Hide file tree
Showing 66 changed files with 283 additions and 297 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.53
version: latest
skip-cache: true
4 changes: 4 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ run:
tests: true
skip-dirs-use-default: true
modules-download-mode: readonly
skip-dirs:
- go/pkg # remove third party mod lib from scanning
- go/src # remove third party mod lib from scanning
- hostedtoolcache # remove the mod caches from scanning

issues:
max-issues-per-linter: 0
Expand Down
34 changes: 18 additions & 16 deletions cmd/karavictl/cmd/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ type ClientOptions struct {

// New returns a new API client.
func New(
ctx context.Context,
_ context.Context,
host string,
opts ClientOptions) (Client, error) {

opts ClientOptions,
) (Client, error) {
if host == "" {
return nil, fmt.Errorf("host must not be empty")
}
Expand All @@ -102,10 +102,11 @@ func New(
host: host,
}

if opts.Insecure {
if opts.Insecure { // #nosec G402
c.http.Transport = &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
MinVersion: tls.VersionTLS13,
},
}
} else {
Expand All @@ -118,6 +119,7 @@ func New(
TLSClientConfig: &tls.Config{
RootCAs: pool,
InsecureSkipVerify: false,
MinVersion: tls.VersionTLS13,
},
}
}
Expand All @@ -131,8 +133,8 @@ func (c *client) Get(
path string,
headers map[string]string,
query url.Values,
resp interface{}) error {

resp interface{},
) error {
return c.DoWithHeaders(
ctx, http.MethodGet, path, headers, query, nil, resp)
}
Expand All @@ -143,8 +145,8 @@ func (c *client) Post(
path string,
headers map[string]string,
query url.Values,
body, resp interface{}) error {

body, resp interface{},
) error {
return c.DoWithHeaders(
ctx, http.MethodPost, path, headers, query, body, resp)
}
Expand All @@ -155,8 +157,8 @@ func (c *client) Patch(
path string,
headers map[string]string,
query url.Values,
body, resp interface{}) error {

body, resp interface{},
) error {
return c.DoWithHeaders(
ctx, http.MethodPatch, path, headers, query, body, resp)
}
Expand All @@ -167,8 +169,8 @@ func (c *client) Delete(
path string,
headers map[string]string,
query url.Values,
body, resp interface{}) error {

body, resp interface{},
) error {
return c.DoWithHeaders(
ctx, http.MethodDelete, path, headers, query, body, resp)
}
Expand All @@ -187,8 +189,8 @@ func (c *client) DoWithHeaders(
method, uri string,
headers map[string]string,
query url.Values,
body, resp interface{}) error {

body, resp interface{},
) error {
res, err := c.DoAndGetResponseBody(
ctx, method, uri, headers, query, body)
if err != nil {
Expand Down Expand Up @@ -217,8 +219,8 @@ func (c *client) DoAndGetResponseBody(
method, uri string,
headers map[string]string,
query url.Values,
body interface{}) (*http.Response, error) {

body interface{},
) (*http.Response, error) {
var (
err error
req *http.Request
Expand Down
12 changes: 8 additions & 4 deletions cmd/karavictl/cmd/api/mocks/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ func (f *FakeClient) Get(ctx context.Context,
path string,
headers map[string]string,
query url.Values,
resp interface{}) error {
resp interface{},
) error {
if f.GetFn != nil {
return f.GetFn(ctx, path, headers, query, resp)
}
Expand All @@ -53,7 +54,8 @@ func (f *FakeClient) Post(
path string,
headers map[string]string,
query url.Values,
body, resp interface{}) error {
body, resp interface{},
) error {
if f.PostFn != nil {
return f.PostFn(ctx, path, headers, query, body, resp)
}
Expand All @@ -66,7 +68,8 @@ func (f *FakeClient) Patch(
path string,
headers map[string]string,
query url.Values,
body, resp interface{}) error {
body, resp interface{},
) error {
if f.PatchFn != nil {
return f.PatchFn(ctx, path, headers, query, body, resp)
}
Expand All @@ -79,7 +82,8 @@ func (f *FakeClient) Delete(
path string,
headers map[string]string,
query url.Values,
body, resp interface{}) error {
body, resp interface{},
) error {
if f.DeleteFn != nil {
return f.DeleteFn(ctx, path, headers, query, body, resp)
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/karavictl/cmd/cluster_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ func NewClusterInfoCmd() *cobra.Command {
if v, _ := cmd.Flags().GetBool("watch"); v {
cmdArgs = append(cmdArgs, "--watch")
}
kCmd := exec.Command(K3sPath, cmdArgs...)
kCmd.Stdout = os.Stdout
err := kCmd.Start()
k3sCmd := exec.Command(K3sPath, cmdArgs...)
k3sCmd.Stdout = os.Stdout
err := k3sCmd.Start()
if err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)
}

if err := kCmd.Wait(); err != nil {
if err := k3sCmd.Wait(); err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)
}
Expand Down
1 change: 0 additions & 1 deletion cmd/karavictl/cmd/generate_admin_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ func NewAdminTokenCmd() *cobra.Command {
Short: "Generate tokens for an admin.",
Long: `Generates tokens for an admin.`,
RunE: func(cmd *cobra.Command, args []string) error {

adminName, err := cmd.Flags().GetString("name")
if err != nil {
reportErrorAndExit(JSONOutput, cmd.ErrOrStderr(), err)
Expand Down
5 changes: 2 additions & 3 deletions cmd/karavictl/cmd/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ func GetAuthorizedStorageSystems() (map[string]Storage, error) {
"secret/karavi-storage-secret")

b, err := k3sCmd.Output()

if err != nil {
return nil, err
}
Expand Down Expand Up @@ -245,7 +244,7 @@ func validatePowerMaxStorageResourcePool(ctx context.Context, storageSystemDetai
return nil
}

func validatePowerScaleIsiPath(storageSystemDetails System, storageSystemID string, poolQuota PoolQuota) error {
func validatePowerScaleIsiPath(storageSystemDetails System, _ string, poolQuota PoolQuota) error {
endpoint := GetPowerScaleEndpoint(storageSystemDetails)
epURL, err := url.Parse(endpoint)
if err != nil {
Expand Down Expand Up @@ -368,7 +367,7 @@ func createRoleServiceClient(addr string, insecure bool) (pb.RoleServiceClient,
var conn *grpc.ClientConn
var err error

if insecure {
if insecure { // #nosec G402
conn, err = grpc.Dial(addr,
grpc.WithTimeout(10*time.Second),
grpc.WithContextDialer(func(_ context.Context, addr string) (net.Conn, error) {
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 @@ -112,7 +112,7 @@ func NewRoleCreateCmd() *cobra.Command {
return roleCreateCmd
}

func doRoleCreateRequest(ctx context.Context, addr string, insecure bool, role *roles.Instance, cmd *cobra.Command, adminTknBody token.AdminToken) error {
func doRoleCreateRequest(_ context.Context, addr string, insecure bool, role *roles.Instance, cmd *cobra.Command, adminTknBody token.AdminToken) error {
client, err := CreateHTTPClient(fmt.Sprintf("https://%s", addr), insecure)
if err != nil {
reportErrorAndExit(JSONOutput, cmd.ErrOrStderr(), err)
Expand Down
5 changes: 2 additions & 3 deletions cmd/karavictl/cmd/role_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@ import (
"encoding/json"
"errors"
"fmt"
"net/http"
"net/url"

"karavi-authorization/internal/token"
"karavi-authorization/internal/web"
"karavi-authorization/pb"
"net/http"
"net/url"

"github.com/spf13/cobra"
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/karavictl/cmd/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func createStorageServiceClient(addr string, insecure bool) (pb.StorageServiceCl
var conn *grpc.ClientConn
var err error

if insecure {
if insecure { // #nosec G402
conn, err = grpc.Dial(addr,
grpc.WithTimeout(10*time.Second),
grpc.WithContextDialer(func(_ context.Context, addr string) (net.Conn, error) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/karavictl/cmd/storage_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func NewStorageCreateCmd() *cobra.Command {
}

// Gather the inputs
var input = struct {
input := struct {
Type string
Endpoint string
SystemID string
Expand Down
3 changes: 1 addition & 2 deletions cmd/karavictl/cmd/storage_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func NewStorageDeleteCmd() *cobra.Command {
}

// Gather the inputs
var input = struct {
input := struct {
Type string
SystemID string
}{
Expand Down Expand Up @@ -93,7 +93,6 @@ func NewStorageDeleteCmd() *cobra.Command {
}

func doStorageDeleteRequest(ctx context.Context, addr string, storageType string, systemID string, insecure bool, cmd *cobra.Command, adminTknBody token.AdminToken) error {

client, err := CreateHTTPClient(fmt.Sprintf("https://%s", addr), insecure)
if err != nil {
reportErrorAndExit(JSONOutput, cmd.ErrOrStderr(), err)
Expand Down
1 change: 0 additions & 1 deletion cmd/karavictl/cmd/storage_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ func NewStorageGetCmd() *cobra.Command {
}

func doStorageGetRequest(ctx context.Context, addr string, storageType string, systemID string, insecure bool, cmd *cobra.Command, adminTknBody token.AdminToken) ([]byte, error) {

client, err := CreateHTTPClient(fmt.Sprintf("https://%s", addr), insecure)
if err != nil {
reportErrorAndExit(JSONOutput, cmd.ErrOrStderr(), err)
Expand Down
3 changes: 2 additions & 1 deletion cmd/karavictl/cmd/tenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ func reportErrorAndExit(er ErrorReporter, w io.Writer, err error) {
func jsonOutput(w io.Writer, v interface{}) error {
enc := json.NewEncoder(w)
enc.SetIndent("", " ")
if err := enc.Encode(&v); err != nil {
err := enc.Encode(&v)
if err != nil {
return err
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion cmd/karavictl/cmd/tenant_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func TestTenantList(t *testing.T) {
var gotOutput bytes.Buffer

rootCmd := NewRootCmd()
//tenantListCmd := NewTenantListCmd()
// tenantListCmd := NewTenantListCmd()

rootCmd.SetErr(&gotOutput)
rootCmd.SetArgs([]string{"tenant", "list", "--admin-token", "admin.yaml", "--addr", "proxy.com"})
Expand Down
15 changes: 5 additions & 10 deletions cmd/proxy-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
"karavi-authorization/internal/web"
"karavi-authorization/pb"
"net/http"
_ "net/http/pprof"
"os"
"os/signal"
"path/filepath"
Expand Down Expand Up @@ -79,7 +78,7 @@ var (
)

func init() {
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true} // #nosec G402
}

func main() {
Expand Down Expand Up @@ -266,10 +265,6 @@ func run(log *logrus.Entry) error {
}

// Start debug service
//
// /debug/pprof - added to the default mux by importing the net/http/pprof package.
// /debug/vars - added to the default mux by importing the expvar package.
//
log.Info("main: initializing debugging support")

// Default prometheus metrics
Expand Down Expand Up @@ -620,7 +615,7 @@ func rolesHandler(log *logrus.Entry, opaHost string) http.Handler {
func volumesHandler(roleServ *roleClientService, storageServ *storageClientService, rdb *redis.Client, tm token.Manager, log *logrus.Entry) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var sysID, sysType, storPool, tenant string
var volumeMap = make(map[string]map[string]string)
volumeMap := make(map[string]map[string]string)
var volumeList []*pb.Volume
var resp *pb.RoleListResponse
keyTenantRevoked := "tenant:revoked"
Expand All @@ -639,7 +634,7 @@ func volumesHandler(roleServ *roleClientService, storageServ *storageClientServi
switch scheme {
case "Bearer":
var claims token.Claims
//check validity of token
// check validity of token
_, err := tm.ParseWithClaims(tkn, JWTSigningSecret, &claims)
if err != nil {
log.WithError(err).Printf("error parsing token: %v", err)
Expand Down Expand Up @@ -723,7 +718,7 @@ func volumesHandler(roleServ *roleClientService, storageServ *storageClientServi
for volKey := range res {
if strings.Contains(volKey, "capacity") {
splitStr := strings.Split(volKey, ":")
//example : vol:k8s-cb89d36285:capacity
// example : vol:k8s-cb89d36285:capacity
if len(splitStr) == 3 {
volumeMap[sysID][splitStr[1]] = splitStr[1]
}
Expand All @@ -732,7 +727,7 @@ func volumesHandler(roleServ *roleClientService, storageServ *storageClientServi
for volKey := range res {
if strings.Contains(volKey, "deleted") {
splitStr := strings.Split(volKey, ":")
//example : vol:k8s-cb89d36285:deleted
// example : vol:k8s-cb89d36285:deleted
if len(splitStr) == 3 {
delete(volumeMap[sysID], splitStr[1])
}
Expand Down
Loading

0 comments on commit 0767ae2

Please sign in to comment.