mirror of
https://github.com/netbirdio/netbird.git
synced 2025-01-19 04:19:48 +01:00
Update account peers on login on meta change (#2991)
* Update account peers on login on meta change * Factor out LoginPeer peer not found handling
This commit is contained in:
parent
e67fe89adb
commit
713e320c4c
@ -710,11 +710,7 @@ func (am *DefaultAccountManager) SyncPeer(ctx context.Context, sync PeerSync, ac
|
|||||||
return peer, account.GetPeerNetworkMap(ctx, peer.ID, customZone, validPeersMap, am.metrics.AccountManagerMetrics()), postureChecks, nil
|
return peer, account.GetPeerNetworkMap(ctx, peer.ID, customZone, validPeersMap, am.metrics.AccountManagerMetrics()), postureChecks, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoginPeer logs in or registers a peer.
|
func (am *DefaultAccountManager) handlePeerLoginNotFound(ctx context.Context, login PeerLogin, err error) (*nbpeer.Peer, *NetworkMap, []*posture.Checks, error) {
|
||||||
// If peer doesn't exist the function checks whether a setup key or a user is present and registers a new peer if so.
|
|
||||||
func (am *DefaultAccountManager) LoginPeer(ctx context.Context, login PeerLogin) (*nbpeer.Peer, *NetworkMap, []*posture.Checks, error) {
|
|
||||||
accountID, err := am.Store.GetAccountIDByPeerPubKey(ctx, login.WireGuardPubKey)
|
|
||||||
if err != nil {
|
|
||||||
if errStatus, ok := status.FromError(err); ok && errStatus.Type() == status.NotFound {
|
if errStatus, ok := status.FromError(err); ok && errStatus.Type() == status.NotFound {
|
||||||
// we couldn't find this peer by its public key which can mean that peer hasn't been registered yet.
|
// we couldn't find this peer by its public key which can mean that peer hasn't been registered yet.
|
||||||
// Try registering it.
|
// Try registering it.
|
||||||
@ -732,6 +728,14 @@ func (am *DefaultAccountManager) LoginPeer(ctx context.Context, login PeerLogin)
|
|||||||
return nil, nil, nil, status.Errorf(status.Internal, "failed while logging in peer")
|
return nil, nil, nil, status.Errorf(status.Internal, "failed while logging in peer")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LoginPeer logs in or registers a peer.
|
||||||
|
// If peer doesn't exist the function checks whether a setup key or a user is present and registers a new peer if so.
|
||||||
|
func (am *DefaultAccountManager) LoginPeer(ctx context.Context, login PeerLogin) (*nbpeer.Peer, *NetworkMap, []*posture.Checks, error) {
|
||||||
|
accountID, err := am.Store.GetAccountIDByPeerPubKey(ctx, login.WireGuardPubKey)
|
||||||
|
if err != nil {
|
||||||
|
return am.handlePeerLoginNotFound(ctx, login, err)
|
||||||
|
}
|
||||||
|
|
||||||
// when the client sends a login request with a JWT which is used to get the user ID,
|
// when the client sends a login request with a JWT which is used to get the user ID,
|
||||||
// it means that the client has already checked if it needs login and had been through the SSO flow
|
// it means that the client has already checked if it needs login and had been through the SSO flow
|
||||||
// so, we can skip this check and directly proceed with the login
|
// so, we can skip this check and directly proceed with the login
|
||||||
@ -828,7 +832,12 @@ func (am *DefaultAccountManager) LoginPeer(ctx context.Context, login PeerLogin)
|
|||||||
return nil, nil, nil, err
|
return nil, nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if updateRemotePeers || isStatusChanged {
|
postureChecks, err := am.getPeerPostureChecks(account, peer.ID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if updateRemotePeers || isStatusChanged || (updated && len(postureChecks) > 0) {
|
||||||
am.updateAccountPeers(ctx, accountID)
|
am.updateAccountPeers(ctx, accountID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user