mirror of
https://github.com/gravitl/netmaker.git
synced 2024-11-10 17:48:25 +08:00
Merge pull request #1424 from gravitl/feature_v0.14.7_netmakeraddvarforpublicipservice
Add PUBLIC_IP_SERVICE to netmaker (server).
This commit is contained in:
commit
2585e88d79
3 changed files with 17 additions and 3 deletions
|
@ -2,8 +2,6 @@ package logger
|
|||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/gravitl/netmaker/servercfg"
|
||||
)
|
||||
|
||||
// Verbosity - current logging verbosity level (optionally set)
|
||||
|
@ -25,6 +23,5 @@ func getVerbose() int32 {
|
|||
if Verbosity >= 1 && Verbosity <= 4 {
|
||||
return int32(Verbosity)
|
||||
}
|
||||
Verbosity = int(servercfg.GetVerbosity())
|
||||
return int32(Verbosity)
|
||||
}
|
||||
|
|
6
main.go
6
main.go
|
@ -42,6 +42,7 @@ func main() {
|
|||
fmt.Println(models.RetrieveLogo()) // print the logo
|
||||
initialize() // initial db and acls; gen cert if required
|
||||
setGarbageCollection()
|
||||
setVerbosity()
|
||||
defer database.CloseDB()
|
||||
startControllers() // start the api endpoint and mq
|
||||
}
|
||||
|
@ -182,6 +183,11 @@ func runMessageQueue(wg *sync.WaitGroup) {
|
|||
client.Disconnect(250)
|
||||
}
|
||||
|
||||
func setVerbosity() {
|
||||
verbose := int(servercfg.GetVerbosity())
|
||||
logger.Verbosity = verbose
|
||||
}
|
||||
|
||||
func setGarbageCollection() {
|
||||
_, gcset := os.LookupEnv("GOGC")
|
||||
if !gcset {
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/gravitl/netmaker/config"
|
||||
"github.com/gravitl/netmaker/logger"
|
||||
"github.com/gravitl/netmaker/models"
|
||||
)
|
||||
|
||||
|
@ -427,7 +428,16 @@ func GetPublicIP() (string, error) {
|
|||
var err error
|
||||
|
||||
iplist := []string{"https://ip.server.gravitl.com", "https://ifconfig.me", "https://api.ipify.org", "https://ipinfo.io/ip"}
|
||||
publicIpService := os.Getenv("PUBLIC_IP_SERVICE")
|
||||
if publicIpService != "" {
|
||||
logger.Log(3, "User provided public IP service is", publicIpService)
|
||||
|
||||
// prepend the user-specified service so it's checked first
|
||||
iplist = append([]string{publicIpService}, iplist...)
|
||||
}
|
||||
|
||||
for _, ipserver := range iplist {
|
||||
logger.Log(3, "Running public IP check with service", ipserver)
|
||||
client := &http.Client{
|
||||
Timeout: time.Second * 10,
|
||||
}
|
||||
|
@ -442,6 +452,7 @@ func GetPublicIP() (string, error) {
|
|||
continue
|
||||
}
|
||||
endpoint = string(bodyBytes)
|
||||
logger.Log(3, "Public IP address is", endpoint)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue