From a305223d652c84e0e7ab1f16f0d3014a3a99a329 Mon Sep 17 00:00:00 2001 From: Fabian Seidl <fabian.b.seidl@stud.h-da.de> Date: Tue, 14 Jun 2022 10:10:48 +0000 Subject: [PATCH] Resolve "There are two defined errors (ErrNotFound and ErrCouldNotFind) which represent the same issue" See merge request danet/gosdn!332 --- controller/nucleus/databaseDeviceStore.go | 12 ++++++------ controller/nucleus/databasePndStore.go | 4 ++-- controller/nucleus/databaseSbiStore.go | 2 +- controller/nucleus/deviceFilesystemStore.go | 6 +++--- controller/nucleus/deviceStore.go | 4 ---- controller/nucleus/errors/errors.go | 16 +++------------- controller/nucleus/memoryDeviceStore.go | 6 +++--- controller/nucleus/memoryPndStore.go | 4 ++-- controller/nucleus/memorySbiStore.go | 2 +- controller/nucleus/pndFilesystemStore.go | 6 +++--- controller/nucleus/sbiFilesystemStore.go | 4 ++-- controller/rbac/databaseRoleStore.go | 14 +++++++------- controller/rbac/databaseUserStore.go | 14 +++++++------- controller/rbac/memoryRoleStore.go | 6 +++--- controller/rbac/memoryUserStore.go | 6 +++--- controller/rbac/roleFileSystemStore.go | 6 +++--- controller/rbac/roleStore.go | 9 --------- controller/rbac/userFileSystemStore.go | 6 +++--- controller/rbac/userStore.go | 9 --------- controller/store/oldGenericStore.go | 4 ++-- csbi/deployment.go | 4 ++-- 21 files changed, 56 insertions(+), 88 deletions(-) diff --git a/controller/nucleus/databaseDeviceStore.go b/controller/nucleus/databaseDeviceStore.go index 5ebf57278..530bbec1e 100644 --- a/controller/nucleus/databaseDeviceStore.go +++ b/controller/nucleus/databaseDeviceStore.go @@ -34,7 +34,7 @@ func (s *DatabaseDeviceStore) Get(query store.Query) (device.LoadedDevice, error if query.ID.String() != "" { loadedDevice, err := s.getByID(query.ID) if err != nil { - return loadedDevice, errors.ErrCouldNotFind{StoreName: deviceStoreName} + return loadedDevice, err } return loadedDevice, nil @@ -42,7 +42,7 @@ func (s *DatabaseDeviceStore) Get(query store.Query) (device.LoadedDevice, error loadedDevice, err := s.getByName(query.Name) if err != nil { - return loadedDevice, errors.ErrCouldNotFind{StoreName: deviceStoreName} + return loadedDevice, err } return loadedDevice, nil @@ -59,13 +59,13 @@ func (s *DatabaseDeviceStore) getByID(idOfDevice uuid.UUID) (device.LoadedDevice collection := db.Collection(s.storeName) result := collection.FindOne(ctx, bson.D{primitive.E{Key: "_id", Value: idOfDevice.String()}}) if result == nil { - return loadedDevice, errors.ErrCouldNotFind{StoreName: deviceStoreName} + return loadedDevice, errors.ErrCouldNotFind{ID: idOfDevice} } err := result.Decode(&loadedDevice) if err != nil { log.Printf("Failed marshalling %v", err) - return loadedDevice, errors.ErrCouldNotFind{StoreName: deviceStoreName} + return loadedDevice, errors.ErrCouldNotMarshall{StoreName: s.storeName} } return loadedDevice, nil @@ -82,13 +82,13 @@ func (s *DatabaseDeviceStore) getByName(nameOfDevice string) (device.LoadedDevic collection := db.Collection(s.storeName) result := collection.FindOne(ctx, bson.D{primitive.E{Key: "name", Value: nameOfDevice}}) if result == nil { - return loadedDevice, errors.ErrCouldNotFind{StoreName: deviceStoreName} + return loadedDevice, errors.ErrCouldNotFind{Name: nameOfDevice} } err := result.Decode(&loadedDevice) if err != nil { log.Printf("Failed marshalling %v", err) - return loadedDevice, errors.ErrCouldNotFind{StoreName: deviceStoreName} + return loadedDevice, errors.ErrCouldNotMarshall{StoreName: s.storeName} } return loadedDevice, nil diff --git a/controller/nucleus/databasePndStore.go b/controller/nucleus/databasePndStore.go index a26dfadf1..f39ef1138 100644 --- a/controller/nucleus/databasePndStore.go +++ b/controller/nucleus/databasePndStore.go @@ -37,7 +37,7 @@ func (s *DatabasePndStore) Get(query store.Query) (networkdomain.NetworkDomain, collection := db.Collection(s.pndStoreName) result := collection.FindOne(ctx, bson.D{primitive.E{Key: "_id", Value: query.ID.String()}}) if result == nil { - return nil, nil + return nil, errors.ErrCouldNotFind{ID: query.ID} } err := result.Decode(&loadedPND) @@ -153,7 +153,7 @@ func (s *DatabasePndStore) Delete(pnd networkdomain.NetworkDomain) error { func (s *DatabasePndStore) PendingChannels(id uuid.UUID, parseErrors ...error) (chan device.Details, error) { ch, ok := s.pendingChannels[id] if !ok { - return nil, &errors.ErrNotFound{ID: id} + return nil, &errors.ErrCouldNotFind{ID: id} } return ch, nil } diff --git a/controller/nucleus/databaseSbiStore.go b/controller/nucleus/databaseSbiStore.go index b0404f573..43a1bca99 100644 --- a/controller/nucleus/databaseSbiStore.go +++ b/controller/nucleus/databaseSbiStore.go @@ -68,7 +68,7 @@ func (s *DatabaseSbiStore) Get(query store.Query) (southbound.LoadedSbi, error) collection := db.Collection(s.sbiStoreName) result := collection.FindOne(ctx, bson.D{primitive.E{Key: "_id", Value: query.ID.String()}}) if result == nil { - return loadedSbi, nil + return loadedSbi, errors.ErrCouldNotFind{ID: query.ID} } err := result.Decode(&loadedSbi) diff --git a/controller/nucleus/deviceFilesystemStore.go b/controller/nucleus/deviceFilesystemStore.go index 0d9db1f89..76f50dd2e 100644 --- a/controller/nucleus/deviceFilesystemStore.go +++ b/controller/nucleus/deviceFilesystemStore.go @@ -80,7 +80,7 @@ func (s *FilesystemDeviceStore) Get(query store.Query) (device.LoadedDevice, err } } - return device, &errors.ErrNotFound{ID: query.ID, Name: query.Name} + return device, &errors.ErrCouldNotFind{ID: query.ID, Name: query.Name} } // GetAll returns all stored devices. @@ -142,7 +142,7 @@ func (s *FilesystemDeviceStore) Update(deviceToUpdate device.Device) error { } } - return &errors.ErrNotFound{ID: deviceToUpdate.ID().String(), Name: deviceToUpdate.Name()} + return &errors.ErrCouldNotFind{ID: deviceToUpdate.ID().String(), Name: deviceToUpdate.Name()} } // Delete deletes a device from the device store. @@ -170,5 +170,5 @@ func (s *FilesystemDeviceStore) Delete(deviceToDelete device.Device) error { } } - return &errors.ErrNotFound{ID: deviceToDelete.ID, Name: deviceToDelete.Name()} + return &errors.ErrCouldNotFind{ID: deviceToDelete.ID, Name: deviceToDelete.Name()} } diff --git a/controller/nucleus/deviceStore.go b/controller/nucleus/deviceStore.go index aa886eb11..681209da5 100644 --- a/controller/nucleus/deviceStore.go +++ b/controller/nucleus/deviceStore.go @@ -10,10 +10,6 @@ import ( log "github.com/sirupsen/logrus" ) -const ( - deviceStoreName = "device" -) - // NewDeviceStore returns a DeviceStore func NewDeviceStore(pndUUID uuid.UUID) device.Store { storeMode := store.GetStoreMode() diff --git a/controller/nucleus/errors/errors.go b/controller/nucleus/errors/errors.go index 54be6a617..eac05eb44 100644 --- a/controller/nucleus/errors/errors.go +++ b/controller/nucleus/errors/errors.go @@ -23,17 +23,6 @@ func (e *ErrNil) Error() string { return fmt.Sprintf("struct cannot be nil") } -// ErrNotFound implements the Error interface and is called if a specific ID -// of a storable item could not be found. -type ErrNotFound struct { - ID interface{} - Name interface{} -} - -func (e *ErrNotFound) Error() string { - return fmt.Sprintf("ID: %v or Name: %v not found", e.ID, e.Name) -} - // ErrAlreadyExists implements the Error interface and is called if a specific ID // of a storable item already exists. type ErrAlreadyExists struct { @@ -193,11 +182,12 @@ func (e ErrCouldNotUpdate) Error() string { // ErrCouldNotFind implements the Error interface and is called if a // stored item can not be found. type ErrCouldNotFind struct { - StoreName string + ID any + Name string } func (e ErrCouldNotFind) Error() string { - return fmt.Sprintf("could not find %s", e.StoreName) + return fmt.Sprintf("ID: %v or Name: %v not found", e.ID, e.Name) } // ErrCouldNotCreate implements the Error interface and is called if a diff --git a/controller/nucleus/memoryDeviceStore.go b/controller/nucleus/memoryDeviceStore.go index a7c775a88..2bc429058 100644 --- a/controller/nucleus/memoryDeviceStore.go +++ b/controller/nucleus/memoryDeviceStore.go @@ -50,7 +50,7 @@ func (t *MemoryDeviceStore) Add(item device.Device) error { func (t *MemoryDeviceStore) Update(item device.Device) error { _, ok := t.Store[item.ID().String()] if !ok { - return errors.ErrCouldNotFind{StoreName: deviceStoreName} + return errors.ErrCouldNotFind{ID: item.ID(), Name: item.Name()} } var device device.LoadedDevice @@ -85,12 +85,12 @@ func (t *MemoryDeviceStore) Get(query store.Query) (device.LoadedDevice, error) // Second search for name id, ok := t.nameLookupTable[query.Name] if !ok { - return item, errors.ErrCouldNotFind{StoreName: deviceStoreName} + return item, errors.ErrCouldNotFind{ID: query.ID, Name: query.Name} } item, ok := t.Store[id] if !ok { - return item, errors.ErrCouldNotFind{StoreName: deviceStoreName} + return item, errors.ErrCouldNotFind{ID: query.ID, Name: query.Name} } return item, nil diff --git a/controller/nucleus/memoryPndStore.go b/controller/nucleus/memoryPndStore.go index 627470364..c86337899 100644 --- a/controller/nucleus/memoryPndStore.go +++ b/controller/nucleus/memoryPndStore.go @@ -45,7 +45,7 @@ func (t *MemoryPndStore) Delete(item networkdomain.NetworkDomain) error { func (t *MemoryPndStore) Get(query store.Query) (networkdomain.NetworkDomain, error) { item, ok := t.Store[query.ID] if !ok { - return nil, &nerrors.ErrNotFound{ID: query.ID, Name: query.Name} + return nil, &nerrors.ErrCouldNotFind{ID: query.ID, Name: query.Name} } return item, nil @@ -67,7 +67,7 @@ func (t *MemoryPndStore) GetAll() ([]networkdomain.NetworkDomain, error) { func (t *MemoryPndStore) PendingChannels(id uuid.UUID, parseErrors ...error) (chan device.Details, error) { ch, ok := t.pendingChannels[id] if !ok { - return nil, &nerrors.ErrNotFound{ID: id} + return nil, &nerrors.ErrCouldNotFind{ID: id} } return ch, nil } diff --git a/controller/nucleus/memorySbiStore.go b/controller/nucleus/memorySbiStore.go index d9f124502..d1f69e12a 100644 --- a/controller/nucleus/memorySbiStore.go +++ b/controller/nucleus/memorySbiStore.go @@ -90,7 +90,7 @@ func (t *MemorySbiStore) Get(query store.Query) (southbound.LoadedSbi, error) { item, ok := t.Store[id] if !ok { - return item, errors.ErrCouldNotFind{StoreName: sbiStoreName} + return item, errors.ErrCouldNotFind{ID: query.ID, Name: query.Name} } return item, nil diff --git a/controller/nucleus/pndFilesystemStore.go b/controller/nucleus/pndFilesystemStore.go index beba95994..81d243b7b 100644 --- a/controller/nucleus/pndFilesystemStore.go +++ b/controller/nucleus/pndFilesystemStore.go @@ -131,7 +131,7 @@ func (t *FilesystemPndStore) Delete(item networkdomain.NetworkDomain) error { } } - return &errors.ErrNotFound{ID: item.ID, Name: item.GetName()} + return &errors.ErrCouldNotFind{ID: item.ID, Name: item.GetName()} } // Get provides a the query interface to find a stored pnd. @@ -150,7 +150,7 @@ func (t *FilesystemPndStore) Get(query store.Query) (networkdomain.NetworkDomain } } - return nil, &errors.ErrNotFound{ID: query.ID, Name: query.Name} + return nil, &errors.ErrCouldNotFind{ID: query.ID, Name: query.Name} } // GetAll returns all pnds currently on the store. @@ -168,7 +168,7 @@ func (t *FilesystemPndStore) GetAll() ([]networkdomain.NetworkDomain, error) { func (t *FilesystemPndStore) PendingChannels(id uuid.UUID, parseErrors ...error) (chan device.Details, error) { ch, ok := t.pendingChannels[id] if !ok { - return nil, &errors.ErrNotFound{ID: id} + return nil, &errors.ErrCouldNotFind{ID: id} } return ch, nil } diff --git a/controller/nucleus/sbiFilesystemStore.go b/controller/nucleus/sbiFilesystemStore.go index 64fdeb481..9859549f6 100644 --- a/controller/nucleus/sbiFilesystemStore.go +++ b/controller/nucleus/sbiFilesystemStore.go @@ -110,7 +110,7 @@ func (s *FilesystemSbiStore) Delete(sbiToDelete southbound.SouthboundInterface) return nil } } - return &errors.ErrNotFound{ID: sbiToDelete.ID, Name: sbiToDelete.Name()} + return &errors.ErrCouldNotFind{ID: sbiToDelete.ID, Name: sbiToDelete.Name()} } // Get takes a SouthboundInterface's UUID or name and returns the SouthboundInterface. If the requested @@ -132,7 +132,7 @@ func (s *FilesystemSbiStore) Get(query store.Query) (southbound.LoadedSbi, error } } - return sbi, &errors.ErrNotFound{ID: query.ID, Name: query.Name} + return sbi, &errors.ErrCouldNotFind{ID: query.ID, Name: query.Name} } // GetAll returns all SBIs diff --git a/controller/rbac/databaseRoleStore.go b/controller/rbac/databaseRoleStore.go index 4ee86a6c0..b97da6d9a 100644 --- a/controller/rbac/databaseRoleStore.go +++ b/controller/rbac/databaseRoleStore.go @@ -48,7 +48,7 @@ func (s *DatabaseRoleStore) Delete(roleToDelete rbac.Role) error { Collection(s.roleStoreName). DeleteOne(ctx, bson.D{primitive.E{Key: "_id", Value: roleToDelete.ID().String()}}) if err != nil { - return errors.ErrCouldNotFind{StoreName: s.roleStoreName} + return errors.ErrCouldNotFind{ID: roleToDelete.ID(), Name: roleToDelete.Name()} } return nil @@ -62,7 +62,7 @@ func (s *DatabaseRoleStore) Get(query store.Query) (rbac.LoadedRole, error) { if query.ID != uuid.Nil { loadedRole, err := s.getByID(query.ID) if err != nil { - return loadedRole, errors.ErrCouldNotFind{StoreName: s.roleStoreName} + return loadedRole, err } return loadedRole, nil @@ -70,7 +70,7 @@ func (s *DatabaseRoleStore) Get(query store.Query) (rbac.LoadedRole, error) { loadedRole, err := s.getByName(query.Name) if err != nil { - return loadedRole, errors.ErrCouldNotFind{StoreName: s.roleStoreName} + return loadedRole, err } return loadedRole, nil @@ -87,13 +87,13 @@ func (s *DatabaseRoleStore) getByID(idOfRole uuid.UUID) (rbac.LoadedRole, error) collection := db.Collection(s.roleStoreName) result := collection.FindOne(ctx, bson.D{primitive.E{Key: "_id", Value: idOfRole.String()}}) if result == nil { - return loadedRole, errors.ErrCouldNotFind{StoreName: s.roleStoreName} + return loadedRole, errors.ErrCouldNotFind{ID: idOfRole} } err := result.Decode(&loadedRole) if err != nil { log.Printf("Failed marshalling %v", err) - return loadedRole, errors.ErrCouldNotFind{StoreName: s.roleStoreName} + return loadedRole, errors.ErrCouldNotMarshall{StoreName: s.roleStoreName} } return loadedRole, nil @@ -110,13 +110,13 @@ func (s *DatabaseRoleStore) getByName(nameOfRole string) (rbac.LoadedRole, error collection := db.Collection(s.roleStoreName) result := collection.FindOne(ctx, bson.D{primitive.E{Key: "rolename", Value: nameOfRole}}) if result == nil { - return loadedRole, errors.ErrCouldNotFind{StoreName: s.roleStoreName} + return loadedRole, errors.ErrCouldNotFind{Name: nameOfRole} } err := result.Decode(&loadedRole) if err != nil { log.Printf("Failed marshalling %v", err) - return loadedRole, errors.ErrCouldNotFind{StoreName: s.roleStoreName} + return loadedRole, errors.ErrCouldNotMarshall{StoreName: s.roleStoreName} } return loadedRole, nil diff --git a/controller/rbac/databaseUserStore.go b/controller/rbac/databaseUserStore.go index f6b0064c3..a300c96ed 100644 --- a/controller/rbac/databaseUserStore.go +++ b/controller/rbac/databaseUserStore.go @@ -48,7 +48,7 @@ func (s *DatabaseUserStore) Delete(userToDelete rbac.User) error { Collection(s.userStoreName). DeleteOne(ctx, bson.D{primitive.E{Key: "_id", Value: userToDelete.ID().String()}}) if err != nil { - return errors.ErrCouldNotFind{StoreName: s.userStoreName} + return errors.ErrCouldNotFind{ID: userToDelete.ID(), Name: userToDelete.Name()} } return nil @@ -62,7 +62,7 @@ func (s *DatabaseUserStore) Get(query store.Query) (rbac.LoadedUser, error) { if query.ID != uuid.Nil { loadedUser, err := s.getByID(query.ID) if err != nil { - return loadedUser, errors.ErrCouldNotFind{StoreName: s.userStoreName} + return loadedUser, err } return loadedUser, nil @@ -70,7 +70,7 @@ func (s *DatabaseUserStore) Get(query store.Query) (rbac.LoadedUser, error) { loadedUser, err := s.getByName(query.Name) if err != nil { - return loadedUser, errors.ErrCouldNotFind{StoreName: s.userStoreName} + return loadedUser, err } return loadedUser, nil @@ -87,13 +87,13 @@ func (s *DatabaseUserStore) getByID(idOfUser uuid.UUID) (rbac.LoadedUser, error) collection := db.Collection(s.userStoreName) result := collection.FindOne(ctx, bson.D{primitive.E{Key: "_id", Value: idOfUser.String()}}) if result == nil { - return loadedUser, errors.ErrCouldNotFind{StoreName: s.userStoreName} + return loadedUser, errors.ErrCouldNotFind{ID: idOfUser} } err := result.Decode(&loadedUser) if err != nil { log.Printf("Failed marshalling %v", err) - return loadedUser, errors.ErrCouldNotFind{StoreName: s.userStoreName} + return loadedUser, errors.ErrCouldNotMarshall{StoreName: s.userStoreName} } return loadedUser, nil @@ -110,13 +110,13 @@ func (s *DatabaseUserStore) getByName(nameOfUser string) (rbac.LoadedUser, error collection := db.Collection(s.userStoreName) result := collection.FindOne(ctx, bson.D{primitive.E{Key: "username", Value: nameOfUser}}) if result == nil { - return loadedUser, errors.ErrCouldNotFind{StoreName: s.userStoreName} + return loadedUser, errors.ErrCouldNotFind{Name: nameOfUser} } err := result.Decode(&loadedUser) if err != nil { log.Printf("Failed marshalling %v", err) - return loadedUser, errors.ErrCouldNotFind{StoreName: s.userStoreName} + return loadedUser, errors.ErrCouldNotMarshall{StoreName: s.userStoreName} } return loadedUser, nil diff --git a/controller/rbac/memoryRoleStore.go b/controller/rbac/memoryRoleStore.go index da0e023eb..103f1c1a2 100644 --- a/controller/rbac/memoryRoleStore.go +++ b/controller/rbac/memoryRoleStore.go @@ -56,7 +56,7 @@ func (s *MemoryRoleStore) Delete(item rbac.Role) error { func (s *MemoryRoleStore) Update(item rbac.Role) error { _, ok := s.Store[item.ID().String()] if !ok { - return errors.ErrCouldNotFind{StoreName: roleStoreName} + return errors.ErrCouldNotFind{ID: item.ID(), Name: item.Name()} } var role rbac.LoadedRole @@ -84,12 +84,12 @@ func (s *MemoryRoleStore) Get(query store.Query) (rbac.LoadedRole, error) { // Second search for name id, ok := s.nameLookupTable[query.Name] if !ok { - return item, errors.ErrCouldNotFind{StoreName: roleStoreName} + return item, errors.ErrCouldNotFind{ID: query.ID, Name: query.Name} } item, ok := s.Store[id] if !ok { - return item, errors.ErrCouldNotFind{StoreName: roleStoreName} + return item, errors.ErrCouldNotFind{ID: query.ID, Name: query.Name} } return item, nil diff --git a/controller/rbac/memoryUserStore.go b/controller/rbac/memoryUserStore.go index c97439278..0387d2994 100644 --- a/controller/rbac/memoryUserStore.go +++ b/controller/rbac/memoryUserStore.go @@ -56,7 +56,7 @@ func (s *MemoryUserStore) Delete(item rbac.User) error { func (s *MemoryUserStore) Update(item rbac.User) error { _, ok := s.Store[item.ID().String()] if !ok { - return errors.ErrCouldNotFind{StoreName: userStoreName} + return errors.ErrCouldNotFind{ID: item.ID(), Name: item.Name()} } var user rbac.LoadedUser @@ -84,12 +84,12 @@ func (s *MemoryUserStore) Get(query store.Query) (rbac.LoadedUser, error) { // Second search for name id, ok := s.nameLookupTable[query.Name] if !ok { - return item, errors.ErrCouldNotFind{StoreName: userStoreName} + return item, errors.ErrCouldNotFind{ID: query.ID, Name: query.Name} } item, ok := s.Store[id] if !ok { - return item, errors.ErrCouldNotFind{StoreName: userStoreName} + return item, errors.ErrCouldNotFind{ID: query.ID, Name: query.Name} } return item, nil diff --git a/controller/rbac/roleFileSystemStore.go b/controller/rbac/roleFileSystemStore.go index 02a2baaee..3c4fd0c26 100644 --- a/controller/rbac/roleFileSystemStore.go +++ b/controller/rbac/roleFileSystemStore.go @@ -105,7 +105,7 @@ func (s *FileSystemRoleStore) Delete(RoleToDelete rbac.Role) error { } } - return &errors.ErrNotFound{ID: RoleToDelete.ID} + return &errors.ErrCouldNotFind{ID: RoleToDelete.ID(), Name: RoleToDelete.Name()} } //Get takes a Roles ID and return the Role if found @@ -125,7 +125,7 @@ func (s *FileSystemRoleStore) Get(query store.Query) (rbac.LoadedRole, error) { } } - return role, &errors.ErrNotFound{ID: query.ID, Name: query.Name} + return role, &errors.ErrCouldNotFind{ID: query.ID, Name: query.Name} } // GetAll returns all the Roles @@ -162,5 +162,5 @@ func (s *FileSystemRoleStore) Update(roleToUpdate rbac.Role) error { } } - return &errors.ErrNotFound{ID: roleToUpdate.ID().String()} + return &errors.ErrCouldNotFind{ID: roleToUpdate.ID(), Name: roleToUpdate.Name()} } diff --git a/controller/rbac/roleStore.go b/controller/rbac/roleStore.go index 35b9a5127..908f81033 100644 --- a/controller/rbac/roleStore.go +++ b/controller/rbac/roleStore.go @@ -5,15 +5,6 @@ import ( "code.fbi.h-da.de/danet/gosdn/controller/store" ) -const ( - roleStoreName = "role" -) - -// RoleStore is used to store Roles -type RoleStore struct { - roleStoreName string -} - // NewRoleStore returns a roleStore func NewRoleStore() rbac.RoleStore { storeMode := store.GetStoreMode() diff --git a/controller/rbac/userFileSystemStore.go b/controller/rbac/userFileSystemStore.go index 11f2184c7..f0547a6b2 100644 --- a/controller/rbac/userFileSystemStore.go +++ b/controller/rbac/userFileSystemStore.go @@ -105,7 +105,7 @@ func (s *FileSystemUserStore) Delete(userToDelete rbac.User) error { } } - return &errors.ErrNotFound{ID: userToDelete.ID} + return &errors.ErrCouldNotFind{ID: userToDelete.ID(), Name: userToDelete.Name()} } //Get takes a Users ID and return the User if found @@ -125,7 +125,7 @@ func (s *FileSystemUserStore) Get(query store.Query) (rbac.LoadedUser, error) { return user, nil } } - return user, &errors.ErrNotFound{ID: query.ID, Name: query.Name} + return user, &errors.ErrCouldNotFind{ID: query.ID, Name: query.Name} } // GetAll returns all the Users @@ -162,5 +162,5 @@ func (s *FileSystemUserStore) Update(userToUpdate rbac.User) error { } } - return &errors.ErrNotFound{ID: userToUpdate.ID().String()} + return &errors.ErrCouldNotFind{ID: userToUpdate.ID(), Name: userToUpdate.Name()} } diff --git a/controller/rbac/userStore.go b/controller/rbac/userStore.go index e157d8bf0..f9f646b3b 100644 --- a/controller/rbac/userStore.go +++ b/controller/rbac/userStore.go @@ -5,15 +5,6 @@ import ( "code.fbi.h-da.de/danet/gosdn/controller/store" ) -const ( - userStoreName = "user" -) - -// UserStore is used to store Users -type UserStore struct { - userStoreName string -} - // NewUserStore returns a userStore func NewUserStore() rbac.UserStore { storeMode := store.GetStoreMode() diff --git a/controller/store/oldGenericStore.go b/controller/store/oldGenericStore.go index d33e81be6..19ab0cc7b 100644 --- a/controller/store/oldGenericStore.go +++ b/controller/store/oldGenericStore.go @@ -50,7 +50,7 @@ func (s *genericStore) Add(item store.Storable) error { // use GetDevice, GetPND, GetSBI, or GetChange respectively. func (s *genericStore) Get(id uuid.UUID) (store.Storable, error) { if !s.Exists(id) { - return nil, &errors.ErrNotFound{ID: id} + return nil, &errors.ErrCouldNotFind{ID: id} } log.WithFields(log.Fields{ "uuid": id, @@ -64,7 +64,7 @@ func (s *genericStore) Get(id uuid.UUID) (store.Storable, error) { // exist in the Store an error is returned. func (s *genericStore) Delete(id uuid.UUID) error { if !s.Exists(id) { - return &errors.ErrNotFound{ID: id} + return &errors.ErrCouldNotFind{ID: id} } s.storeLock.Lock() delete(s.Store, id) diff --git a/csbi/deployment.go b/csbi/deployment.go index a07aae382..72d25a4c5 100644 --- a/csbi/deployment.go +++ b/csbi/deployment.go @@ -64,7 +64,7 @@ func (store DeploymentStore) Get(id uuid.UUID) (Deployment, error) { log.Tracef("requested %v from store", id) deployment := <-store.in if deployment.ID != id { - return Deployment{}, &errors.ErrNotFound{ID: id} + return Deployment{}, &errors.ErrCouldNotFind{ID: id} } log.Tracef("received %v from store", id) log.Tracef("leaving Get func for %v", id) @@ -80,7 +80,7 @@ func (store DeploymentStore) Delete(id uuid.UUID) error { log.Tracef("requested %v from store", id) deployment := <-store.in if deployment.ID != id { - return &errors.ErrNotFound{ID: id} + return &errors.ErrCouldNotFind{ID: id} } log.Tracef("received %v from store", id) deployment.State = pb.State_STATE_DECOMMISSIONED -- GitLab