Skip to content

Commit

Permalink
Fix lint (#2427)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcmmbaga authored Aug 14, 2024
1 parent 181dd93 commit 6016d2f
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 24 deletions.
3 changes: 2 additions & 1 deletion client/internal/auth/device_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package auth
import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
Expand Down Expand Up @@ -180,7 +181,7 @@ func (d *DeviceAuthorizationFlow) WaitToken(ctx context.Context, info AuthFlowIn
continue
}

return TokenInfo{}, fmt.Errorf(tokenResponse.ErrorDescription)
return TokenInfo{}, errors.New(tokenResponse.ErrorDescription)
}

tokenInfo := TokenInfo{
Expand Down
6 changes: 3 additions & 3 deletions client/internal/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -960,9 +960,9 @@ func (e *Engine) connWorker(conn *peer.Conn, peerKey string) {
for {

// randomize starting time a bit
min := 500
max := 2000
duration := time.Duration(rand.Intn(max-min)+min) * time.Millisecond
minValue := 500
maxValue := 2000
duration := time.Duration(rand.Intn(maxValue-minValue)+minValue) * time.Millisecond
select {
case <-e.ctx.Done():
return
Expand Down
3 changes: 2 additions & 1 deletion client/internal/routemanager/sysctl/sysctl_linux.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// go:build !android
//go:build !android

package sysctl

import (
Expand Down
6 changes: 3 additions & 3 deletions client/ssh/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ func (srv *DefaultServer) publicKeyHandler(ctx ssh.Context, key ssh.PublicKey) b

func prepareUserEnv(user *user.User, shell string) []string {
return []string{
fmt.Sprintf("SHELL=" + shell),
fmt.Sprintf("USER=" + user.Username),
fmt.Sprintf("HOME=" + user.HomeDir),
fmt.Sprint("SHELL=" + shell),
fmt.Sprint("USER=" + user.Username),
fmt.Sprint("HOME=" + user.HomeDir),
}
}

Expand Down
7 changes: 4 additions & 3 deletions management/client/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package client

import (
"context"
"errors"
"fmt"
"io"
"sync"
Expand Down Expand Up @@ -267,7 +268,7 @@ func (c *GrpcClient) receiveEvents(stream proto.ManagementService_SyncClient, se
// GetServerPublicKey returns server's WireGuard public key (used later for encrypting messages sent to the server)
func (c *GrpcClient) GetServerPublicKey() (*wgtypes.Key, error) {
if !c.ready() {
return nil, fmt.Errorf(errMsgNoMgmtConnection)
return nil, errors.New(errMsgNoMgmtConnection)
}

mgmCtx, cancel := context.WithTimeout(c.ctx, 5*time.Second)
Expand Down Expand Up @@ -314,7 +315,7 @@ func (c *GrpcClient) IsHealthy() bool {

func (c *GrpcClient) login(serverKey wgtypes.Key, req *proto.LoginRequest) (*proto.LoginResponse, error) {
if !c.ready() {
return nil, fmt.Errorf(errMsgNoMgmtConnection)
return nil, errors.New(errMsgNoMgmtConnection)
}

loginReq, err := encryption.EncryptMessage(serverKey, c.key, req)
Expand Down Expand Up @@ -452,7 +453,7 @@ func (c *GrpcClient) GetPKCEAuthorizationFlow(serverKey wgtypes.Key) (*proto.PKC
// It should be used if there is changes on peer posture check after initial sync.
func (c *GrpcClient) SyncMeta(sysInfo *system.Info) error {
if !c.ready() {
return fmt.Errorf(errMsgNoMgmtConnection)
return errors.New(errMsgNoMgmtConnection)
}

serverPubKey, err := c.GetServerPublicKey()
Expand Down
12 changes: 6 additions & 6 deletions management/server/grpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ func (s *GRPCServer) validateToken(ctx context.Context, jwtToken string) (string
}

if err := s.accountManager.CheckUserAccessByJWTGroups(ctx, claims); err != nil {
return "", status.Errorf(codes.PermissionDenied, err.Error())
return "", status.Error(codes.PermissionDenied, err.Error())
}

return claims.UserId, nil
Expand All @@ -268,15 +268,15 @@ func mapError(ctx context.Context, err error) error {
if e, ok := internalStatus.FromError(err); ok {
switch e.Type() {
case internalStatus.PermissionDenied:
return status.Errorf(codes.PermissionDenied, e.Message)
return status.Error(codes.PermissionDenied, e.Message)
case internalStatus.Unauthorized:
return status.Errorf(codes.PermissionDenied, e.Message)
return status.Error(codes.PermissionDenied, e.Message)
case internalStatus.Unauthenticated:
return status.Errorf(codes.PermissionDenied, e.Message)
return status.Error(codes.PermissionDenied, e.Message)
case internalStatus.PreconditionFailed:
return status.Errorf(codes.FailedPrecondition, e.Message)
return status.Error(codes.FailedPrecondition, e.Message)
case internalStatus.NotFound:
return status.Errorf(codes.NotFound, e.Message)
return status.Error(codes.NotFound, e.Message)
default:
}
}
Expand Down
2 changes: 1 addition & 1 deletion management/server/http/posture_checks_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func initPostureChecksTestData(postureChecks ...*posture.Checks) *PostureChecksH
testPostureChecks[postureChecks.ID] = postureChecks

if err := postureChecks.Validate(); err != nil {
return status.Errorf(status.InvalidArgument, err.Error())
return status.Errorf(status.InvalidArgument, err.Error()) //nolint
}

return nil
Expand Down
5 changes: 3 additions & 2 deletions management/server/idp/auth0_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package idp
import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
Expand Down Expand Up @@ -44,14 +45,14 @@ type mockJsonParser struct {

func (m *mockJsonParser) Marshal(v interface{}) ([]byte, error) {
if m.marshalErrorString != "" {
return nil, fmt.Errorf(m.marshalErrorString)
return nil, errors.New(m.marshalErrorString)
}
return m.jsonParser.Marshal(v)
}

func (m *mockJsonParser) Unmarshal(data []byte, v interface{}) error {
if m.unmarshalErrorString != "" {
return fmt.Errorf(m.unmarshalErrorString)
return errors.New(m.unmarshalErrorString)
}
return m.jsonParser.Unmarshal(data, v)
}
Expand Down
4 changes: 2 additions & 2 deletions management/server/jwtclaims/jwtValidator.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (m *JWTValidator) ValidateAndParse(ctx context.Context, token string) (*jwt
// If we get here, the required token is missing
errorMsg := "required authorization token not found"
log.WithContext(ctx).Debugf(" Error: No credentials found (CredentialsOptional=false)")
return nil, fmt.Errorf(errorMsg)
return nil, errors.New(errorMsg)
}

// Now parse the token
Expand All @@ -173,7 +173,7 @@ func (m *JWTValidator) ValidateAndParse(ctx context.Context, token string) (*jwt
// Check if the parsed token is valid...
if !parsedToken.Valid {
errorMsg := "token is invalid"
log.WithContext(ctx).Debugf(errorMsg)
log.WithContext(ctx).Debug(errorMsg)
return nil, errors.New(errorMsg)
}

Expand Down
2 changes: 1 addition & 1 deletion management/server/posture_checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (am *DefaultAccountManager) SavePostureChecks(ctx context.Context, accountI
}

if err := postureChecks.Validate(); err != nil {
return status.Errorf(status.InvalidArgument, err.Error())
return status.Errorf(status.InvalidArgument, err.Error()) //nolint
}

exists, uniqName := am.savePostureChecks(account, postureChecks)
Expand Down
2 changes: 1 addition & 1 deletion sharedsock/sock_nolinux.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ import (

// Listen is not supported on other platforms then Linux
func Listen(port int, filter BPFFilter) (net.PacketConn, error) {
return nil, fmt.Errorf(fmt.Sprintf("Not supported OS %s. SharedSocket is only supported on Linux", runtime.GOOS))
return nil, fmt.Errorf("not supported OS %s. SharedSocket is only supported on Linux", runtime.GOOS)
}

0 comments on commit 6016d2f

Please sign in to comment.