Add account networks

Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
This commit is contained in:
bcmmbaga 2024-12-10 11:20:48 +01:00
parent 21eca7e1d1
commit 6a1eda1caa
No known key found for this signature in database
GPG Key ID: 511EED5C928AD547
3 changed files with 25 additions and 0 deletions

View File

@ -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,
}
}

View File

@ -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 {

View File

@ -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,
}
}