|
@@ -13,6 +13,9 @@ import (
|
|
|
"github.com/gravitl/netmaker/models"
|
|
|
)
|
|
|
|
|
|
+// EmqxBrokerType denotes the broker type for EMQX MQTT
|
|
|
+const EmqxBrokerType = "emqx"
|
|
|
+
|
|
|
var (
|
|
|
Version = "dev"
|
|
|
Is_EE = false
|
|
@@ -35,7 +38,6 @@ func GetServerConfig() config.ServerConfig {
|
|
|
cfg.CoreDNSAddr = GetCoreDNSAddr()
|
|
|
cfg.APIHost = GetAPIHost()
|
|
|
cfg.APIPort = GetAPIPort()
|
|
|
- cfg.MQPort = GetMQPort()
|
|
|
cfg.MasterKey = "(hidden)"
|
|
|
cfg.DNSKey = "(hidden)"
|
|
|
cfg.AllowedOrigin = GetAllowedOrigin()
|
|
@@ -43,6 +45,8 @@ func GetServerConfig() config.ServerConfig {
|
|
|
cfg.NodeID = GetNodeID()
|
|
|
cfg.StunHost = GetStunAddr()
|
|
|
cfg.StunPort = GetStunPort()
|
|
|
+ cfg.BrokerType = GetBrokerType()
|
|
|
+ cfg.EmqxRestEndpoint = GetEmqxRestEndpoint()
|
|
|
if IsRestBackend() {
|
|
|
cfg.RestBackend = "on"
|
|
|
}
|
|
@@ -83,14 +87,13 @@ func GetServerConfig() config.ServerConfig {
|
|
|
func GetServerInfo() models.ServerConfig {
|
|
|
var cfg models.ServerConfig
|
|
|
cfg.Server = GetServer()
|
|
|
- cfg.Broker = GetBroker()
|
|
|
cfg.MQUserName = GetMqUserName()
|
|
|
cfg.MQPassword = GetMqPassword()
|
|
|
cfg.API = GetAPIConnString()
|
|
|
cfg.CoreDNSAddr = GetCoreDNSAddr()
|
|
|
cfg.APIPort = GetAPIPort()
|
|
|
- cfg.MQPort = GetMQPort()
|
|
|
cfg.DNSMode = "off"
|
|
|
+ cfg.Broker = GetPublicBrokerEndpoint()
|
|
|
if IsDNSMode() {
|
|
|
cfg.DNSMode = "on"
|
|
|
}
|
|
@@ -196,32 +199,39 @@ func GetCoreDNSAddr() string {
|
|
|
return addr
|
|
|
}
|
|
|
|
|
|
-// GetMQPort - gets the mq port
|
|
|
-func GetMQPort() string {
|
|
|
- port := "8883" //default
|
|
|
- if os.Getenv("MQ_PORT") != "" {
|
|
|
- port = os.Getenv("MQ_PORT")
|
|
|
- } else if config.Config.Server.MQPort != "" {
|
|
|
- port = config.Config.Server.MQPort
|
|
|
+// GetPublicBrokerEndpoint - returns the public broker endpoint which shall be used by netclient
|
|
|
+func GetPublicBrokerEndpoint() string {
|
|
|
+ if os.Getenv("BROKER_ENDPOINT") != "" {
|
|
|
+ return os.Getenv("BROKER_ENDPOINT")
|
|
|
+ } else {
|
|
|
+ return config.Config.Server.Broker
|
|
|
}
|
|
|
- return port
|
|
|
}
|
|
|
|
|
|
// GetMessageQueueEndpoint - gets the message queue endpoint
|
|
|
func GetMessageQueueEndpoint() (string, bool) {
|
|
|
host, _ := GetPublicIP()
|
|
|
- if os.Getenv("MQ_HOST") != "" {
|
|
|
- host = os.Getenv("MQ_HOST")
|
|
|
- } else if config.Config.Server.MQHOST != "" {
|
|
|
- host = config.Config.Server.MQHOST
|
|
|
- }
|
|
|
- secure := strings.Contains(host, "wss") || strings.Contains(host, "ssl")
|
|
|
- if secure {
|
|
|
- host = "wss://" + host
|
|
|
+ if os.Getenv("SERVER_BROKER_ENDPOINT") != "" {
|
|
|
+ host = os.Getenv("SERVER_BROKER_ENDPOINT")
|
|
|
+ } else if config.Config.Server.ServerBrokerEndpoint != "" {
|
|
|
+ host = config.Config.Server.ServerBrokerEndpoint
|
|
|
+ } else if os.Getenv("BROKER_ENDPOINT") != "" {
|
|
|
+ host = os.Getenv("BROKER_ENDPOINT")
|
|
|
+ } else if config.Config.Server.Broker != "" {
|
|
|
+ host = config.Config.Server.Broker
|
|
|
+ } else {
|
|
|
+ host += ":1883" // default
|
|
|
+ }
|
|
|
+ return host, strings.Contains(host, "wss") || strings.Contains(host, "ssl") || strings.Contains(host, "mqtts")
|
|
|
+}
|
|
|
+
|
|
|
+// GetBrokerType - returns the type of MQ broker
|
|
|
+func GetBrokerType() string {
|
|
|
+ if os.Getenv("BROKER_TYPE") != "" {
|
|
|
+ return os.Getenv("BROKER_TYPE")
|
|
|
} else {
|
|
|
- host = "ws://" + host
|
|
|
+ return "mosquitto"
|
|
|
}
|
|
|
- return host + ":" + GetMQServerPort(), secure
|
|
|
}
|
|
|
|
|
|
// GetMasterKey - gets the configured master key of server
|
|
@@ -325,17 +335,6 @@ func GetServer() string {
|
|
|
return server
|
|
|
}
|
|
|
|
|
|
-// GetBroker - gets the broker name
|
|
|
-func GetBroker() string {
|
|
|
- server := ""
|
|
|
- if os.Getenv("BROKER_NAME") != "" {
|
|
|
- server = os.Getenv("BROKER_NAME")
|
|
|
- } else if config.Config.Server.Broker != "" {
|
|
|
- server = config.Config.Server.Broker
|
|
|
- }
|
|
|
- return server
|
|
|
-}
|
|
|
-
|
|
|
func GetVerbosity() int32 {
|
|
|
var verbosity = 0
|
|
|
var err error
|
|
@@ -527,17 +526,6 @@ func GetAzureTenant() string {
|
|
|
return azureTenant
|
|
|
}
|
|
|
|
|
|
-// GetMQServerPort - get mq port for server
|
|
|
-func GetMQServerPort() string {
|
|
|
- port := "1883" //default
|
|
|
- if os.Getenv("MQ_SERVER_PORT") != "" {
|
|
|
- port = os.Getenv("MQ_SERVER_PORT")
|
|
|
- } else if config.Config.Server.MQServerPort != "" {
|
|
|
- port = config.Config.Server.MQServerPort
|
|
|
- }
|
|
|
- return port
|
|
|
-}
|
|
|
-
|
|
|
// GetMqPassword - fetches the MQ password
|
|
|
func GetMqPassword() string {
|
|
|
password := ""
|
|
@@ -560,6 +548,11 @@ func GetMqUserName() string {
|
|
|
return password
|
|
|
}
|
|
|
|
|
|
+// GetEmqxRestEndpoint - returns the REST API Endpoint of EMQX
|
|
|
+func GetEmqxRestEndpoint() string {
|
|
|
+ return os.Getenv("EMQX_REST_ENDPOINT")
|
|
|
+}
|
|
|
+
|
|
|
// IsBasicAuthEnabled - checks if basic auth has been configured to be turned off
|
|
|
func IsBasicAuthEnabled() bool {
|
|
|
var enabled = true //default
|