From dc8f55f23e925061847d59236f191763434b5d9a Mon Sep 17 00:00:00 2001 From: Pascal Fischer Date: Mon, 4 Dec 2023 16:26:34 +0100 Subject: [PATCH] remove dependency cycle from prepare peer --- go.mod | 2 +- go.sum | 4 ++++ management/server/peer.go | 18 ++++++++++-------- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index 1d83be3b3..12b7d9a95 100644 --- a/go.mod +++ b/go.mod @@ -51,7 +51,7 @@ require ( github.com/miekg/dns v1.1.43 github.com/mitchellh/hashstructure/v2 v2.0.2 github.com/nadoo/ipset v0.5.0 - github.com/netbirdio/management-integrations/additions v0.0.0-20231204103351-c9d8082fc22f + github.com/netbirdio/management-integrations/additions v0.0.0-20231204152258-2328ed53de48 github.com/netbirdio/management-integrations/integrations v0.0.0-20231128140355-566178608e97 github.com/okta/okta-sdk-golang/v2 v2.18.0 github.com/patrickmn/go-cache v2.1.0+incompatible diff --git a/go.sum b/go.sum index 4474f9b4f..b0fdfecfd 100644 --- a/go.sum +++ b/go.sum @@ -501,6 +501,10 @@ github.com/netbirdio/management-integrations/additions v0.0.0-20231204103019-ac6 github.com/netbirdio/management-integrations/additions v0.0.0-20231204103019-ac6dd5a9c91c/go.mod h1:31FhBNvQ+riHEIu6LSTmqr8IeuSIsGfQffqV4LFmbwA= github.com/netbirdio/management-integrations/additions v0.0.0-20231204103351-c9d8082fc22f h1:yDNCzVwhgV05+D1sFmXCj9HEr2sob/MoWaGQLy3mKyY= github.com/netbirdio/management-integrations/additions v0.0.0-20231204103351-c9d8082fc22f/go.mod h1:31FhBNvQ+riHEIu6LSTmqr8IeuSIsGfQffqV4LFmbwA= +github.com/netbirdio/management-integrations/additions v0.0.0-20231204151811-a5cf1000bdd4 h1:ApjFM/CU3My4lLL1HVb0j7q4+jmXdbYFVT8RJNLQjyc= +github.com/netbirdio/management-integrations/additions v0.0.0-20231204151811-a5cf1000bdd4/go.mod h1:31FhBNvQ+riHEIu6LSTmqr8IeuSIsGfQffqV4LFmbwA= +github.com/netbirdio/management-integrations/additions v0.0.0-20231204152258-2328ed53de48 h1:TEaiKhkxwIFA2AmIj/7x9X/6zlXjV68Vs6Wclew1oTs= +github.com/netbirdio/management-integrations/additions v0.0.0-20231204152258-2328ed53de48/go.mod h1:31FhBNvQ+riHEIu6LSTmqr8IeuSIsGfQffqV4LFmbwA= github.com/netbirdio/management-integrations/integrations v0.0.0-20231128140355-566178608e97 h1:2VmrReIXt4W45l7O93kzoTq7Bpn3CDGKhBwnqih0eao= github.com/netbirdio/management-integrations/integrations v0.0.0-20231128140355-566178608e97/go.mod h1:eRv50kd3bXd2y59HK3OY4RI8YUL0JEN290D5dqW4llY= github.com/netbirdio/service v0.0.0-20230215170314-b923b89432b0 h1:hirFRfx3grVA/9eEyjME5/z3nxdJlN9kfQpvWWPk32g= diff --git a/management/server/peer.go b/management/server/peer.go index c025d7fd6..de7ce263e 100644 --- a/management/server/peer.go +++ b/management/server/peer.go @@ -406,14 +406,16 @@ func (am *DefaultAccountManager) AddPeer(setupKey, userID string, peer *nbpeer.P Ephemeral: ephemeral, } - peerToAdd := additions.PreparePeer(newPeer, account.Settings) + if account.Settings.Extra != nil { + newPeer = additions.PreparePeer(newPeer, account.Settings.Extra) + } // add peer to 'All' group group, err := account.GetGroupAll() if err != nil { return nil, nil, err } - group.Peers = append(group.Peers, peerToAdd.ID) + group.Peers = append(group.Peers, newPeer.ID) var groupsToAdd []string if addedByUser { @@ -431,27 +433,27 @@ func (am *DefaultAccountManager) AddPeer(setupKey, userID string, peer *nbpeer.P if len(groupsToAdd) > 0 { for _, s := range groupsToAdd { if g, ok := account.Groups[s]; ok && g.Name != "All" { - g.Peers = append(g.Peers, peerToAdd.ID) + g.Peers = append(g.Peers, newPeer.ID) } } } - account.Peers[peerToAdd.ID] = newPeer + account.Peers[newPeer.ID] = newPeer account.Network.IncSerial() err = am.Store.SaveAccount(account) if err != nil { return nil, nil, err } - opEvent.TargetID = peerToAdd.ID - opEvent.Meta = peerToAdd.EventMeta(am.GetDNSDomain()) + opEvent.TargetID = newPeer.ID + opEvent.Meta = newPeer.EventMeta(am.GetDNSDomain()) am.StoreEvent(opEvent.InitiatorID, opEvent.TargetID, opEvent.AccountID, opEvent.Activity, opEvent.Meta) am.updateAccountPeers(account) - networkMap := account.GetPeerNetworkMap(peerToAdd.ID, am.dnsDomain) - return peerToAdd, networkMap, nil + networkMap := account.GetPeerNetworkMap(newPeer.ID, am.dnsDomain) + return newPeer, networkMap, nil } // SyncPeer checks whether peer is eligible for receiving NetworkMap (authenticated) and returns its NetworkMap if eligible