mirror of
https://github.com/netbirdio/netbird.git
synced 2025-02-12 08:19:30 +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"
|
cacheStore "github.com/eko/gocache/v3/store"
|
||||||
"github.com/hashicorp/go-multierror"
|
"github.com/hashicorp/go-multierror"
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
|
"github.com/netbirdio/netbird/management/server/networks"
|
||||||
gocache "github.com/patrickmn/go-cache"
|
gocache "github.com/patrickmn/go-cache"
|
||||||
"github.com/rs/xid"
|
"github.com/rs/xid"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
@ -276,6 +277,8 @@ type Account struct {
|
|||||||
PostureChecks []*posture.Checks `gorm:"foreignKey:AccountID;references:id"`
|
PostureChecks []*posture.Checks `gorm:"foreignKey:AccountID;references:id"`
|
||||||
// Settings is a dictionary of Account settings
|
// Settings is a dictionary of Account settings
|
||||||
Settings *Settings `gorm:"embedded;embeddedPrefix: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
|
// 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())
|
postureChecks = append(postureChecks, postureCheck.Copy())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nets := []*networks.Network{}
|
||||||
|
for _, network := range a.Networks {
|
||||||
|
nets = append(nets, network.Copy())
|
||||||
|
}
|
||||||
|
|
||||||
return &Account{
|
return &Account{
|
||||||
Id: a.Id,
|
Id: a.Id,
|
||||||
CreatedBy: a.CreatedBy,
|
CreatedBy: a.CreatedBy,
|
||||||
@ -897,6 +905,7 @@ func (a *Account) Copy() *Account {
|
|||||||
DNSSettings: dnsSettings,
|
DNSSettings: dnsSettings,
|
||||||
PostureChecks: postureChecks,
|
PostureChecks: postureChecks,
|
||||||
Settings: settings,
|
Settings: settings,
|
||||||
|
Networks: nets,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/golang-jwt/jwt"
|
"github.com/golang-jwt/jwt"
|
||||||
|
"github.com/netbirdio/netbird/management/server/networks"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@ -1778,6 +1779,11 @@ func TestAccount_Copy(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
Settings: &Settings{},
|
Settings: &Settings{},
|
||||||
|
Networks: []*networks.Network{
|
||||||
|
{
|
||||||
|
ID: "network1",
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
err := hasNilField(account)
|
err := hasNilField(account)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -17,3 +17,13 @@ func NewNetwork(accountId, name, description string) *Network {
|
|||||||
Description: description,
|
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