From 21586acc1647c79fb23b01a69ace05ce51e55cdc Mon Sep 17 00:00:00 2001 From: bcmmbaga Date: Tue, 10 Dec 2024 14:59:55 +0100 Subject: [PATCH] Add network routers in account object Signed-off-by: bcmmbaga --- management/server/account.go | 9 ++++++++- management/server/networks/network_router.go | 12 ++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/management/server/account.go b/management/server/account.go index e89609e57..bd0b2f049 100644 --- a/management/server/account.go +++ b/management/server/account.go @@ -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, } } diff --git a/management/server/networks/network_router.go b/management/server/networks/network_router.go index cf7859fa8..cadabf3cc 100644 --- a/management/server/networks/network_router.go +++ b/management/server/networks/network_router.go @@ -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, + } +}