Use peers and groups map for peers validation

Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
This commit is contained in:
bcmmbaga
2025-01-15 12:50:25 +03:00
parent 6367fe4f74
commit 4afaabb33c
4 changed files with 11 additions and 11 deletions

View File

@@ -147,7 +147,7 @@ func TestMigrateNetIPFieldFromBlobToJSON_WithJSONData(t *testing.T) {
err = db.Save(&types.Account{
Id: "1234",
PeersG: []*nbpeer.Peer{
PeersG: []nbpeer.Peer{
{Location: nbpeer.Location{ConnectionIP: net.IP{10, 0, 0, 1}}},
}},
).Error

View File

@@ -101,7 +101,7 @@ func (am *DefaultAccountManager) GetPeers(ctx context.Context, accountID, userID
return nil, err
}
approvedPeersMap, err := am.integratedPeerValidator.GetValidatedPeers(accountID, account.GroupsG, account.PeersG, account.Settings.Extra)
approvedPeersMap, err := am.integratedPeerValidator.GetValidatedPeers(accountID, maps.Values(account.Groups), maps.Values(account.Peers), account.Settings.Extra)
if err != nil {
return nil, err
}
@@ -404,7 +404,7 @@ func (am *DefaultAccountManager) GetNetworkMap(ctx context.Context, peerID strin
groups[groupID] = group.Peers
}
validatedPeers, err := am.integratedPeerValidator.GetValidatedPeers(account.Id, account.GroupsG, account.PeersG, account.Settings.Extra)
validatedPeers, err := am.integratedPeerValidator.GetValidatedPeers(account.Id, maps.Values(account.Groups), maps.Values(account.Peers), account.Settings.Extra)
if err != nil {
return nil, err
}
@@ -962,7 +962,7 @@ func (am *DefaultAccountManager) getValidatedPeerWithMap(ctx context.Context, is
return nil, nil, nil, err
}
approvedPeersMap, err := am.integratedPeerValidator.GetValidatedPeers(account.Id, account.GroupsG, account.PeersG, account.Settings.Extra)
approvedPeersMap, err := am.integratedPeerValidator.GetValidatedPeers(account.Id, maps.Values(account.Groups), maps.Values(account.Peers), account.Settings.Extra)
if err != nil {
return nil, nil, nil, err
}
@@ -1071,7 +1071,7 @@ func (am *DefaultAccountManager) GetPeer(ctx context.Context, accountID, peerID,
return nil, err
}
approvedPeersMap, err := am.integratedPeerValidator.GetValidatedPeers(accountID, account.GroupsG, account.PeersG, account.Settings.Extra)
approvedPeersMap, err := am.integratedPeerValidator.GetValidatedPeers(accountID, maps.Values(account.Groups), maps.Values(account.Peers), account.Settings.Extra)
if err != nil {
return nil, err
}
@@ -1104,7 +1104,7 @@ func (am *DefaultAccountManager) UpdateAccountPeers(ctx context.Context, account
}
}()
approvedPeersMap, err := am.integratedPeerValidator.GetValidatedPeers(account.Id, account.GroupsG, account.PeersG, account.Settings.Extra)
approvedPeersMap, err := am.integratedPeerValidator.GetValidatedPeers(account.Id, maps.Values(account.Groups), maps.Values(account.Peers), account.Settings.Extra)
if err != nil {
log.WithContext(ctx).Errorf("failed to send out updates to peers, failed to get validate peers: %v", err)
return
@@ -1165,7 +1165,7 @@ func (am *DefaultAccountManager) UpdateAccountPeer(ctx context.Context, accountI
return
}
approvedPeersMap, err := am.integratedPeerValidator.GetValidatedPeers(account.Id, account.GroupsG, account.PeersG, account.Settings.Extra)
approvedPeersMap, err := am.integratedPeerValidator.GetValidatedPeers(account.Id, maps.Values(account.Groups), maps.Values(account.Peers), account.Settings.Extra)
if err != nil {
log.WithContext(ctx).Errorf("failed to send update to peer %s, failed to validate peers: %v", peerId, err)
return

View File

@@ -221,7 +221,7 @@ func generateAccountSQLTypes(account *types.Account) {
for id, peer := range account.Peers {
peer.ID = id
account.PeersG = append(account.PeersG, peer)
account.PeersG = append(account.PeersG, *peer)
}
for id, user := range account.Users {
@@ -235,7 +235,7 @@ func generateAccountSQLTypes(account *types.Account) {
for id, group := range account.Groups {
group.ID = id
account.GroupsG = append(account.GroupsG, group)
account.GroupsG = append(account.GroupsG, *group)
}
for id, route := range account.Routes {

View File

@@ -54,11 +54,11 @@ type Account struct {
SetupKeysG []SetupKey `json:"-" gorm:"foreignKey:AccountID;references:id"`
Network *Network `gorm:"embedded;embeddedPrefix:network_"`
Peers map[string]*nbpeer.Peer `gorm:"-"`
PeersG []*nbpeer.Peer `json:"-" gorm:"foreignKey:AccountID;references:id"`
PeersG []nbpeer.Peer `json:"-" gorm:"foreignKey:AccountID;references:id"`
Users map[string]*User `gorm:"-"`
UsersG []User `json:"-" gorm:"foreignKey:AccountID;references:id"`
Groups map[string]*Group `gorm:"-"`
GroupsG []*Group `json:"-" gorm:"foreignKey:AccountID;references:id"`
GroupsG []Group `json:"-" gorm:"foreignKey:AccountID;references:id"`
Policies []*Policy `gorm:"foreignKey:AccountID;references:id"`
Routes map[route.ID]*route.Route `gorm:"-"`
RoutesG []route.Route `json:"-" gorm:"foreignKey:AccountID;references:id"`