From 79a9fe57d361590109d4e31a178b7d20c880bce4 Mon Sep 17 00:00:00 2001
From: Andre Sterba <andre.sterba@stud.h-da.de>
Date: Tue, 19 Jul 2022 06:51:33 +0000
Subject: [PATCH] Fix lint errors after updating golangci-lint to 1.46

See merge request danet/gosdn!356
---
 .gitlab/ci/.code-quality-ci.yml               |  2 +-
 cli/cmd/deviceDelete.go                       |  6 +++++
 cli/cmd/prompt.go                             | 27 +++----------------
 controller/northbound/server/pnd_test.go      |  2 +-
 controller/northbound/server/user.go          | 21 ---------------
 controller/nucleus/deviceFilesystemStore.go   |  5 ++--
 controller/nucleus/pndStore.go                |  5 ++--
 controller/nucleus/principalNetworkDomain.go  |  3 ++-
 .../nucleus/principalNetworkDomain_test.go    |  5 ++--
 controller/nucleus/sbiFilesystemStore.go      |  1 -
 controller/nucleus/sbiStore.go                |  1 -
 controller/nucleus/southbound.go              |  3 ++-
 controller/nucleus/util/path/translate.go     |  1 +
 controller/rbac/jwtManager_test.go            |  2 +-
 14 files changed, 24 insertions(+), 60 deletions(-)

diff --git a/.gitlab/ci/.code-quality-ci.yml b/.gitlab/ci/.code-quality-ci.yml
index acef63a43..2ebadd27f 100644
--- a/.gitlab/ci/.code-quality-ci.yml
+++ b/.gitlab/ci/.code-quality-ci.yml
@@ -1,5 +1,5 @@
 code-quality:
