mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-06 01:07:41 +08:00
addressed majority of static checks
This commit is contained in:
@@ -117,6 +117,7 @@ func TestGetCustomDNS(t *testing.T) {
|
|||||||
t.Run("EntryExist", func(t *testing.T) {
|
t.Run("EntryExist", func(t *testing.T) {
|
||||||
entry := models.DNSEntry{"10.0.0.3", "", "custom1", "skynet"}
|
entry := models.DNSEntry{"10.0.0.3", "", "custom1", "skynet"}
|
||||||
_, err := logic.CreateDNS(entry)
|
_, err := logic.CreateDNS(entry)
|
||||||
|
assert.Nil(t, err)
|
||||||
dns, err := logic.GetCustomDNS("skynet")
|
dns, err := logic.GetCustomDNS("skynet")
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, 1, len(dns))
|
assert.Equal(t, 1, len(dns))
|
||||||
|
@@ -14,10 +14,6 @@ import (
|
|||||||
"github.com/gravitl/netmaker/mq"
|
"github.com/gravitl/netmaker/mq"
|
||||||
)
|
)
|
||||||
|
|
||||||
type hostNetworksUpdatePayload struct {
|
|
||||||
Networks []string `json:"networks"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func hostHandlers(r *mux.Router) {
|
func hostHandlers(r *mux.Router) {
|
||||||
r.HandleFunc("/api/hosts", logic.SecurityCheck(true, http.HandlerFunc(getHosts))).Methods(http.MethodGet)
|
r.HandleFunc("/api/hosts", logic.SecurityCheck(true, http.HandlerFunc(getHosts))).Methods(http.MethodGet)
|
||||||
r.HandleFunc("/api/hosts/{hostid}", logic.SecurityCheck(true, http.HandlerFunc(updateHost))).Methods(http.MethodPut)
|
r.HandleFunc("/api/hosts/{hostid}", logic.SecurityCheck(true, http.HandlerFunc(updateHost))).Methods(http.MethodPut)
|
||||||
|
@@ -529,21 +529,21 @@ func GetPeerUpdate(node *models.Node, host *models.Host) (models.PeerUpdate, err
|
|||||||
return peerUpdate, nil
|
return peerUpdate, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getRelayAllowedIPs(node, peer *models.Node) []net.IPNet {
|
// func getRelayAllowedIPs(node, peer *models.Node) []net.IPNet {
|
||||||
var allowedips []net.IPNet
|
// var allowedips []net.IPNet
|
||||||
var allowedip net.IPNet
|
// var allowedip net.IPNet
|
||||||
for _, addr := range peer.RelayAddrs {
|
// for _, addr := range peer.RelayAddrs {
|
||||||
if node.Address.IP.String() == addr {
|
// if node.Address.IP.String() == addr {
|
||||||
continue
|
// continue
|
||||||
}
|
// }
|
||||||
if node.Address6.IP.String() == addr {
|
// if node.Address6.IP.String() == addr {
|
||||||
continue
|
// continue
|
||||||
}
|
// }
|
||||||
allowedip.IP = net.ParseIP(addr)
|
// allowedip.IP = net.ParseIP(addr)
|
||||||
allowedips = append(allowedips, allowedip)
|
// allowedips = append(allowedips, allowedip)
|
||||||
}
|
// }
|
||||||
return allowedips
|
// return allowedips
|
||||||
}
|
// }
|
||||||
|
|
||||||
// GetPeerUpdateLegacy - gets a wireguard peer config for each peer of a node
|
// GetPeerUpdateLegacy - gets a wireguard peer config for each peer of a node
|
||||||
func GetPeerUpdateLegacy(node *models.Node) (models.PeerUpdate, error) {
|
func GetPeerUpdateLegacy(node *models.Node) (models.PeerUpdate, error) {
|
||||||
|
@@ -1,8 +1,6 @@
|
|||||||
package logic
|
package logic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/gravitl/netmaker/models"
|
"github.com/gravitl/netmaker/models"
|
||||||
)
|
)
|
||||||
@@ -33,9 +31,3 @@ func EnterpriseCheck() {
|
|||||||
check()
|
check()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// == Private ==
|
|
||||||
|
|
||||||
func isDeleteError(err error) bool {
|
|
||||||
return err != nil && strings.Contains(err.Error(), models.NODE_DELETE)
|
|
||||||
}
|
|
||||||
|
@@ -19,9 +19,6 @@ var (
|
|||||||
Free_Tier = false
|
Free_Tier = false
|
||||||
)
|
)
|
||||||
|
|
||||||
// constant for database key for storing server ids
|
|
||||||
const server_id_key = "nm-server-id"
|
|
||||||
|
|
||||||
type serverData struct {
|
type serverData struct {
|
||||||
PrivateKey string `json:"privatekey,omitempty" bson:"privatekey,omitempty"`
|
PrivateKey string `json:"privatekey,omitempty" bson:"privatekey,omitempty"`
|
||||||
}
|
}
|
||||||
|
@@ -15,8 +15,6 @@ import (
|
|||||||
|
|
||||||
"github.com/c-robinson/iplib"
|
"github.com/c-robinson/iplib"
|
||||||
"github.com/gravitl/netmaker/database"
|
"github.com/gravitl/netmaker/database"
|
||||||
"github.com/gravitl/netmaker/logger"
|
|
||||||
"github.com/gravitl/netmaker/netclient/ncutils"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// IsBase64 - checks if a string is in base64 format
|
// IsBase64 - checks if a string is in base64 format
|
||||||
@@ -113,26 +111,6 @@ func RandomString(length int) string {
|
|||||||
return string(b)
|
return string(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
// == Private Methods ==
|
|
||||||
|
|
||||||
func setIPForwardingLinux() error {
|
|
||||||
out, err := ncutils.RunCmd("sysctl net.ipv4.ip_forward", true)
|
|
||||||
if err != nil {
|
|
||||||
logger.Log(0, "WARNING: Error encountered setting ip forwarding. This can break functionality.")
|
|
||||||
return err
|
|
||||||
} else {
|
|
||||||
s := strings.Fields(string(out))
|
|
||||||
if s[2] != "1" {
|
|
||||||
_, err = ncutils.RunCmd("sysctl -w net.ipv4.ip_forward=1", true)
|
|
||||||
if err != nil {
|
|
||||||
logger.Log(0, "WARNING: Error encountered setting ip forwarding. You may want to investigate this.")
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// StringSliceContains - sees if a string slice contains a string element
|
// StringSliceContains - sees if a string slice contains a string element
|
||||||
func StringSliceContains(slice []string, item string) bool {
|
func StringSliceContains(slice []string, item string) bool {
|
||||||
for _, s := range slice {
|
for _, s := range slice {
|
||||||
@@ -143,8 +121,6 @@ func StringSliceContains(slice []string, item string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// == private ==
|
|
||||||
|
|
||||||
// NormalCIDR - returns the first address of CIDR
|
// NormalCIDR - returns the first address of CIDR
|
||||||
func NormalizeCIDR(address string) (string, error) {
|
func NormalizeCIDR(address string) (string, error) {
|
||||||
ip, IPNet, err := net.ParseCIDR(address)
|
ip, IPNet, err := net.ParseCIDR(address)
|
||||||
@@ -161,23 +137,6 @@ func NormalizeCIDR(address string) (string, error) {
|
|||||||
return IPNet.String(), nil
|
return IPNet.String(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getNetworkProtocols(cidrs []string) (bool, bool) {
|
|
||||||
ipv4 := false
|
|
||||||
ipv6 := false
|
|
||||||
for _, cidr := range cidrs {
|
|
||||||
ip, _, err := net.ParseCIDR(cidr)
|
|
||||||
if err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if ip.To4() == nil {
|
|
||||||
ipv6 = true
|
|
||||||
} else {
|
|
||||||
ipv4 = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ipv4, ipv6
|
|
||||||
}
|
|
||||||
|
|
||||||
// StringDifference - returns the elements in `a` that aren't in `b`.
|
// StringDifference - returns the elements in `a` that aren't in `b`.
|
||||||
func StringDifference(a, b []string) []string {
|
func StringDifference(a, b []string) []string {
|
||||||
mb := make(map[string]struct{}, len(b))
|
mb := make(map[string]struct{}, len(b))
|
||||||
@@ -206,3 +165,22 @@ func CheckIfFileExists(filePath string) bool {
|
|||||||
func RemoveStringSlice(slice []string, i int) []string {
|
func RemoveStringSlice(slice []string, i int) []string {
|
||||||
return append(slice[:i], slice[i+1:]...)
|
return append(slice[:i], slice[i+1:]...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// == private ==
|
||||||
|
|
||||||
|
func getNetworkProtocols(cidrs []string) (bool, bool) {
|
||||||
|
ipv4 := false
|
||||||
|
ipv6 := false
|
||||||
|
for _, cidr := range cidrs {
|
||||||
|
ip, _, err := net.ParseCIDR(cidr)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if ip.To4() == nil {
|
||||||
|
ipv6 = true
|
||||||
|
} else {
|
||||||
|
ipv4 = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ipv4, ipv6
|
||||||
|
}
|
||||||
|
@@ -376,7 +376,7 @@ func updateNodeMetrics(currentNode *models.Node, newMetrics *models.Metrics) boo
|
|||||||
for _, node := range nodes {
|
for _, node := range nodes {
|
||||||
if !newMetrics.Connectivity[node.ID.String()].Connected &&
|
if !newMetrics.Connectivity[node.ID.String()].Connected &&
|
||||||
len(newMetrics.Connectivity[node.ID.String()].NodeName) > 0 &&
|
len(newMetrics.Connectivity[node.ID.String()].NodeName) > 0 &&
|
||||||
node.Connected == true &&
|
node.Connected &&
|
||||||
len(node.FailoverNode) > 0 &&
|
len(node.FailoverNode) > 0 &&
|
||||||
!node.Failover {
|
!node.Failover {
|
||||||
newMetrics.FailoverPeers[node.ID.String()] = node.FailoverNode.String()
|
newMetrics.FailoverPeers[node.ID.String()] = node.FailoverNode.String()
|
||||||
|
@@ -25,7 +25,6 @@ TODO:-
|
|||||||
-> start remote conn after endpoint is updated
|
-> start remote conn after endpoint is updated
|
||||||
-->
|
-->
|
||||||
*/
|
*/
|
||||||
var sent bool
|
|
||||||
|
|
||||||
type ProxyAction string
|
type ProxyAction string
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user