diff --git a/.gitlab/ci/.code-quality-ci.yml b/.gitlab/ci/.code-quality-ci.yml index acef63a432e83cde3dc89b12693333f78b1c843d..2ebadd27f2e7a7d7d6f98b07387b73ea8a936131 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 c354ccc2c5a335df172704914c7d8e976539eaf9..f5cc844e6ea5e81d641eb4399812b3dc635891a4 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 58246f531456468f0701cb1d1394891b63a4571f..6e300101d122f3d8343d97e355a34a789bc77030 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 9534e6fdd0eeb58930057e3dabf8dc4e9eedac40..523753b15d9ddcd404661f63668831e0d1d621bc 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 2e0bfed22e52e23552021744a3421268ea3b1e00..88ff3410801ee1a0dc4e0b111d3d714a644a4390 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 503cef11497ffacb25fd78bd6a38bbbcbd678bf6..b6777b7c2711e3834195aa03f1d4554bd8d1c81e 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 0beb13b4c5009dccd3fd8c2c35fb4f68401a273e..6e4a4b005413a9b8a1f6dfe59bc947afd991a034 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 21dff969692182794f922c4af510fcf9494c02af..7a376e357454fcd502851e09995d9c66099d261d 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 99e78bf61bac5edc14d4c0da1c15b18d09d70cbd..27587e387e5e41bb4658988e0f1a69e37c0d1e43 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 f4558ce6f801609fe885decce44a4fd340c3b3d5..d9a2dcda474bd0e79ccdd12cbadf323d1ce2f47a 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 803dbf043a32998f9481e19e7e5d63bec17879ad..f413ae6f55cd18e482063d70042705fa4886d9d2 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 045e7442bab127ee8a0697f7038a45d76260d8b0..72278e29447bf92d3def28015f3b6485cfeef08b 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 94e6a64508832a41954d8739291edcf93744e6c6..fdd6ab1f4c8f05f05c54ab0bf6fb9d90e731d583 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 e79ec1b9ae4824066cf829b9c617fc5376f4ba1b..dd91e1ffcdc5145f6e642378232ca1e1f8064bea 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)