-    image: ${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/golangci/golangci-lint:v1.45-alpine
+    image: ${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/golangci/golangci-lint:v1.46-alpine
     stage: analyze
     script:
         # writes golangci-lint output to gl-code-quality-report.json
diff --git a/cli/cmd/deviceDelete.go b/cli/cmd/deviceDelete.go
index c354ccc2c..f5cc844e6 100644
--- a/cli/cmd/deviceDelete.go
+++ b/cli/cmd/deviceDelete.go
@@ -53,12 +53,18 @@ The device UUID and request path must be specified as a positional arguments.`,
 			spinner.Fail(err)
 			return err
 		}
+
 		resp, err := pndAdapter.ChangeOND(
 			createContextWithAuthorization(),
 			did,
 			ppb.ApiOperation_API_OPERATION_DELETE,
 			args[1],
 		)
+		if err != nil {
+			spinner.Fail(err)
+			return err
+		}
+
 		for _, r := range resp.Responses {
 			if r.Status == ppb.Status_STATUS_OK {
 				spinner.Success("A change for path deletion for Device: ", did.String(), "has been created -> Change ID: ", r.GetId())
diff --git a/cli/cmd/prompt.go b/cli/cmd/prompt.go
index 58246f531..6e300101d 100644
--- a/cli/cmd/prompt.go
+++ b/cli/cmd/prompt.go
@@ -50,8 +50,9 @@ import (
 type PromptCompleter struct {
 	yangSchemaCompleterMap map[uuid.UUID]*completer.YangSchemaCompleter
 	currentSuggestions     []prompt.Suggest
-	document               *prompt.Document
-	history                []string
+	// nolint:unused
+	document *prompt.Document
+	history  []string
 }
 
 // NewPromptCompleter returns a new promptCompleter
@@ -334,28 +335,6 @@ func getCommittedChanges() ([]prompt.Suggest, error) {
 	return completer.SortSuggestionByText(s), nil
 }
 
-//nolint:deadcode
-// getConfirmedChanges is a helper function which requests all the confirmed
-// changes from the controller and gives feedback about the current pulling
-// status with the help of pterm the result is converted into a prompt.Suggest
-// slice.
-func getConfirmedChanges() ([]prompt.Suggest, error) {
-	spinner, _ := pterm.DefaultSpinner.Start("Fetching commited changes.")
-
-	resp, err := pndAdapter.ConfirmedChanges(createContextWithAuthorization())
-	if err != nil {
-		spinner.Fail(err)
-		return []prompt.Suggest{}, err
-	}
-
-	s := []prompt.Suggest{}
-	for _, change := range resp {
-		s = append(s, prompt.Suggest{Text: change.GetId(), Description: change.State.String()})
-	}
-	spinner.Success()
-	return completer.SortSuggestionByText(s), nil
-}
-
 var exitCmd = &cobra.Command{
 	Use:   "exit",
 	Short: "The exit command exits the interactive prompt mode.",
diff --git a/controller/northbound/server/pnd_test.go b/controller/northbound/server/pnd_test.go
index 9534e6fdd..523753b15 100644
--- a/controller/northbound/server/pnd_test.go
+++ b/controller/northbound/server/pnd_test.go
@@ -10,12 +10,12 @@ import (
 	"code.fbi.h-da.de/danet/gosdn/controller/mocks"
 	"code.fbi.h-da.de/danet/gosdn/controller/nucleus"
 	"code.fbi.h-da.de/danet/gosdn/models/generated/openconfig"
-	"github.com/golang/protobuf/proto"
 	"github.com/google/go-cmp/cmp"
 	"github.com/google/go-cmp/cmp/cmpopts"
 	"github.com/google/uuid"
 	"github.com/openconfig/gnmi/proto/gnmi"
 	"github.com/stretchr/testify/mock"
+	"google.golang.org/protobuf/proto"
 )
 
 func getTestPndServer(t *testing.T) *PndServer {
diff --git a/controller/northbound/server/user.go b/controller/northbound/server/user.go
index 2e0bfed22..88ff34108 100644
--- a/controller/northbound/server/user.go
+++ b/controller/northbound/server/user.go
@@ -188,24 +188,3 @@ func (u User) DeleteUsers(ctx context.Context, request *apb.DeleteUsersRequest)
 		Status:    apb.Status_STATUS_OK,
 	}, nil
 }
-
-func (u User) isValidUser(user rbac.User) (bool, error) {
-	storedUser, err := u.userService.Get(store.Query{Name: user.Name()})
-	if err != nil {
-		return false, err
-	} else if storedUser == nil {
-		return false, status.Errorf(codes.Aborted, "no user object")
-	}
-
-	if storedUser.Name() == user.Name() {
-		salt := storedUser.GetSalt()
-
-		hashedPasswordFromLogin := base64.RawStdEncoding.EncodeToString(argon2.IDKey([]byte(user.GetPassword()), []byte(salt), 1, 64*1024, 4, 32))
-
-		if storedUser.GetPassword() == hashedPasswordFromLogin {
-			return true, nil
-		}
-	}
-
-	return false, status.Errorf(codes.Unauthenticated, "incorrect user name or password")
-}
diff --git a/controller/nucleus/deviceFilesystemStore.go b/controller/nucleus/deviceFilesystemStore.go
index 503cef114..b6777b7c2 100644
--- a/controller/nucleus/deviceFilesystemStore.go
+++ b/controller/nucleus/deviceFilesystemStore.go
@@ -6,7 +6,6 @@ import (
 	"sync"
 
 	"code.fbi.h-da.de/danet/gosdn/controller/interfaces/device"
-	"code.fbi.h-da.de/danet/gosdn/controller/interfaces/southbound"
 	"code.fbi.h-da.de/danet/gosdn/controller/nucleus/errors"
 	"code.fbi.h-da.de/danet/gosdn/controller/store"
 	"github.com/google/uuid"
@@ -14,7 +13,6 @@ import (
 
 // FilesystemDeviceStore is the filesystem implementation of the device store
 type FilesystemDeviceStore struct {
-	sbiStore         southbound.Store
 	pndUUID          uuid.UUID
 	fileMutex        sync.Mutex
 	pathToDeviceFile string
@@ -125,6 +123,9 @@ func (s *FilesystemDeviceStore) Update(deviceToUpdate device.Device) error {
 	defer s.fileMutex.Unlock()
 
 	loadedDeviceToUpdate, err := store.TransformObjectToLoadedObject[device.Device, device.LoadedDevice](deviceToUpdate)
+	if err != nil {
+		return err
+	}
 
 	devices, err := s.readAllDevicesFromFile()
 	if err != nil {
diff --git a/controller/nucleus/pndStore.go b/controller/nucleus/pndStore.go
index 0beb13b4c..6e4a4b005 100644
--- a/controller/nucleus/pndStore.go
+++ b/controller/nucleus/pndStore.go
@@ -18,8 +18,6 @@ type LoadedPnd struct {
 
 // PndStore is used to store PrincipalNetworkDomains
 type PndStore struct {
-	pndStoreName    string
-	pendingChannels map[uuid.UUID]chan device.Details
 }
 
 // NewPndStore returns a PndStore
@@ -31,7 +29,8 @@ func NewPndStore() networkdomain.PndStore {
 	case store.Database:
 		return &DatabasePndStore{
 			pendingChannels: make(map[uuid.UUID]chan device.Details),
-			pndStoreName:    "pnd-store.json"}
+			pndStoreName:    "pnd-store.json",
+		}
 
 	default:
 		store := NewFilesystemPndStore()
diff --git a/controller/nucleus/principalNetworkDomain.go b/controller/nucleus/principalNetworkDomain.go
index 21dff9696..7a376e357 100644
--- a/controller/nucleus/principalNetworkDomain.go
+++ b/controller/nucleus/principalNetworkDomain.go
@@ -61,7 +61,6 @@ func NewPND(
 
 	sbiStore := NewSbiStore(id)
 	deviceStore := NewDeviceStore(id)
-	changeStore := store.NewChangeStore()
 
 	sbiService := NewSbiService(sbiStore, eventService)
 	deviceService := NewDeviceService(
@@ -688,6 +687,7 @@ func (pnd *pndImplementation) requestPlugin(name string, opt *tpb.TransportOptio
 	files := []string{util.GoStructName, util.ManifestFileName, util.GoStructAdditionsName}
 	g := new(errgroup.Group)
 	// we only request one plugin
+	//nolint
 	for _, dep := range resp.GetDeployments() {
 		id := uuid.New()
 		for _, f := range files {
@@ -726,6 +726,7 @@ func (pnd *pndImplementation) requestPlugin(name string, opt *tpb.TransportOptio
 
 		return sbi, nil
 	}
+
 	return nil, fmt.Errorf("requestPlugin: received deployment slice was empty")
 }
 
diff --git a/controller/nucleus/principalNetworkDomain_test.go b/controller/nucleus/principalNetworkDomain_test.go
index 99e78bf61..27587e387 100644
--- a/controller/nucleus/principalNetworkDomain_test.go
+++ b/controller/nucleus/principalNetworkDomain_test.go
@@ -88,9 +88,8 @@ func Test_destroy(t *testing.T) {
 
 func Test_pndImplementation_AddDevice(t *testing.T) {
 	type args struct {
-		device interface{}
-		name   string
-		opts   *tpb.TransportOption
+		name string
+		opts *tpb.TransportOption
 	}
 	tests := []struct {
 		name    string
diff --git a/controller/nucleus/sbiFilesystemStore.go b/controller/nucleus/sbiFilesystemStore.go
index f4558ce6f..d9a2dcda4 100644
--- a/controller/nucleus/sbiFilesystemStore.go
+++ b/controller/nucleus/sbiFilesystemStore.go
@@ -14,7 +14,6 @@ import (
 
 // FilesystemSbiStore is used to store SouthboundInterfaces
 type FilesystemSbiStore struct {
-	sbiStoreName  string
 	pndUUID       uuid.UUID
 	fileMutex     sync.Mutex
 	pathToSbiFile string
diff --git a/controller/nucleus/sbiStore.go b/controller/nucleus/sbiStore.go
index 803dbf043..f413ae6f5 100644
--- a/controller/nucleus/sbiStore.go
+++ b/controller/nucleus/sbiStore.go
@@ -11,7 +11,6 @@ import (
 
 // SbiStore is used to store SouthboundInterfaces
 type SbiStore struct {
-	sbiStoreName string
 }
 
 // NewSbiStore returns a sbiStore
diff --git a/controller/nucleus/southbound.go b/controller/nucleus/southbound.go
index 045e7442b..72278e294 100644
--- a/controller/nucleus/southbound.go
+++ b/controller/nucleus/southbound.go
@@ -78,7 +78,8 @@ func NewSouthboundPlugin(id uuid.UUID, path string, build bool) (*SouthboundPlug
 type OpenConfig struct {
 	schema *ytypes.Schema
 	id     uuid.UUID
-	path   string
+	// nolint:unused
+	path string
 }
 
 // SbiIdentifier returns the string representation of
diff --git a/controller/nucleus/util/path/translate.go b/controller/nucleus/util/path/translate.go
index 94e6a6450..fdd6ab1f4 100644
--- a/controller/nucleus/util/path/translate.go
+++ b/controller/nucleus/util/path/translate.go
@@ -10,6 +10,7 @@ import (
 func ToStrings(path *gpb.Path) []string {
 	elems := make([]string, len(path.Elem))
 	for i, e := range path.Elem {
+		//nolint
 		elems[i] = strings.Title(e.Name)
 	}
 	return elems
diff --git a/controller/rbac/jwtManager_test.go b/controller/rbac/jwtManager_test.go
index e79ec1b9a..dd91e1ffc 100644
--- a/controller/rbac/jwtManager_test.go
+++ b/controller/rbac/jwtManager_test.go
@@ -95,7 +95,7 @@ func TestJWTManager_VerifyToken(t *testing.T) {
 				tokenDuration: tt.fields.tokenDuration,
 			}
 
-			token, err := man.GenerateToken(User{UserName: tt.userName})
+			token, _ := man.GenerateToken(User{UserName: tt.userName})
 			got, err := man.VerifyToken(token)
 			if (err != nil) != tt.wantErr {
 				t.Errorf("JWTManager.VerifyToken() error = %v, wantErr %v", err, tt.wantErr)
-- 
GitLab