mirror of
https://github.com/gravitl/netmaker.git
synced 2026-01-15 15:24:05 +08:00
* feat(go): define flow events; * feat(go): improve structure; * feat(go): improve structure; * feat(go): remove old flow definitions; * feat(sql): add clickhouse init scripts; * feat(sql): add protobuf spec; * fix(sql): store ip as string; * feat(go): move proto def to grpc dir; * feat(go): use node instead of host as type; optimize protobuf defs; * feat(go): add clickhouse db support; add endpoint to query flows; * fix(go): fix clickhouse config; * fix(go): use error response structure to report error; * feat(go): pass flow logging status to netclient; * feat(go): add peer ip identity map to host peer info; * feat(go): remove prefix from participant obj fields; * feat(go): add flow logs enabled field to host; * feat(go): add filtering to get flow api; * feat(go): fix record struct; * feat(go): add exporter url to server config; * feat(go): add exporter url to server config; * feat(go): enable flow logs by default; * feat(go): update nm-quick.sh; * feat(go): update nm-quick.sh; * feat(go): update nm-quick.sh; * feat(go): update nm-quick.sh; * feat(go): add db initialization logic; * feat(go): filter by network id; * fix(go): connection issue; * fix(go): connection issue; * fix(go): golang builder version; * feat(go): add server settings for flow logs; * feat(go): initialize clickhouse in pro; check for retention; * feat(go): add exporter feature flags; * feat(go): add grpc behind caddy; * feat(go): expose ports correctly; * fix(go): grpc caddyfile config; * fix(go): publish exporter feature flags on license validation; * fix(go): set server name for netmaker exporter; * fix(go): set server name for netmaker exporter; * fix(go): check for nil cancel func; * fix(go): add flow logs field to api host; * fix(go): add flow logs field to api host; * fix(go): remove port from grpc setting; * chore(go): tabs; * feat(go): introduce egress range participant type;. * feat(go): rename egress range to egress route for uniform language; * feat(go): rename egress range to egress route for uniform language; * feat: add peer addr identity map to host peer update; * feat: add address identity map to host peer update; * feat: add address identity map to host peer update; * feat: set correct from and to args; * feat: add support for filtering by node; * feat: use corresponding base image; * feat: update dockerfile base image version; * fix: disable flow logs for all host when global settings are changed;
146 lines
5.2 KiB
Go
146 lines
5.2 KiB
Go
package models
|
|
|
|
import (
|
|
"net"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
// ApiHost - the host struct for API usage
|
|
type ApiHost struct {
|
|
ID string `json:"id"`
|
|
Verbosity int `json:"verbosity"`
|
|
FirewallInUse string `json:"firewallinuse"`
|
|
Version string `json:"version"`
|
|
Name string `json:"name"`
|
|
OS string `json:"os"`
|
|
OSFamily string `json:"os_family" yaml:"os_family"`
|
|
OSVersion string `json:"os_version" yaml:"os_version"`
|
|
KernelVersion string `json:"kernel_version" yaml:"kernel_version"`
|
|
Debug bool `json:"debug"`
|
|
IsStaticPort bool `json:"isstaticport"`
|
|
IsStatic bool `json:"isstatic"`
|
|
ListenPort int `json:"listenport"`
|
|
WgPublicListenPort int `json:"wg_public_listen_port" yaml:"wg_public_listen_port"`
|
|
MTU int `json:"mtu" yaml:"mtu"`
|
|
Interfaces []ApiIface `json:"interfaces" yaml:"interfaces"`
|
|
DefaultInterface string `json:"defaultinterface" yaml:"defautlinterface"`
|
|
EndpointIP string `json:"endpointip" yaml:"endpointip"`
|
|
EndpointIPv6 string `json:"endpointipv6" yaml:"endpointipv6"`
|
|
PublicKey string `json:"publickey"`
|
|
MacAddress string `json:"macaddress"`
|
|
Nodes []string `json:"nodes"`
|
|
IsDefault bool `json:"isdefault" yaml:"isdefault"`
|
|
NatType string `json:"nat_type" yaml:"nat_type"`
|
|
PersistentKeepalive int `json:"persistentkeepalive" yaml:"persistentkeepalive"`
|
|
AutoUpdate bool `json:"autoupdate" yaml:"autoupdate"`
|
|
DNS string `json:"dns" yaml:"dns"`
|
|
EnableFlowLogs bool `json:"enable_flow_logs" yaml:"enable_flow_logs"`
|
|
Location string `json:"location"`
|
|
CountryCode string `json:"country_code"`
|
|
}
|
|
|
|
// ApiIface - the interface struct for API usage
|
|
// The original Iface struct contains a net.Address, which does not get marshalled correctly
|
|
type ApiIface struct {
|
|
Name string `json:"name"`
|
|
AddressString string `json:"addressString"`
|
|
}
|
|
|
|
// Host.ConvertNMHostToAPI - converts a Netmaker host to an API editable host
|
|
func (h *Host) ConvertNMHostToAPI() *ApiHost {
|
|
a := ApiHost{}
|
|
a.Debug = h.Debug
|
|
a.EndpointIP = h.EndpointIP.String()
|
|
if a.EndpointIP == "<nil>" {
|
|
a.EndpointIP = ""
|
|
}
|
|
a.EndpointIPv6 = h.EndpointIPv6.String()
|
|
if a.EndpointIPv6 == "<nil>" {
|
|
a.EndpointIPv6 = ""
|
|
}
|
|
a.FirewallInUse = h.FirewallInUse
|
|
a.ID = h.ID.String()
|
|
a.Interfaces = make([]ApiIface, len(h.Interfaces))
|
|
for i := range a.Interfaces {
|
|
a.Interfaces[i] = ApiIface{
|
|
Name: h.Interfaces[i].Name,
|
|
AddressString: h.Interfaces[i].Address.String(),
|
|
}
|
|
}
|
|
a.DefaultInterface = h.DefaultInterface
|
|
a.IsStaticPort = h.IsStaticPort
|
|
a.IsStatic = h.IsStatic
|
|
a.ListenPort = h.ListenPort
|
|
a.MTU = h.MTU
|
|
a.MacAddress = h.MacAddress.String()
|
|
a.Name = h.Name
|
|
a.OS = h.OS
|
|
a.OSFamily = h.OSFamily
|
|
a.KernelVersion = h.KernelVersion
|
|
a.Nodes = h.Nodes
|
|
a.WgPublicListenPort = h.WgPublicListenPort
|
|
a.PublicKey = h.PublicKey.String()
|
|
a.Verbosity = h.Verbosity
|
|
a.Version = h.Version
|
|
a.IsDefault = h.IsDefault
|
|
a.NatType = h.NatType
|
|
a.PersistentKeepalive = int(h.PersistentKeepalive.Seconds())
|
|
a.AutoUpdate = h.AutoUpdate
|
|
a.DNS = h.DNS
|
|
a.EnableFlowLogs = h.EnableFlowLogs
|
|
a.Location = h.Location
|
|
a.CountryCode = h.CountryCode
|
|
return &a
|
|
}
|
|
|
|
// APIHost.ConvertAPIHostToNMHost - convert's a given apihost struct to
|
|
// a Host struct
|
|
func (a *ApiHost) ConvertAPIHostToNMHost(currentHost *Host) *Host {
|
|
h := Host{}
|
|
h.ID = currentHost.ID
|
|
h.HostPass = currentHost.HostPass
|
|
h.DaemonInstalled = currentHost.DaemonInstalled
|
|
if len(a.EndpointIP) == 0 || strings.Contains(a.EndpointIP, "nil") {
|
|
h.EndpointIP = currentHost.EndpointIP
|
|
} else {
|
|
h.EndpointIP = net.ParseIP(a.EndpointIP)
|
|
}
|
|
if len(a.EndpointIPv6) == 0 || strings.Contains(a.EndpointIPv6, "nil") {
|
|
h.EndpointIPv6 = currentHost.EndpointIPv6
|
|
} else {
|
|
h.EndpointIPv6 = net.ParseIP(a.EndpointIPv6)
|
|
}
|
|
h.Debug = a.Debug
|
|
h.FirewallInUse = a.FirewallInUse
|
|
h.IPForwarding = currentHost.IPForwarding
|
|
h.Interface = currentHost.Interface
|
|
h.Interfaces = currentHost.Interfaces
|
|
h.DefaultInterface = currentHost.DefaultInterface
|
|
h.IsDocker = currentHost.IsDocker
|
|
h.IsK8S = currentHost.IsK8S
|
|
h.IsStaticPort = a.IsStaticPort
|
|
h.IsStatic = a.IsStatic
|
|
h.ListenPort = a.ListenPort
|
|
h.MTU = a.MTU
|
|
h.MacAddress = currentHost.MacAddress
|
|
h.PublicKey = currentHost.PublicKey
|
|
h.Name = a.Name
|
|
h.Version = currentHost.Version
|
|
h.Verbosity = a.Verbosity
|
|
h.Nodes = currentHost.Nodes
|
|
h.TrafficKeyPublic = currentHost.TrafficKeyPublic
|
|
h.OS = currentHost.OS
|
|
h.OSFamily = currentHost.OSFamily
|
|
h.KernelVersion = currentHost.KernelVersion
|
|
h.IsDefault = a.IsDefault
|
|
h.NatType = currentHost.NatType
|
|
h.TurnEndpoint = currentHost.TurnEndpoint
|
|
h.PersistentKeepalive = time.Duration(a.PersistentKeepalive) * time.Second
|
|
h.AutoUpdate = a.AutoUpdate
|
|
h.DNS = strings.ToLower(a.DNS)
|
|
h.EnableFlowLogs = a.EnableFlowLogs
|
|
h.Location = currentHost.Location
|
|
h.CountryCode = currentHost.CountryCode
|
|
return &h
|
|
}
|