mirror of
https://github.com/netbirdio/netbird.git
synced 2025-01-21 21:38:44 +01:00
allow resources in groups
This commit is contained in:
parent
1af0d2c669
commit
ef15aec62b
2
go.mod
2
go.mod
@ -60,7 +60,7 @@ require (
|
|||||||
github.com/miekg/dns v1.1.59
|
github.com/miekg/dns v1.1.59
|
||||||
github.com/mitchellh/hashstructure/v2 v2.0.2
|
github.com/mitchellh/hashstructure/v2 v2.0.2
|
||||||
github.com/nadoo/ipset v0.5.0
|
github.com/nadoo/ipset v0.5.0
|
||||||
github.com/netbirdio/management-integrations/integrations v0.0.0-20241106153857-de8e2beb5254
|
github.com/netbirdio/management-integrations/integrations v0.0.0-20241211172827-ba0a446be480
|
||||||
github.com/netbirdio/signal-dispatcher/dispatcher v0.0.0-20241010133937-e0df50df217d
|
github.com/netbirdio/signal-dispatcher/dispatcher v0.0.0-20241010133937-e0df50df217d
|
||||||
github.com/okta/okta-sdk-golang/v2 v2.18.0
|
github.com/okta/okta-sdk-golang/v2 v2.18.0
|
||||||
github.com/oschwald/maxminddb-golang v1.12.0
|
github.com/oschwald/maxminddb-golang v1.12.0
|
||||||
|
2
go.sum
2
go.sum
@ -523,6 +523,8 @@ github.com/netbirdio/ice/v3 v3.0.0-20240315174635-e72a50fcb64e h1:PURA50S8u4mF6R
|
|||||||
github.com/netbirdio/ice/v3 v3.0.0-20240315174635-e72a50fcb64e/go.mod h1:YMLU7qbKfVjmEv7EoZPIVEI+kNYxWCdPK3VS0BU+U4Q=
|
github.com/netbirdio/ice/v3 v3.0.0-20240315174635-e72a50fcb64e/go.mod h1:YMLU7qbKfVjmEv7EoZPIVEI+kNYxWCdPK3VS0BU+U4Q=
|
||||||
github.com/netbirdio/management-integrations/integrations v0.0.0-20241106153857-de8e2beb5254 h1:L8mNd3tBxMdnQNxMNJ+/EiwHwizNOMy8/nHLVGNfjpg=
|
github.com/netbirdio/management-integrations/integrations v0.0.0-20241106153857-de8e2beb5254 h1:L8mNd3tBxMdnQNxMNJ+/EiwHwizNOMy8/nHLVGNfjpg=
|
||||||
github.com/netbirdio/management-integrations/integrations v0.0.0-20241106153857-de8e2beb5254/go.mod h1:nykwWZnxb+sJz2Z//CEq45CMRWSHllH8pODKRB8eY7Y=
|
github.com/netbirdio/management-integrations/integrations v0.0.0-20241106153857-de8e2beb5254/go.mod h1:nykwWZnxb+sJz2Z//CEq45CMRWSHllH8pODKRB8eY7Y=
|
||||||
|
github.com/netbirdio/management-integrations/integrations v0.0.0-20241211172827-ba0a446be480 h1:M+UPn/o+plVE7ZehgL6/1dftptsO1tyTPssgImgi+28=
|
||||||
|
github.com/netbirdio/management-integrations/integrations v0.0.0-20241211172827-ba0a446be480/go.mod h1:RC0PnyATSBPrRWKQgb+7KcC1tMta9eYyzuA414RG9wQ=
|
||||||
github.com/netbirdio/service v0.0.0-20240911161631-f62744f42502 h1:3tHlFmhTdX9axERMVN63dqyFqnvuD+EMJHzM7mNGON8=
|
github.com/netbirdio/service v0.0.0-20240911161631-f62744f42502 h1:3tHlFmhTdX9axERMVN63dqyFqnvuD+EMJHzM7mNGON8=
|
||||||
github.com/netbirdio/service v0.0.0-20240911161631-f62744f42502/go.mod h1:CIMRFEJVL+0DS1a3Nx06NaMn4Dz63Ng6O7dl0qH0zVM=
|
github.com/netbirdio/service v0.0.0-20240911161631-f62744f42502/go.mod h1:CIMRFEJVL+0DS1a3Nx06NaMn4Dz63Ng6O7dl0qH0zVM=
|
||||||
github.com/netbirdio/signal-dispatcher/dispatcher v0.0.0-20241010133937-e0df50df217d h1:bRq5TKgC7Iq20pDiuC54yXaWnAVeS5PdGpSokFTlR28=
|
github.com/netbirdio/signal-dispatcher/dispatcher v0.0.0-20241010133937-e0df50df217d h1:bRq5TKgC7Iq20pDiuC54yXaWnAVeS5PdGpSokFTlR28=
|
||||||
|
@ -11,8 +11,6 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
nbgroup "github.com/netbirdio/netbird/management/server/group"
|
|
||||||
|
|
||||||
nbdns "github.com/netbirdio/netbird/dns"
|
nbdns "github.com/netbirdio/netbird/dns"
|
||||||
"github.com/netbirdio/netbird/management/server/status"
|
"github.com/netbirdio/netbird/management/server/status"
|
||||||
"github.com/netbirdio/netbird/management/server/types"
|
"github.com/netbirdio/netbird/management/server/types"
|
||||||
@ -661,7 +659,7 @@ func TestGroupAccountPeersUpdate(t *testing.T) {
|
|||||||
close(done)
|
close(done)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
err = manager.SaveGroup(context.Background(), account.Id, userID, &nbgroup.Group{
|
err = manager.SaveGroup(context.Background(), account.Id, userID, &types.Group{
|
||||||
ID: "groupD",
|
ID: "groupD",
|
||||||
Name: "GroupD",
|
Name: "GroupD",
|
||||||
Peers: []string{peer1.ID},
|
Peers: []string{peer1.ID},
|
||||||
|
@ -292,7 +292,8 @@ func toGroupResponse(peers []*nbpeer.Peer, group *types.Group) *api.Group {
|
|||||||
peersMap[peer.ID] = peer
|
peersMap[peer.ID] = peer
|
||||||
}
|
}
|
||||||
|
|
||||||
cache := make(map[string]api.PeerMinimum)
|
peerCache := make(map[string]api.PeerMinimum)
|
||||||
|
resCache := make(map[string]api.Resource)
|
||||||
gr := api.Group{
|
gr := api.Group{
|
||||||
Id: group.ID,
|
Id: group.ID,
|
||||||
Name: group.Name,
|
Name: group.Name,
|
||||||
@ -300,7 +301,7 @@ func toGroupResponse(peers []*nbpeer.Peer, group *types.Group) *api.Group {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, pid := range group.Peers {
|
for _, pid := range group.Peers {
|
||||||
_, ok := cache[pid]
|
_, ok := peerCache[pid]
|
||||||
if !ok {
|
if !ok {
|
||||||
peer, ok := peersMap[pid]
|
peer, ok := peersMap[pid]
|
||||||
if !ok {
|
if !ok {
|
||||||
@ -310,7 +311,7 @@ func toGroupResponse(peers []*nbpeer.Peer, group *types.Group) *api.Group {
|
|||||||
Id: peer.ID,
|
Id: peer.ID,
|
||||||
Name: peer.Name,
|
Name: peer.Name,
|
||||||
}
|
}
|
||||||
cache[pid] = peerResp
|
peerCache[pid] = peerResp
|
||||||
gr.Peers = append(gr.Peers, peerResp)
|
gr.Peers = append(gr.Peers, peerResp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -318,20 +319,19 @@ func toGroupResponse(peers []*nbpeer.Peer, group *types.Group) *api.Group {
|
|||||||
gr.PeersCount = len(gr.Peers)
|
gr.PeersCount = len(gr.Peers)
|
||||||
|
|
||||||
for _, res := range group.Resources {
|
for _, res := range group.Resources {
|
||||||
_, ok := cache[res.ID]
|
_, ok := resCache[res.ID]
|
||||||
if !ok {
|
if !ok {
|
||||||
peer, ok := peersMap[pid]
|
resource, ok := resMap[res.ID]
|
||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
peerResp := api.PeerMinimum{
|
resResp := resource.ToAPIResponse()
|
||||||
Id: peer.ID,
|
resCache[res.ID] = *resResp
|
||||||
Name: peer.Name,
|
gr.Resources = append(gr.Resources, *resResp)
|
||||||
}
|
|
||||||
cache[pid] = peerResp
|
|
||||||
gr.Peers = append(gr.Peers, peerResp)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gr.ResourcesCount = len(gr.Resources)
|
||||||
|
|
||||||
return &gr
|
return &gr
|
||||||
}
|
}
|
||||||
|
@ -16,8 +16,6 @@ import (
|
|||||||
"github.com/magiconair/properties/assert"
|
"github.com/magiconair/properties/assert"
|
||||||
"golang.org/x/exp/maps"
|
"golang.org/x/exp/maps"
|
||||||
|
|
||||||
nbgroup "github.com/netbirdio/netbird/management/server/group"
|
|
||||||
|
|
||||||
"github.com/netbirdio/netbird/management/server"
|
"github.com/netbirdio/netbird/management/server"
|
||||||
"github.com/netbirdio/netbird/management/server/http/api"
|
"github.com/netbirdio/netbird/management/server/http/api"
|
||||||
"github.com/netbirdio/netbird/management/server/http/util"
|
"github.com/netbirdio/netbird/management/server/http/util"
|
||||||
@ -25,6 +23,7 @@ import (
|
|||||||
"github.com/netbirdio/netbird/management/server/mock_server"
|
"github.com/netbirdio/netbird/management/server/mock_server"
|
||||||
nbpeer "github.com/netbirdio/netbird/management/server/peer"
|
nbpeer "github.com/netbirdio/netbird/management/server/peer"
|
||||||
"github.com/netbirdio/netbird/management/server/status"
|
"github.com/netbirdio/netbird/management/server/status"
|
||||||
|
"github.com/netbirdio/netbird/management/server/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
var TestPeers = map[string]*nbpeer.Peer{
|
var TestPeers = map[string]*nbpeer.Peer{
|
||||||
@ -155,7 +154,7 @@ func TestGetGroup(t *testing.T) {
|
|||||||
t.Fatalf("I don't know what I expected; %v", err)
|
t.Fatalf("I don't know what I expected; %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
got := &nbgroup.Group{}
|
got := &types.Group{}
|
||||||
if err = json.Unmarshal(content, &got); err != nil {
|
if err = json.Unmarshal(content, &got); err != nil {
|
||||||
t.Fatalf("Sent content is not in correct json format; %v", err)
|
t.Fatalf("Sent content is not in correct json format; %v", err)
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
|
|
||||||
"github.com/netbirdio/netbird/management/server/account"
|
"github.com/netbirdio/netbird/management/server/account"
|
||||||
nbpeer "github.com/netbirdio/netbird/management/server/peer"
|
nbpeer "github.com/netbirdio/netbird/management/server/peer"
|
||||||
|
"github.com/netbirdio/netbird/management/server/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// IntegratedValidator interface exists to avoid the circle dependencies
|
// IntegratedValidator interface exists to avoid the circle dependencies
|
||||||
|
@ -13,6 +13,7 @@ import (
|
|||||||
"github.com/netbirdio/netbird/management/server/activity"
|
"github.com/netbirdio/netbird/management/server/activity"
|
||||||
"github.com/netbirdio/netbird/management/server/status"
|
"github.com/netbirdio/netbird/management/server/status"
|
||||||
"github.com/netbirdio/netbird/management/server/store"
|
"github.com/netbirdio/netbird/management/server/store"
|
||||||
|
"github.com/netbirdio/netbird/management/server/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
const domainPattern = `^(?i)[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,}$`
|
const domainPattern = `^(?i)[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,}$`
|
||||||
|
@ -13,8 +13,6 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
nbgroup "github.com/netbirdio/netbird/management/server/group"
|
|
||||||
|
|
||||||
"github.com/netbirdio/netbird/management/domain"
|
"github.com/netbirdio/netbird/management/domain"
|
||||||
"github.com/netbirdio/netbird/management/server/activity"
|
"github.com/netbirdio/netbird/management/server/activity"
|
||||||
nbpeer "github.com/netbirdio/netbird/management/server/peer"
|
nbpeer "github.com/netbirdio/netbird/management/server/peer"
|
||||||
@ -2148,7 +2146,7 @@ func TestRouteAccountPeersUpdate(t *testing.T) {
|
|||||||
close(done)
|
close(done)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
err = manager.SaveGroup(context.Background(), account.Id, userID, &nbgroup.Group{
|
err = manager.SaveGroup(context.Background(), account.Id, userID, &types.Group{
|
||||||
ID: "groupC",
|
ID: "groupC",
|
||||||
Name: "GroupC",
|
Name: "GroupC",
|
||||||
Peers: []string{peer1ID},
|
Peers: []string{peer1ID},
|
||||||
|
@ -436,7 +436,7 @@ func (s *SqlStore) SaveUser(ctx context.Context, lockStrength LockingStrength, u
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SaveGroups saves the given list of groups to the database.
|
// SaveGroups saves the given list of groups to the database.
|
||||||
func (s *SqlStore) SaveGroups(ctx context.Context, lockStrength LockingStrength, groups []*nbgroup.Group) error {
|
func (s *SqlStore) SaveGroups(ctx context.Context, lockStrength LockingStrength, groups []*types.Group) error {
|
||||||
if len(groups) == 0 {
|
if len(groups) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -574,8 +574,8 @@ func (s *SqlStore) GetAccountUsers(ctx context.Context, lockStrength LockingStre
|
|||||||
return users, nil
|
return users, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SqlStore) GetAccountGroups(ctx context.Context, lockStrength LockingStrength, accountID string) ([]*nbgroup.Group, error) {
|
func (s *SqlStore) GetAccountGroups(ctx context.Context, lockStrength LockingStrength, accountID string) ([]*types.Group, error) {
|
||||||
var groups []*nbgroup.Group
|
var groups []*types.Group
|
||||||
result := s.db.Clauses(clause.Locking{Strength: string(lockStrength)}).Find(&groups, accountIDCondition, accountID)
|
result := s.db.Clauses(clause.Locking{Strength: string(lockStrength)}).Find(&groups, accountIDCondition, accountID)
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
if errors.Is(result.Error, gorm.ErrRecordNotFound) {
|
if errors.Is(result.Error, gorm.ErrRecordNotFound) {
|
||||||
@ -658,7 +658,7 @@ func (s *SqlStore) GetAccount(ctx context.Context, accountID string) (*types.Acc
|
|||||||
}
|
}
|
||||||
account.UsersG = nil
|
account.UsersG = nil
|
||||||
|
|
||||||
account.Groups = make(map[string]*nbgroup.Group, len(account.GroupsG))
|
account.Groups = make(map[string]*types.Group, len(account.GroupsG))
|
||||||
for _, group := range account.GroupsG {
|
for _, group := range account.GroupsG {
|
||||||
account.Groups[group.ID] = group.Copy()
|
account.Groups[group.ID] = group.Copy()
|
||||||
}
|
}
|
||||||
@ -1020,7 +1020,7 @@ func (s *SqlStore) IncrementSetupKeyUsage(ctx context.Context, setupKeyID string
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *SqlStore) AddPeerToAllGroup(ctx context.Context, accountID string, peerID string) error {
|
func (s *SqlStore) AddPeerToAllGroup(ctx context.Context, accountID string, peerID string) error {
|
||||||
var group nbgroup.Group
|
var group types.Group
|
||||||
result := s.db.Where("account_id = ? AND name = ?", accountID, "All").First(&group)
|
result := s.db.Where("account_id = ? AND name = ?", accountID, "All").First(&group)
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
if errors.Is(result.Error, gorm.ErrRecordNotFound) {
|
if errors.Is(result.Error, gorm.ErrRecordNotFound) {
|
||||||
@ -1045,7 +1045,7 @@ func (s *SqlStore) AddPeerToAllGroup(ctx context.Context, accountID string, peer
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *SqlStore) AddPeerToGroup(ctx context.Context, accountId string, peerId string, groupID string) error {
|
func (s *SqlStore) AddPeerToGroup(ctx context.Context, accountId string, peerId string, groupID string) error {
|
||||||
var group nbgroup.Group
|
var group types.Group
|
||||||
result := s.db.Where(accountAndIDQueryCondition, accountId, groupID).First(&group)
|
result := s.db.Where(accountAndIDQueryCondition, accountId, groupID).First(&group)
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
if errors.Is(result.Error, gorm.ErrRecordNotFound) {
|
if errors.Is(result.Error, gorm.ErrRecordNotFound) {
|
||||||
@ -1205,8 +1205,8 @@ func (s *SqlStore) GetAccountDomainAndCategory(ctx context.Context, lockStrength
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetGroupByID retrieves a group by ID and account ID.
|
// GetGroupByID retrieves a group by ID and account ID.
|
||||||
func (s *SqlStore) GetGroupByID(ctx context.Context, lockStrength LockingStrength, accountID, groupID string) (*nbgroup.Group, error) {
|
func (s *SqlStore) GetGroupByID(ctx context.Context, lockStrength LockingStrength, accountID, groupID string) (*types.Group, error) {
|
||||||
var group *nbgroup.Group
|
var group *types.Group
|
||||||
result := s.db.Clauses(clause.Locking{Strength: string(lockStrength)}).First(&group, accountAndIDQueryCondition, accountID, groupID)
|
result := s.db.Clauses(clause.Locking{Strength: string(lockStrength)}).First(&group, accountAndIDQueryCondition, accountID, groupID)
|
||||||
if err := result.Error; err != nil {
|
if err := result.Error; err != nil {
|
||||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
@ -1220,8 +1220,8 @@ func (s *SqlStore) GetGroupByID(ctx context.Context, lockStrength LockingStrengt
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetGroupByName retrieves a group by name and account ID.
|
// GetGroupByName retrieves a group by name and account ID.
|
||||||
func (s *SqlStore) GetGroupByName(ctx context.Context, lockStrength LockingStrength, accountID, groupName string) (*nbgroup.Group, error) {
|
func (s *SqlStore) GetGroupByName(ctx context.Context, lockStrength LockingStrength, accountID, groupName string) (*types.Group, error) {
|
||||||
var group nbgroup.Group
|
var group types.Group
|
||||||
|
|
||||||
// TODO: This fix is accepted for now, but if we need to handle this more frequently
|
// TODO: This fix is accepted for now, but if we need to handle this more frequently
|
||||||
// we may need to reconsider changing the types.
|
// we may need to reconsider changing the types.
|
||||||
@ -1244,15 +1244,15 @@ func (s *SqlStore) GetGroupByName(ctx context.Context, lockStrength LockingStren
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetGroupsByIDs retrieves groups by their IDs and account ID.
|
// GetGroupsByIDs retrieves groups by their IDs and account ID.
|
||||||
func (s *SqlStore) GetGroupsByIDs(ctx context.Context, lockStrength LockingStrength, accountID string, groupIDs []string) (map[string]*nbgroup.Group, error) {
|
func (s *SqlStore) GetGroupsByIDs(ctx context.Context, lockStrength LockingStrength, accountID string, groupIDs []string) (map[string]*types.Group, error) {
|
||||||
var groups []*nbgroup.Group
|
var groups []*types.Group
|
||||||
result := s.db.Clauses(clause.Locking{Strength: string(lockStrength)}).Find(&groups, accountAndIDsQueryCondition, accountID, groupIDs)
|
result := s.db.Clauses(clause.Locking{Strength: string(lockStrength)}).Find(&groups, accountAndIDsQueryCondition, accountID, groupIDs)
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
log.WithContext(ctx).Errorf("failed to get groups by ID's from store: %s", result.Error)
|
log.WithContext(ctx).Errorf("failed to get groups by ID's from store: %s", result.Error)
|
||||||
return nil, status.Errorf(status.Internal, "failed to get groups by ID's from store")
|
return nil, status.Errorf(status.Internal, "failed to get groups by ID's from store")
|
||||||
}
|
}
|
||||||
|
|
||||||
groupsMap := make(map[string]*nbgroup.Group)
|
groupsMap := make(map[string]*types.Group)
|
||||||
for _, group := range groups {
|
for _, group := range groups {
|
||||||
groupsMap[group.ID] = group
|
groupsMap[group.ID] = group
|
||||||
}
|
}
|
||||||
@ -1261,7 +1261,7 @@ func (s *SqlStore) GetGroupsByIDs(ctx context.Context, lockStrength LockingStren
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SaveGroup saves a group to the store.
|
// SaveGroup saves a group to the store.
|
||||||
func (s *SqlStore) SaveGroup(ctx context.Context, lockStrength LockingStrength, group *nbgroup.Group) error {
|
func (s *SqlStore) SaveGroup(ctx context.Context, lockStrength LockingStrength, group *types.Group) error {
|
||||||
result := s.db.Clauses(clause.Locking{Strength: string(lockStrength)}).Save(group)
|
result := s.db.Clauses(clause.Locking{Strength: string(lockStrength)}).Save(group)
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
log.WithContext(ctx).Errorf("failed to save group to store: %v", result.Error)
|
log.WithContext(ctx).Errorf("failed to save group to store: %v", result.Error)
|
||||||
@ -1273,7 +1273,7 @@ func (s *SqlStore) SaveGroup(ctx context.Context, lockStrength LockingStrength,
|
|||||||
// DeleteGroup deletes a group from the database.
|
// DeleteGroup deletes a group from the database.
|
||||||
func (s *SqlStore) DeleteGroup(ctx context.Context, lockStrength LockingStrength, accountID, groupID string) error {
|
func (s *SqlStore) DeleteGroup(ctx context.Context, lockStrength LockingStrength, accountID, groupID string) error {
|
||||||
result := s.db.Clauses(clause.Locking{Strength: string(lockStrength)}).
|
result := s.db.Clauses(clause.Locking{Strength: string(lockStrength)}).
|
||||||
Delete(&nbgroup.Group{}, accountAndIDQueryCondition, accountID, groupID)
|
Delete(&types.Group{}, accountAndIDQueryCondition, accountID, groupID)
|
||||||
if err := result.Error; err != nil {
|
if err := result.Error; err != nil {
|
||||||
log.WithContext(ctx).Errorf("failed to delete group from store: %s", result.Error)
|
log.WithContext(ctx).Errorf("failed to delete group from store: %s", result.Error)
|
||||||
return status.Errorf(status.Internal, "failed to delete group from store")
|
return status.Errorf(status.Internal, "failed to delete group from store")
|
||||||
@ -1289,7 +1289,7 @@ func (s *SqlStore) DeleteGroup(ctx context.Context, lockStrength LockingStrength
|
|||||||
// DeleteGroups deletes groups from the database.
|
// DeleteGroups deletes groups from the database.
|
||||||
func (s *SqlStore) DeleteGroups(ctx context.Context, strength LockingStrength, accountID string, groupIDs []string) error {
|
func (s *SqlStore) DeleteGroups(ctx context.Context, strength LockingStrength, accountID string, groupIDs []string) error {
|
||||||
result := s.db.Clauses(clause.Locking{Strength: string(strength)}).
|
result := s.db.Clauses(clause.Locking{Strength: string(strength)}).
|
||||||
Delete(&nbgroup.Group{}, accountAndIDsQueryCondition, accountID, groupIDs)
|
Delete(&types.Group{}, accountAndIDsQueryCondition, accountID, groupIDs)
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
log.WithContext(ctx).Errorf("failed to delete groups from store: %v", result.Error)
|
log.WithContext(ctx).Errorf("failed to delete groups from store: %v", result.Error)
|
||||||
return status.Errorf(status.Internal, "failed to delete groups from store")
|
return status.Errorf(status.Internal, "failed to delete groups from store")
|
||||||
|
@ -19,8 +19,6 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
nbgroup "github.com/netbirdio/netbird/management/server/group"
|
|
||||||
|
|
||||||
nbdns "github.com/netbirdio/netbird/dns"
|
nbdns "github.com/netbirdio/netbird/dns"
|
||||||
resourceTypes "github.com/netbirdio/netbird/management/server/networks/resources/types"
|
resourceTypes "github.com/netbirdio/netbird/management/server/networks/resources/types"
|
||||||
routerTypes "github.com/netbirdio/netbird/management/server/networks/routers/types"
|
routerTypes "github.com/netbirdio/netbird/management/server/networks/routers/types"
|
||||||
@ -1202,7 +1200,7 @@ func TestSqlite_CreateAndGetObjectInTransaction(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
group := &nbgroup.Group{
|
group := &types.Group{
|
||||||
ID: "group-id",
|
ID: "group-id",
|
||||||
AccountID: "account-id",
|
AccountID: "account-id",
|
||||||
Name: "group-name",
|
Name: "group-name",
|
||||||
@ -1378,7 +1376,7 @@ func TestSqlStore_SaveGroup(t *testing.T) {
|
|||||||
|
|
||||||
accountID := "bf1c8084-ba50-4ce7-9439-34653001fc3b"
|
accountID := "bf1c8084-ba50-4ce7-9439-34653001fc3b"
|
||||||
|
|
||||||
group := &nbgroup.Group{
|
group := &types.Group{
|
||||||
ID: "group-id",
|
ID: "group-id",
|
||||||
AccountID: accountID,
|
AccountID: accountID,
|
||||||
Issued: "api",
|
Issued: "api",
|
||||||
@ -1399,7 +1397,7 @@ func TestSqlStore_SaveGroups(t *testing.T) {
|
|||||||
|
|
||||||
accountID := "bf1c8084-ba50-4ce7-9439-34653001fc3b"
|
accountID := "bf1c8084-ba50-4ce7-9439-34653001fc3b"
|
||||||
|
|
||||||
groups := []*nbgroup.Group{
|
groups := []*types.Group{
|
||||||
{
|
{
|
||||||
ID: "group-1",
|
ID: "group-1",
|
||||||
AccountID: accountID,
|
AccountID: accountID,
|
||||||
@ -2138,15 +2136,15 @@ func newAccountWithId(ctx context.Context, accountID, userID, domain string) *ty
|
|||||||
// addAllGroup to account object if it doesn't exist
|
// addAllGroup to account object if it doesn't exist
|
||||||
func addAllGroup(account *types.Account) error {
|
func addAllGroup(account *types.Account) error {
|
||||||
if len(account.Groups) == 0 {
|
if len(account.Groups) == 0 {
|
||||||
allGroup := &nbgroup.Group{
|
allGroup := &types.Group{
|
||||||
ID: xid.New().String(),
|
ID: xid.New().String(),
|
||||||
Name: "All",
|
Name: "All",
|
||||||
Issued: nbgroup.GroupIssuedAPI,
|
Issued: types.GroupIssuedAPI,
|
||||||
}
|
}
|
||||||
for _, peer := range account.Peers {
|
for _, peer := range account.Peers {
|
||||||
allGroup.Peers = append(allGroup.Peers, peer.ID)
|
allGroup.Peers = append(allGroup.Peers, peer.ID)
|
||||||
}
|
}
|
||||||
account.Groups = map[string]*nbgroup.Group{allGroup.ID: allGroup}
|
account.Groups = map[string]*types.Group{allGroup.ID: allGroup}
|
||||||
|
|
||||||
id := xid.New().String()
|
id := xid.New().String()
|
||||||
|
|
||||||
|
@ -76,9 +76,9 @@ type Store interface {
|
|||||||
GetAccountGroups(ctx context.Context, lockStrength LockingStrength, accountID string) ([]*types.Group, error)
|
GetAccountGroups(ctx context.Context, lockStrength LockingStrength, accountID string) ([]*types.Group, error)
|
||||||
GetGroupByID(ctx context.Context, lockStrength LockingStrength, groupID, accountID string) (*types.Group, error)
|
GetGroupByID(ctx context.Context, lockStrength LockingStrength, groupID, accountID string) (*types.Group, error)
|
||||||
GetGroupByName(ctx context.Context, lockStrength LockingStrength, groupName, accountID string) (*types.Group, error)
|
GetGroupByName(ctx context.Context, lockStrength LockingStrength, groupName, accountID string) (*types.Group, error)
|
||||||
GetGroupsByIDs(ctx context.Context, lockStrength LockingStrength, accountID string, groupIDs []string) (map[string]*nbgroup.Group, error)
|
GetGroupsByIDs(ctx context.Context, lockStrength LockingStrength, accountID string, groupIDs []string) (map[string]*types.Group, error)
|
||||||
SaveGroups(ctx context.Context, lockStrength LockingStrength, groups []*nbgroup.Group) error
|
SaveGroups(ctx context.Context, lockStrength LockingStrength, groups []*types.Group) error
|
||||||
SaveGroup(ctx context.Context, lockStrength LockingStrength, group *nbgroup.Group) error
|
SaveGroup(ctx context.Context, lockStrength LockingStrength, group *types.Group) error
|
||||||
DeleteGroup(ctx context.Context, lockStrength LockingStrength, accountID, groupID string) error
|
DeleteGroup(ctx context.Context, lockStrength LockingStrength, accountID, groupID string) error
|
||||||
DeleteGroups(ctx context.Context, strength LockingStrength, accountID string, groupIDs []string) error
|
DeleteGroups(ctx context.Context, strength LockingStrength, accountID string, groupIDs []string) error
|
||||||
|
|
||||||
|
@ -58,8 +58,8 @@ type Account struct {
|
|||||||
PeersG []nbpeer.Peer `json:"-" gorm:"foreignKey:AccountID;references:id"`
|
PeersG []nbpeer.Peer `json:"-" gorm:"foreignKey:AccountID;references:id"`
|
||||||
Users map[string]*User `gorm:"-"`
|
Users map[string]*User `gorm:"-"`
|
||||||
UsersG []User `json:"-" gorm:"foreignKey:AccountID;references:id"`
|
UsersG []User `json:"-" gorm:"foreignKey:AccountID;references:id"`
|
||||||
Groups map[string]*types.Group `gorm:"-"`
|
Groups map[string]*Group `gorm:"-"`
|
||||||
GroupsG []types.Group `json:"-" gorm:"foreignKey:AccountID;references:id"`
|
GroupsG []Group `json:"-" gorm:"foreignKey:AccountID;references:id"`
|
||||||
Policies []*Policy `gorm:"foreignKey:AccountID;references:id"`
|
Policies []*Policy `gorm:"foreignKey:AccountID;references:id"`
|
||||||
Routes map[route.ID]*route.Route `gorm:"-"`
|
Routes map[route.ID]*route.Route `gorm:"-"`
|
||||||
RoutesG []route.Route `json:"-" gorm:"foreignKey:AccountID;references:id"`
|
RoutesG []route.Route `json:"-" gorm:"foreignKey:AccountID;references:id"`
|
||||||
@ -213,7 +213,7 @@ func (a *Account) GetRoutesByPrefixOrDomains(prefix netip.Prefix, domains domain
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetGroup returns a group by ID if exists, nil otherwise
|
// GetGroup returns a group by ID if exists, nil otherwise
|
||||||
func (a *Account) GetGroup(groupID string) *types.Group {
|
func (a *Account) GetGroup(groupID string) *Group {
|
||||||
return a.Groups[groupID]
|
return a.Groups[groupID]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -608,7 +608,7 @@ func (a *Account) FindUser(userID string) (*User, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// FindGroupByName looks for a given group in the Account by name or returns error if the group wasn't found.
|
// FindGroupByName looks for a given group in the Account by name or returns error if the group wasn't found.
|
||||||
func (a *Account) FindGroupByName(groupName string) (*types.Group, error) {
|
func (a *Account) FindGroupByName(groupName string) (*Group, error) {
|
||||||
for _, group := range a.Groups {
|
for _, group := range a.Groups {
|
||||||
if group.Name == groupName {
|
if group.Name == groupName {
|
||||||
return group, nil
|
return group, nil
|
||||||
@ -702,7 +702,7 @@ func (a *Account) Copy() *Account {
|
|||||||
setupKeys[id] = key.Copy()
|
setupKeys[id] = key.Copy()
|
||||||
}
|
}
|
||||||
|
|
||||||
groups := map[string]*nbgroup.Group{}
|
groups := map[string]*Group{}
|
||||||
for id, group := range a.Groups {
|
for id, group := range a.Groups {
|
||||||
groups[id] = group.Copy()
|
groups[id] = group.Copy()
|
||||||
}
|
}
|
||||||
@ -773,7 +773,7 @@ func (a *Account) Copy() *Account {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Account) GetGroupAll() (*nbgroup.Group, error) {
|
func (a *Account) GetGroupAll() (*Group, error) {
|
||||||
for _, g := range a.Groups {
|
for _, g := range a.Groups {
|
||||||
if g.Name == "All" {
|
if g.Name == "All" {
|
||||||
return g, nil
|
return g, nil
|
||||||
@ -909,7 +909,7 @@ func (a *Account) connResourcesGenerator(ctx context.Context) (func(*PolicyRule,
|
|||||||
all, err := a.GetGroupAll()
|
all, err := a.GetGroupAll()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithContext(ctx).Errorf("failed to get group all: %v", err)
|
log.WithContext(ctx).Errorf("failed to get group all: %v", err)
|
||||||
all = &nbgroup.Group{}
|
all = &Group{}
|
||||||
}
|
}
|
||||||
|
|
||||||
return func(rule *PolicyRule, groupPeers []*nbpeer.Peer, direction int) {
|
return func(rule *PolicyRule, groupPeers []*nbpeer.Peer, direction int) {
|
||||||
|
Loading…
Reference in New Issue
Block a user