feat: add network:report command
This commit is contained in:
@@ -18,6 +18,7 @@ Manages network settings for an app
|
||||
Additional commands:`
|
||||
|
||||
helpContent = `
|
||||
network:report [<app>] [<flag>], Displays a network report for one or more apps
|
||||
network:rebuild <app>, Rebuilds network settings for an app
|
||||
network:rebuildall, Rebuild network settings for all apps
|
||||
network:set <app> <property> (<value>), Set or clear a network property for an app
|
||||
|
||||
67
plugins/network/src/subcommands/report/report.go
Normal file
67
plugins/network/src/subcommands/report/report.go
Normal file
@@ -0,0 +1,67 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/dokku/dokku/plugins/common"
|
||||
"github.com/dokku/dokku/plugins/network"
|
||||
)
|
||||
|
||||
func reportSingleApp(appName, infoFlag string) {
|
||||
infoFlags := map[string]string{
|
||||
"--network-bind-all-interfaces": common.PropertyGet("network", appName, "bind-all-interfaces"),
|
||||
"--network-listeners": strings.Join(network.GetListeners(appName), " "),
|
||||
}
|
||||
|
||||
if len(infoFlag) == 0 {
|
||||
common.LogInfo2Quiet(fmt.Sprintf("%s network information", appName))
|
||||
for k, v := range infoFlags {
|
||||
key := common.UcFirst(strings.Replace(strings.TrimPrefix(k, "--"), "-", " ", -1))
|
||||
common.LogVerbose(fmt.Sprintf("%s: %s", key, v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
for k, v := range infoFlags {
|
||||
if infoFlag == k {
|
||||
fmt.Fprintln(os.Stdout, v)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
keys := reflect.ValueOf(infoFlags).MapKeys()
|
||||
strkeys := make([]string, len(keys))
|
||||
for i := 0; i < len(keys); i++ {
|
||||
strkeys[i] = keys[i].String()
|
||||
}
|
||||
common.LogFail(fmt.Sprintf("Invalid flag passed, valid flags: %s", strings.Join(strkeys, ", ")))
|
||||
}
|
||||
|
||||
// set or clear a network property for an app
|
||||
func main() {
|
||||
flag.Parse()
|
||||
appName := flag.Arg(1)
|
||||
infoFlag := flag.Arg(2)
|
||||
|
||||
if strings.HasPrefix(appName, "--") {
|
||||
infoFlag = appName
|
||||
appName = ""
|
||||
}
|
||||
|
||||
if len(appName) == 0 {
|
||||
apps, err := common.DokkuApps()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for _, appName := range apps {
|
||||
reportSingleApp(appName, infoFlag)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
reportSingleApp(appName, infoFlag)
|
||||
}
|
||||
@@ -4,10 +4,9 @@ import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/dokku/dokku/plugins/common"
|
||||
"github.com/dokku/dokku/plugins/network"
|
||||
)
|
||||
|
||||
// returns the listeners (host:port combinations) for a given app container
|
||||
@@ -15,18 +14,6 @@ func main() {
|
||||
flag.Parse()
|
||||
appName := flag.Arg(0)
|
||||
|
||||
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))
|
||||
}
|
||||
|
||||
listeners := network.GetListeners(appName)
|
||||
fmt.Fprint(os.Stdout, strings.Join(listeners, " "))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user