diff --git a/management/server/file_store.go b/management/server/file_store.go index d75dbb07b..a6e29ec44 100644 --- a/management/server/file_store.go +++ b/management/server/file_store.go @@ -1,7 +1,6 @@ package server import ( - "errors" "os" "path/filepath" "strings" @@ -580,7 +579,15 @@ func (s *FileStore) GetAccountByPeerPubKey(peerKey string) (*Account, error) { } func (s *FileStore) GetAccountIDByPeerPubKey(peerKey string) (string, error) { - return "", errors.New("not implemented") + s.mux.Lock() + defer s.mux.Unlock() + + accountID, ok := s.PeerKeyID2AccountID[peerKey] + if !ok { + return "", status.Errorf(status.NotFound, "provided peer key doesn't exists %s", peerKey) + } + + return accountID, nil } // GetInstallationID returns the installation ID from the store diff --git a/management/server/sqlite_store.go b/management/server/sqlite_store.go index 044eae61e..bdb889919 100644 --- a/management/server/sqlite_store.go +++ b/management/server/sqlite_store.go @@ -289,7 +289,15 @@ func (s *SqliteStore) SavePeerStatus(accountID, peerID string, peerStatus nbpeer "peer_status_requires_approval": peerStatus.RequiresApproval, }) - return result.Error + if result.Error != nil { + return result.Error + } + + if result.RowsAffected == 0 { + return status.Errorf(status.NotFound, "peer %s not found", peerID) + } + + return nil } func (s *SqliteStore) SavePeerLocation(accountID string, peerWithLocation *nbpeer.Peer) error { @@ -303,7 +311,16 @@ func (s *SqliteStore) SavePeerLocation(accountID string, peerWithLocation *nbpee "location_city_name": location.CityName, "location_geo_name_id": location.GeoNameID, }) - return result.Error + + if result.Error != nil { + return result.Error + } + + if result.RowsAffected == 0 { + return status.Errorf(status.NotFound, "peer %s not found", peerWithLocation.ID) + } + + return nil } // DeleteHashedPAT2TokenIDIndex is noop in Sqlite