add regexp for salt-master if using ip:port

This commit is contained in:
wh1te909 2020-10-15 12:55:21 -07:00
parent 7a3d895368
commit 29e6f8cfbf
1 changed files with 11 additions and 0 deletions

View File

@ -7,6 +7,7 @@ import (
"net/url"
"os"
"path/filepath"
"regexp"
"strings"
"time"
@ -51,6 +52,16 @@ func (a *WindowsAgent) Install(i *Installer) {
a.installerMsg("Invalid URL (must contain https or http)", "error")
}
// will match either ipv4 , or ipv4:port
var ipPort = regexp.MustCompile(`[0-9]+(?:\.[0-9]+){3}(:[0-9]+)?`)
// if ipv4:port, strip the port to get ip for salt master
if ipPort.MatchString(u.Host) && strings.Contains(u.Host, ":") {
i.SaltMaster = strings.Split(u.Host, ":")[0]
} else {
i.SaltMaster = u.Host
}
i.SaltMaster = u.Host
a.Logger.Debugln("Salt Master:", i.SaltMaster)