Skip to content

Commit

Permalink
[management] merge update account peers in sync call (#2978)
Browse files Browse the repository at this point in the history
  • Loading branch information
pascal-fischer authored Dec 3, 2024
1 parent e5d42bc commit d063fbb
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions management/server/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -678,40 +678,34 @@ func (am *DefaultAccountManager) SyncPeer(ctx context.Context, sync PeerSync, ac
if err != nil {
return nil, nil, nil, fmt.Errorf("failed to save peer: %w", err)
}

if sync.UpdateAccountPeers {
am.updateAccountPeers(ctx, account.Id)
}
}

peerNotValid, isStatusChanged, err := am.integratedPeerValidator.IsNotValidPeer(ctx, account.Id, peer, account.GetPeerGroupsList(peer.ID), account.Settings.Extra)
if err != nil {
return nil, nil, nil, fmt.Errorf("failed to validate peer: %w", err)
}

var postureChecks []*posture.Checks
postureChecks, err := am.getPeerPostureChecks(account, peer.ID)
if err != nil {
return nil, nil, nil, err
}

if isStatusChanged || sync.UpdateAccountPeers || (updated && len(postureChecks) > 0) {
am.updateAccountPeers(ctx, account.Id)
}

if peerNotValid {
emptyMap := &NetworkMap{
Network: account.Network.Copy(),
}
return peer, emptyMap, postureChecks, nil
}

if isStatusChanged {
am.updateAccountPeers(ctx, account.Id)
return peer, emptyMap, []*posture.Checks{}, nil
}

validPeersMap, err := am.GetValidatedPeers(account)
if err != nil {
return nil, nil, nil, fmt.Errorf("failed to get validated peers: %w", err)
}

postureChecks, err = am.getPeerPostureChecks(account, peer.ID)
if err != nil {
return nil, nil, nil, err
}

customZone := account.GetPeersCustomZone(ctx, am.dnsDomain)
return peer, account.GetPeerNetworkMap(ctx, peer.ID, customZone, validPeersMap, am.metrics.AccountManagerMetrics()), postureChecks, nil
}
Expand Down

0 comments on commit d063fbb

Please sign in to comment.