From bfd65feb90a89956453d925703a5a8dba9decad5 Mon Sep 17 00:00:00 2001 From: Hugo Vieira Date: Thu, 6 Oct 2022 17:59:16 +0100 Subject: [PATCH] feat(cmd): Display session connection information --- internal/cmd/commands/sessionscmd/funcs.go | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/internal/cmd/commands/sessionscmd/funcs.go b/internal/cmd/commands/sessionscmd/funcs.go index 16fdb100f1..16a32a50a4 100644 --- a/internal/cmd/commands/sessionscmd/funcs.go +++ b/internal/cmd/commands/sessionscmd/funcs.go @@ -2,6 +2,8 @@ package sessionscmd import ( "fmt" + "net" + "strconv" "strings" "time" @@ -230,6 +232,20 @@ func printItemTable(item *sessions.Session, resp *api.Response) string { } } + var connectionsMaps []map[string]interface{} + for _, sc := range item.Connections { + cm := map[string]interface{}{ + "Client Address": net.JoinHostPort(sc.ClientTcpAddress, strconv.FormatUint(uint64(sc.ClientTcpPort), 10)), + "Endpoint Address": net.JoinHostPort(sc.EndpointTcpAddress, strconv.FormatUint(uint64(sc.EndpointTcpPort), 10)), + "Bytes Up": sc.BytesUp, + "Bytes Down": sc.BytesDown, + } + if len(sc.ClosedReason) != 0 { + cm["Closed Reason"] = sc.ClosedReason + } + connectionsMaps = append(connectionsMaps, cm) + } + ret := []string{ "", "Session information:", @@ -265,5 +281,18 @@ func printItemTable(item *sessions.Session, resp *api.Response) string { } } + if len(item.Connections) > 0 { + ret = append(ret, + "", + " Connections:", + ) + for _, c := range connectionsMaps { + ret = append(ret, + base.WrapMap(4, maxLength, c), + "", + ) + } + } + return base.WrapForHelpText(ret) }