Browse Source

fixed minor client bug

0xdcarns 3 years ago
parent
commit
b1595d5ef4
4 changed files with 58 additions and 2 deletions
  1. 1 1
      netclient/main.go
  2. 6 0
      netclient/ncutils/netclientutils.go
  3. 48 0
      servercfg/serverconf.go
  4. 3 1
      serverctl/serverctl.go

+ 1 - 1
netclient/main.go

@@ -24,7 +24,7 @@ func main() {
 	app := cli.NewApp()
 	app.Name = "Netclient CLI"
 	app.Usage = "Netmaker's netclient agent and CLI. Used to perform interactions with Netmaker server and set local WireGuard config."
-	app.Version = "v0.8.4"
+	app.Version = "v0.8.5"
 
 	hostname, err := os.Hostname()
 	if err != nil {

+ 6 - 0
netclient/ncutils/netclientutils.go

@@ -397,6 +397,12 @@ func FileExists(f string) bool {
 	if os.IsNotExist(err) {
 		return false
 	}
+	if err != nil && strings.Contains(err.Error(), "not a directory") {
+		return false
+	}
+	if err != nil {
+		Log("error reading file: " + f + ", " + err.Error())
+	}
 	return !info.IsDir()
 }
 

+ 48 - 0
servercfg/serverconf.go

@@ -12,6 +12,7 @@ import (
 	"github.com/gravitl/netmaker/config"
 )
 
+// SetHost - sets the host ip
 func SetHost() error {
 	remoteip, err := GetPublicIP()
 	if err != nil {
@@ -20,6 +21,8 @@ func SetHost() error {
 	os.Setenv("SERVER_HOST", remoteip)
 	return nil
 }
+
+// GetServerConfig - gets the server config into memory from file or env
 func GetServerConfig() config.ServerConfig {
 	var cfg config.ServerConfig
 	cfg.APIConnString = GetAPIConnString()
@@ -76,6 +79,8 @@ func GetServerConfig() config.ServerConfig {
 
 	return cfg
 }
+
+// GetFrontendURL - gets the frontend url
 func GetFrontendURL() string {
 	var frontend = ""
 	if os.Getenv("FRONTEND_URL") != "" {
@@ -86,6 +91,7 @@ func GetFrontendURL() string {
 	return frontend
 }
 
+// GetAPIConnString - gets the api connections string
 func GetAPIConnString() string {
 	conn := ""
 	if os.Getenv("SERVER_API_CONN_STRING") != "" {
@@ -95,6 +101,8 @@ func GetAPIConnString() string {
 	}
 	return conn
 }
+
+// GetVersion - version of netmaker
 func GetVersion() string {
 	version := "0.8.5"
 	if config.Config.Server.Version != "" {
@@ -102,6 +110,8 @@ func GetVersion() string {
 	}
 	return version
 }
+
+// GetDB - gets the database type
 func GetDB() string {
 	database := "sqlite"
 	if os.Getenv("DATABASE") != "" {
@@ -111,6 +121,8 @@ func GetDB() string {
 	}
 	return database
 }
+
+// GetAPIHost - gets the api host
 func GetAPIHost() string {
 	serverhost := "127.0.0.1"
 	remoteip, _ := GetPublicIP()
@@ -127,6 +139,8 @@ func GetAPIHost() string {
 	}
 	return serverhost
 }
+
+// GetPodIP - get the pod's ip
 func GetPodIP() string {
 	podip := "127.0.0.1"
 	if os.Getenv("POD_IP") != "" {
@@ -135,6 +149,7 @@ func GetPodIP() string {
 	return podip
 }
 
+// GetAPIPort - gets the api port
 func GetAPIPort() string {
 	apiport := "8081"
 	if os.Getenv("API_PORT") != "" {
@@ -145,6 +160,7 @@ func GetAPIPort() string {
 	return apiport
 }
 
+// GetCheckinInterval - get check in interval for nodes
 func GetCheckinInterval() string {
 	seconds := "15"
 	if os.Getenv("CHECKIN_INTERVAL") != "" {
@@ -155,6 +171,7 @@ func GetCheckinInterval() string {
 	return seconds
 }
 
+// GetDefaultNodeLimit - get node limit if one is set
 func GetDefaultNodeLimit() int32 {
 	var limit int32
 	limit = 999999999
@@ -166,6 +183,8 @@ func GetDefaultNodeLimit() int32 {
 	}
 	return limit
 }
+
+// GetGRPCConnString - get grpc conn string
 func GetGRPCConnString() string {
 	conn := ""
 	if os.Getenv("SERVER_GRPC_CONN_STRING") != "" {
@@ -176,6 +195,7 @@ func GetGRPCConnString() string {
 	return conn
 }
 
+// GetCoreDNSAddr - gets the core dns address
 func GetCoreDNSAddr() string {
 	addr, _ := GetPublicIP()
 	if os.Getenv("COREDNS_ADDR") != "" {
@@ -186,6 +206,7 @@ func GetCoreDNSAddr() string {
 	return addr
 }
 
+// GetGRPCHost - get the grpc host url
 func GetGRPCHost() string {
 	serverhost := "127.0.0.1"
 	remoteip, _ := GetPublicIP()
@@ -202,6 +223,8 @@ func GetGRPCHost() string {
 	}
 	return serverhost
 }
+
+// GetGRPCPort - gets the grpc port
 func GetGRPCPort() string {
 	grpcport := "50051"
 	if os.Getenv("GRPC_PORT") != "" {
@@ -211,6 +234,8 @@ func GetGRPCPort() string {
 	}
 	return grpcport
 }
+
+// GetMasterKey - gets the configured master key of server
 func GetMasterKey() string {
 	key := "secretkey"
 	if os.Getenv("MASTER_KEY") != "" {
@@ -220,6 +245,8 @@ func GetMasterKey() string {
 	}
 	return key
 }
+
+// GetAllowedOrigin - get the allowed origin
 func GetAllowedOrigin() string {
 	allowedorigin := "*"
 	if os.Getenv("CORS_ALLOWED_ORIGIN") != "" {
@@ -229,6 +256,8 @@ func GetAllowedOrigin() string {
 	}
 	return allowedorigin
 }
+
+// IsRestBackend - checks if rest is on or off
 func IsRestBackend() bool {
 	isrest := true
 	if os.Getenv("REST_BACKEND") != "" {
@@ -242,6 +271,8 @@ func IsRestBackend() bool {
 	}
 	return isrest
 }
+
+// IsAgentBackend - checks if agent backed is on or off
 func IsAgentBackend() bool {
 	isagent := true
 	if os.Getenv("AGENT_BACKEND") != "" {
@@ -255,6 +286,8 @@ func IsAgentBackend() bool {
 	}
 	return isagent
 }
+
+// IsClientMode - checks if it should run in client mode
 func IsClientMode() string {
 	isclient := "on"
 	if os.Getenv("CLIENT_MODE") != "" {
@@ -274,6 +307,8 @@ func IsClientMode() string {
 	}
 	return isclient
 }
+
+// IsDNSMode - should it run with DNS
 func IsDNSMode() bool {
 	isdns := true
 	if os.Getenv("DNS_MODE") != "" {
@@ -288,6 +323,7 @@ func IsDNSMode() bool {
 	return isdns
 }
 
+// IsGRPCSSL - ssl grpc on or off
 func IsGRPCSSL() bool {
 	isssl := false
 	if os.Getenv("GRPC_SSL") != "" {
@@ -302,6 +338,7 @@ func IsGRPCSSL() bool {
 	return isssl
 }
 
+// DisableRemoteIPCheck - disable the remote ip check
 func DisableRemoteIPCheck() bool {
 	disabled := false
 	if os.Getenv("DISABLE_REMOTE_IP_CHECK") != "" {
@@ -315,6 +352,8 @@ func DisableRemoteIPCheck() bool {
 	}
 	return disabled
 }
+
+// DisableDefaultNet - disable default net
 func DisableDefaultNet() bool {
 	disabled := false
 	if os.Getenv("DISABLE_DEFAULT_NET") != "" {
@@ -328,6 +367,8 @@ func DisableDefaultNet() bool {
 	}
 	return disabled
 }
+
+// GetPublicIP - gets public ip
 func GetPublicIP() (string, error) {
 
 	endpoint := ""
@@ -354,6 +395,8 @@ func GetPublicIP() (string, error) {
 	}
 	return endpoint, err
 }
+
+// GetVerbose - get the verbosity of server
 func GetVerbose() int32 {
 	level, err := strconv.Atoi(os.Getenv("VERBOSITY"))
 	if err != nil || level < 0 {
@@ -365,6 +408,7 @@ func GetVerbose() int32 {
 	return int32(level)
 }
 
+// GetPlatform - get the system type of server
 func GetPlatform() string {
 	platform := "linux"
 	if os.Getenv("PLATFORM") != "" {
@@ -375,6 +419,7 @@ func GetPlatform() string {
 	return platform
 }
 
+// GetSQLConn - get the sql connection string
 func GetSQLConn() string {
 	sqlconn := "http://"
 	if os.Getenv("SQL_CONN") != "" {
@@ -385,6 +430,7 @@ func GetSQLConn() string {
 	return sqlconn
 }
 
+// IsSplitDNS - checks if split dns is on
 func IsSplitDNS() bool {
 	issplit := false
 	if os.Getenv("IS_SPLIT_DNS") == "yes" {
@@ -395,6 +441,7 @@ func IsSplitDNS() bool {
 	return issplit
 }
 
+// GetNodeID - gets the node id
 func GetNodeID() string {
 	var id string
 	id = getMacAddr()
@@ -406,6 +453,7 @@ func GetNodeID() string {
 	return id
 }
 
+// GetServerCheckinInterval - gets the server check-in time
 func GetServerCheckinInterval() int64 {
 	var t = int64(5)
 	var envt, _ = strconv.Atoi(os.Getenv("SERVER_CHECKIN_INTERVAL"))

+ 3 - 1
serverctl/serverctl.go

@@ -107,9 +107,11 @@ func HandleContainedClient() error {
 			err = logic.ServerCheckin(servercfg.GetNodeID(), serverNet.NetID)
 			if err != nil {
 				logic.Log("error occurred during server checkin: "+err.Error(), 1)
+			} else {
+				logic.Log("completed a checking peers of network "+serverNet.NetID, 3)
 			}
 		}
-		logic.Log("completed a checkin call", 3)
+		// logic.Log("completed a checkin call", 3)
 	}
 	return nil
 }