feat: add network:report command

This commit is contained in:
Jose Diaz-Gonzalez
2017-10-04 00:48:02 -04:00
parent fdbab2c291
commit ad732bd42b
8 changed files with 141 additions and 17 deletions

View File

@@ -2,6 +2,7 @@ package network
import (
"fmt"
"path/filepath"
"strconv"
"strings"
@@ -148,6 +149,23 @@ func GetDefaultValue(property string) (value string) {
return
}
// GetListeners returns a string array of app listeners
func GetListeners(appName string) []string {
dokkuRoot := common.MustGetEnv("DOKKU_ROOT")
appRoot := strings.Join([]string{dokkuRoot, appName}, "/")
files, _ := filepath.Glob(appRoot + "/IP.web.*")
var listeners []string
for _, ipfile := range files {
portfile := strings.Replace(ipfile, "/IP.web.", "/PORT.web.", 1)
ipAddress := common.ReadFirstLine(ipfile)
port := common.ReadFirstLine(portfile)
listeners = append(listeners, fmt.Sprintf("%s:%s", ipAddress, port))
}
return listeners
}
// HasNetworkConfig returns whether the network configuration for a given app exists
func HasNetworkConfig(appName string) bool {
appRoot := strings.Join([]string{common.MustGetEnv("DOKKU_ROOT"), appName}, "/")