mirror of
https://github.com/netbirdio/management-refactor.git
synced 2026-05-22 17:12:59 -07:00
56 lines
1.2 KiB
Go
56 lines
1.2 KiB
Go
package networks
|
|
|
|
import (
|
|
"github.com/netbirdio/netbird/management/server/http/api"
|
|
"github.com/rs/xid"
|
|
)
|
|
|
|
type Network struct {
|
|
ID string
|
|
AccountID string
|
|
Name string
|
|
Description string
|
|
}
|
|
|
|
func NewNetwork(accountId, name, description string) *Network {
|
|
return &Network{
|
|
ID: xid.New().String(),
|
|
AccountID: accountId,
|
|
Name: name,
|
|
Description: description,
|
|
}
|
|
}
|
|
|
|
func (n *Network) ToAPIResponse(routerIDs []string, resourceIDs []string, routingPeersCount int, policyIDs []string) *api.Network {
|
|
return &api.Network{
|
|
Id: n.ID,
|
|
Name: n.Name,
|
|
Description: &n.Description,
|
|
Routers: routerIDs,
|
|
Resources: resourceIDs,
|
|
RoutingPeersCount: routingPeersCount,
|
|
Policies: policyIDs,
|
|
}
|
|
}
|
|
|
|
func (n *Network) FromAPIRequest(req *api.NetworkRequest) {
|
|
n.Name = req.Name
|
|
if req.Description != nil {
|
|
n.Description = *req.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,
|
|
}
|
|
}
|
|
|
|
func (n *Network) EventMeta() map[string]any {
|
|
return map[string]any{"name": n.Name}
|
|
}
|