Skip to content

Commit

Permalink
Assign groups to peers when registering with the setup key (#466)
Browse files Browse the repository at this point in the history
  • Loading branch information
braginini authored Sep 13, 2022
1 parent be7d829 commit cd7d1a8
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions management/server/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ func (am *DefaultAccountManager) AddPeer(
var account *Account
var err error
var sk *SetupKey
// auto-assign groups that are coming with a SetupKey or a User
var groupsToAdd []string
if len(upperKey) != 0 {
account, err = am.Store.GetAccountBySetupKey(upperKey)
if err != nil {
Expand Down Expand Up @@ -321,6 +323,8 @@ func (am *DefaultAccountManager) AddPeer(
)
}

groupsToAdd = sk.AutoGroups

} else if len(userID) != 0 {
account, err = am.Store.GetUserAccount(userID)
if err != nil {
Expand Down Expand Up @@ -361,6 +365,14 @@ func (am *DefaultAccountManager) AddPeer(
}
group.Peers = append(group.Peers, newPeer.Key)

if len(groupsToAdd) > 0 {
for _, s := range groupsToAdd {
if g, ok := account.Groups[s]; ok && g.Name != "All" {
g.Peers = append(g.Peers, newPeer.Key)
}
}
}

account.Peers[newPeer.Key] = newPeer
if len(upperKey) != 0 {
account.SetupKeys[sk.Key] = sk.IncrementUsage()
Expand Down

0 comments on commit cd7d1a8

Please sign in to comment.