mirror of
https://github.com/netbirdio/netbird.git
synced 2025-01-31 10:31:58 +01:00
Add account networks
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
This commit is contained in:
parent
21eca7e1d1
commit
6a1eda1caa
@ -21,6 +21,7 @@ import (
|
||||
cacheStore "github.com/eko/gocache/v3/store"
|
||||
"github.com/hashicorp/go-multierror"
|
||||
"github.com/miekg/dns"
|
||||
"github.com/netbirdio/netbird/management/server/networks"
|
||||
gocache "github.com/patrickmn/go-cache"
|
||||
"github.com/rs/xid"
|
||||
log "github.com/sirupsen/logrus"
|
||||
@ -276,6 +277,8 @@ type Account struct {
|
||||
PostureChecks []*posture.Checks `gorm:"foreignKey:AccountID;references:id"`
|
||||
// Settings is a dictionary of Account settings
|
||||
Settings *Settings `gorm:"embedded;embeddedPrefix:settings_"`
|
||||
|
||||
Networks []*networks.Network `gorm:"foreignKey:AccountID;references:id"`
|
||||
}
|
||||
|
||||
// Subclass used in gorm to only load settings and not whole account
|
||||
@ -879,6 +882,11 @@ func (a *Account) Copy() *Account {
|
||||
postureChecks = append(postureChecks, postureCheck.Copy())
|
||||
}
|
||||
|
||||
nets := []*networks.Network{}
|
||||
for _, network := range a.Networks {
|
||||
nets = append(nets, network.Copy())
|
||||
}
|
||||
|
||||
return &Account{
|
||||
Id: a.Id,
|
||||
CreatedBy: a.CreatedBy,
|
||||
@ -897,6 +905,7 @@ func (a *Account) Copy() *Account {
|
||||
DNSSettings: dnsSettings,
|
||||
PostureChecks: postureChecks,
|
||||
Settings: settings,
|
||||
Networks: nets,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/golang-jwt/jwt"
|
||||
"github.com/netbirdio/netbird/management/server/networks"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
@ -1778,6 +1779,11 @@ func TestAccount_Copy(t *testing.T) {
|
||||
},
|
||||
},
|
||||
Settings: &Settings{},
|
||||
Networks: []*networks.Network{
|
||||
{
|
||||
ID: "network1",
|
||||
},
|
||||
},
|
||||
}
|
||||
err := hasNilField(account)
|
||||
if err != nil {
|
||||
|
@ -17,3 +17,13 @@ func NewNetwork(accountId, name, description string) *Network {
|
||||
Description: description,
|
||||
}
|
||||
}
|
||||
|
||||
// Copy returns a copy of a posture checks.
|
||||
func (n *Network) Copy() *Network {
|
||||
return &Network{
|
||||
ID: n.ID,
|
||||
AccountID: n.AccountID,
|
||||
Name: n.Name,
|
||||
Description: n.Description,
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user