Add network routers in account object

Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
This commit is contained in:
bcmmbaga 2024-12-10 14:59:55 +01:00
parent f9be8f829e
commit 21586acc16
No known key found for this signature in database
GPG Key ID: 511EED5C928AD547
2 changed files with 20 additions and 1 deletions

View File

@ -278,7 +278,8 @@ type Account struct {
// Settings is a dictionary of Account settings
Settings *Settings `gorm:"embedded;embeddedPrefix:settings_"`
Networks []*networks.Network `gorm:"foreignKey:AccountID;references:id"`
Networks []*networks.Network `gorm:"foreignKey:AccountID;references:id"`
NetworkRouters []*networks.NetworkRouter `gorm:"foreignKey:AccountID;references:id"`
}
// Subclass used in gorm to only load settings and not whole account
@ -887,6 +888,11 @@ func (a *Account) Copy() *Account {
nets = append(nets, network.Copy())
}
networkRouters := []*networks.NetworkRouter{}
for _, router := range a.NetworkRouters {
networkRouters = append(networkRouters, router.Copy())
}
return &Account{
Id: a.Id,
CreatedBy: a.CreatedBy,
@ -906,6 +912,7 @@ func (a *Account) Copy() *Account {
PostureChecks: postureChecks,
Settings: settings,
Networks: nets,
NetworkRouters: networkRouters,
}
}

View File

@ -31,3 +31,15 @@ func NewNetworkRouter(accountID string, networkID string, peer string, peerGroup
Metric: metric,
}, nil
}
func (n *NetworkRouter) Copy() *NetworkRouter {
return &NetworkRouter{
ID: n.ID,
NetworkID: n.NetworkID,
AccountID: n.AccountID,
Peer: n.Peer,
PeerGroups: n.PeerGroups,
Masquerade: n.Masquerade,
Metric: n.Metric,
}
}