mirror of
https://github.com/gravitl/netmaker.git
synced 2025-09-29 00:14:35 +08:00
addressed majority of static checks
This commit is contained in:
parent
a710ac3570
commit
706bba0593
8 changed files with 36 additions and 73 deletions
|
@ -117,6 +117,7 @@ func TestGetCustomDNS(t *testing.T) {
|
|||
t.Run("EntryExist", func(t *testing.T) {
|
||||
entry := models.DNSEntry{"10.0.0.3", "", "custom1", "skynet"}
|
||||
_, err := logic.CreateDNS(entry)
|
||||
assert.Nil(t, err)
|
||||
dns, err := logic.GetCustomDNS("skynet")
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 1, len(dns))
|
||||
|
|
|
@ -14,10 +14,6 @@ import (
|
|||
"github.com/gravitl/netmaker/mq"
|
||||
)
|
||||
|
||||
type hostNetworksUpdatePayload struct {
|
||||
Networks []string `json:"networks"`
|
||||
}
|
||||
|
||||
func hostHandlers(r *mux.Router) {
|
||||
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)
|
||||
|
|
|
@ -529,21 +529,21 @@ func GetPeerUpdate(node *models.Node, host *models.Host) (models.PeerUpdate, err
|
|||
return peerUpdate, nil
|
||||
}
|
||||
|
||||
func getRelayAllowedIPs(node, peer *models.Node) []net.IPNet {
|
||||
var allowedips []net.IPNet
|
||||
var allowedip net.IPNet
|
||||
for _, addr := range peer.RelayAddrs {
|
||||
if node.Address.IP.String() == addr {
|
||||
continue
|
||||
}
|
||||
if node.Address6.IP.String() == addr {
|
||||
continue
|
||||
}
|
||||
allowedip.IP = net.ParseIP(addr)
|
||||
allowedips = append(allowedips, allowedip)
|
||||
}
|
||||
return allowedips
|
||||
}
|
||||
// func getRelayAllowedIPs(node, peer *models.Node) []net.IPNet {
|
||||
// var allowedips []net.IPNet
|
||||
// var allowedip net.IPNet
|
||||
// for _, addr := range peer.RelayAddrs {
|
||||
// if node.Address.IP.String() == addr {
|
||||
// continue
|
||||
// }
|
||||
// if node.Address6.IP.String() == addr {
|
||||
// continue
|
||||
// }
|
||||
// allowedip.IP = net.ParseIP(addr)
|
||||
// allowedips = append(allowedips, allowedip)
|
||||
// }
|
||||
// return allowedips
|
||||
// }
|
||||
|
||||
// GetPeerUpdateLegacy - gets a wireguard peer config for each peer of a node
|
||||
func GetPeerUpdateLegacy(node *models.Node) (models.PeerUpdate, error) {
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package logic
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/gravitl/netmaker/models"
|
||||
)
|
||||
|
@ -33,9 +31,3 @@ func EnterpriseCheck() {
|
|||
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
|
||||
)
|
||||
|
||||
// constant for database key for storing server ids
|
||||
const server_id_key = "nm-server-id"
|
||||
|
||||
type serverData struct {
|
||||
PrivateKey string `json:"privatekey,omitempty" bson:"privatekey,omitempty"`
|
||||
}
|
||||
|
|
|
@ -15,8 +15,6 @@ import (
|
|||
|
||||
"github.com/c-robinson/iplib"
|
||||
"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
|
||||
|
@ -113,26 +111,6 @@ func RandomString(length int) string {
|
|||
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
|
||||
func StringSliceContains(slice []string, item string) bool {
|
||||
for _, s := range slice {
|
||||
|
@ -143,8 +121,6 @@ func StringSliceContains(slice []string, item string) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
// == private ==
|
||||
|
||||
// NormalCIDR - returns the first address of CIDR
|
||||
func NormalizeCIDR(address string) (string, error) {
|
||||
ip, IPNet, err := net.ParseCIDR(address)
|
||||
|
@ -161,23 +137,6 @@ func NormalizeCIDR(address string) (string, error) {
|
|||
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`.
|
||||
func StringDifference(a, b []string) []string {
|
||||
mb := make(map[string]struct{}, len(b))
|
||||
|
@ -206,3 +165,22 @@ func CheckIfFileExists(filePath string) bool {
|
|||
func RemoveStringSlice(slice []string, i int) []string {
|
||||
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 {
|
||||
if !newMetrics.Connectivity[node.ID.String()].Connected &&
|
||||
len(newMetrics.Connectivity[node.ID.String()].NodeName) > 0 &&
|
||||
node.Connected == true &&
|
||||
node.Connected &&
|
||||
len(node.FailoverNode) > 0 &&
|
||||
!node.Failover {
|
||||
newMetrics.FailoverPeers[node.ID.String()] = node.FailoverNode.String()
|
||||
|
|
|
@ -25,7 +25,6 @@ TODO:-
|
|||
-> start remote conn after endpoint is updated
|
||||
-->
|
||||
*/
|
||||
var sent bool
|
||||
|
||||
type ProxyAction string
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue