feat: optionally log

This commit is contained in:
Jose Diaz-Gonzalez committed 2020-02-25 20:11:43 -05:00
1 parent 6ecf6c31ba
commit e6bf778a65
2 files changed
+18 -8

No files matched your search

+12 -5
View File
@@ -100,7 +100,8 @@ func getAppProxyType(appName string) string {
func getProxyPortMap(appName string) []PortMap { func getProxyPortMap(appName string) []PortMap {
value := config.GetWithDefault(appName, "DOKKU_PROXY_PORT_MAP", "") value := config.GetWithDefault(appName, "DOKKU_PROXY_PORT_MAP", "")
return parseProxyPortMapString(value) warn := false
return parseProxyPortMapString(value, warn)
} }
func listAppProxyPorts(appName string) error { func listAppProxyPorts(appName string) error {
@@ -165,24 +166,30 @@ func removeProxyPorts(appName string, proxyPortMap []PortMap) error {
return setProxyPorts(appName, toSet) return setProxyPorts(appName, toSet)
} }
func parseProxyPortMapString(stringPortMap string) []PortMap { func parseProxyPortMapString(stringPortMap string, warn bool) []PortMap {
var proxyPortMap []PortMap var proxyPortMap []PortMap
for _, v := range strings.Split(strings.TrimSpace(stringPortMap), " ") { for _, v := range strings.Split(strings.TrimSpace(stringPortMap), " ") {
parts := strings.SplitN(v, ":", 3) parts := strings.SplitN(v, ":", 3)
if len(parts) != 3 { if len(parts) != 3 {
common.LogWarn(fmt.Sprintf("Invalid port map %s", v)) if warn {
common.LogWarn(fmt.Sprintf("Invalid port map %s", v))
}
continue continue
} }
hostPort, err := strconv.Atoi(parts[1]) hostPort, err := strconv.Atoi(parts[1])
if err != nil { if err != nil {
common.LogWarn(fmt.Sprintf("Invalid port map %s", v)) if warn {
common.LogWarn(fmt.Sprintf("Invalid port map %s", v))
}
} }
containerPort, err := strconv.Atoi(parts[2]) containerPort, err := strconv.Atoi(parts[2])
if err != nil { if err != nil {
common.LogWarn(fmt.Sprintf("Invalid port map %s", v)) if warn {
common.LogWarn(fmt.Sprintf("Invalid port map %s", v))
}
} }
proxyPortMap = append(proxyPortMap, PortMap{ proxyPortMap = append(proxyPortMap, PortMap{
+6 -3
View File
@@ -85,7 +85,8 @@ func CommandPortsAdd(args []string) error {
} }
stringPortMap := strings.Join(args[1:], " ") stringPortMap := strings.Join(args[1:], " ")
proxyPortMap := parseProxyPortMapString(stringPortMap) warn := true
proxyPortMap := parseProxyPortMapString(stringPortMap, warn)
if err := addProxyPorts(appName, proxyPortMap); err != nil { if err := addProxyPorts(appName, proxyPortMap); err != nil {
return err return err
} }
@@ -121,7 +122,8 @@ func CommandPortsRemove(args []string) error {
} }
stringPortMap := strings.Join(args[1:], " ") stringPortMap := strings.Join(args[1:], " ")
proxyPortMap := parseProxyPortMapString(stringPortMap) warn := true
proxyPortMap := parseProxyPortMapString(stringPortMap, warn)
if err := removeProxyPorts(appName, proxyPortMap); err != nil { if err := removeProxyPorts(appName, proxyPortMap); err != nil {
return err return err
} }
@@ -141,7 +143,8 @@ func CommandPortsSet(args []string) error {
} }
stringPortMap := strings.Join(args[1:], " ") stringPortMap := strings.Join(args[1:], " ")
proxyPortMap := parseProxyPortMapString(stringPortMap) warn := true
proxyPortMap := parseProxyPortMapString(stringPortMap, warn)
if err := setProxyPorts(appName, proxyPortMap); err != nil { if err := setProxyPorts(appName, proxyPortMap); err != nil {
return err return err
} }