mirror of
https://github.com/netbirdio/netbird.git
synced 2024-11-22 08:03:30 +01:00
extract peer preparation
This commit is contained in:
parent
d5bf79bc51
commit
b9fc008542
2
go.mod
2
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-20231129145353-f46b1dd842f2
|
||||
github.com/netbirdio/management-integrations/additions v0.0.0-20231204103351-c9d8082fc22f
|
||||
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
|
||||
|
4
go.sum
4
go.sum
@ -497,6 +497,10 @@ github.com/nadoo/ipset v0.5.0 h1:5GJUAuZ7ITQQQGne5J96AmFjRtI8Avlbk6CabzYWVUc=
|
||||
github.com/nadoo/ipset v0.5.0/go.mod h1:rYF5DQLRGGoQ8ZSWeK+6eX5amAuPqwFkWjhQlEITGJQ=
|
||||
github.com/netbirdio/management-integrations/additions v0.0.0-20231129145353-f46b1dd842f2 h1:fNGkwtLHz0U4bP3bPVSwbtfL4I0ZVNYNCpmGwl6TETE=
|
||||
github.com/netbirdio/management-integrations/additions v0.0.0-20231129145353-f46b1dd842f2/go.mod h1:31FhBNvQ+riHEIu6LSTmqr8IeuSIsGfQffqV4LFmbwA=
|
||||
github.com/netbirdio/management-integrations/additions v0.0.0-20231204103019-ac6dd5a9c91c h1:LerqmkLL6OG+1n+wzxgXOx6kJZETUJVAvU5fZokUn9Q=
|
||||
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/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=
|
||||
|
@ -406,16 +406,14 @@ func (am *DefaultAccountManager) AddPeer(setupKey, userID string, peer *nbpeer.P
|
||||
Ephemeral: ephemeral,
|
||||
}
|
||||
|
||||
if account.Settings.Extra != nil && account.Settings.Extra.PeerApprovalEnabled {
|
||||
newPeer.Status.RequiresApproval = true
|
||||
}
|
||||
peerToAdd := additions.PreparePeer(newPeer, account.Settings)
|
||||
|
||||
// add peer to 'All' group
|
||||
group, err := account.GetGroupAll()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
group.Peers = append(group.Peers, newPeer.ID)
|
||||
group.Peers = append(group.Peers, peerToAdd.ID)
|
||||
|
||||
var groupsToAdd []string
|
||||
if addedByUser {
|
||||
@ -433,26 +431,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, newPeer.ID)
|
||||
g.Peers = append(g.Peers, peerToAdd.ID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
account.Peers[newPeer.ID] = newPeer
|
||||
account.Peers[peerToAdd.ID] = newPeer
|
||||
account.Network.IncSerial()
|
||||
err = am.Store.SaveAccount(account)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
opEvent.TargetID = newPeer.ID
|
||||
opEvent.Meta = newPeer.EventMeta(am.GetDNSDomain())
|
||||
opEvent.TargetID = peerToAdd.ID
|
||||
opEvent.Meta = peerToAdd.EventMeta(am.GetDNSDomain())
|
||||
|
||||
am.StoreEvent(opEvent.InitiatorID, opEvent.TargetID, opEvent.AccountID, opEvent.Activity, opEvent.Meta)
|
||||
|
||||
am.updateAccountPeers(account)
|
||||
|
||||
networkMap := account.GetPeerNetworkMap(newPeer.ID, am.dnsDomain)
|
||||
return newPeer, networkMap, nil
|
||||
networkMap := account.GetPeerNetworkMap(peerToAdd.ID, am.dnsDomain)
|
||||
return peerToAdd, networkMap, nil
|
||||
}
|
||||
|
||||
// SyncPeer checks whether peer is eligible for receiving NetworkMap (authenticated) and returns its NetworkMap if eligible
|
||||
|
Loading…
Reference in New Issue
Block a user