From 967149ef7bc127a91f8b5b9c035856baf940ac2c Mon Sep 17 00:00:00 2001 From: Andrea Falzetti Date: Fri, 7 Oct 2022 12:10:27 +0000 Subject: [PATCH] fix(gitpod-cli): ports list safe access to exposed url --- components/gitpod-cli/cmd/ports-list.go | 32 ++++++++++++++++++++----- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/components/gitpod-cli/cmd/ports-list.go b/components/gitpod-cli/cmd/ports-list.go index 55bf6c2c065e87..8aa2b75039cd05 100644 --- a/components/gitpod-cli/cmd/ports-list.go +++ b/components/gitpod-cli/cmd/ports-list.go @@ -48,9 +48,18 @@ var listPortsCmd = &cobra.Command{ table.SetCenterSeparator("|") for _, port := range ports { - status := "not served" + status := "" statusColor := tablewriter.FgHiBlackColor - if port.Exposed == nil && port.Tunneled == nil { + accessible := port.Exposed != nil || port.Tunneled != nil + + exposedUrl := "" + if port.Exposed != nil { + exposedUrl = port.Exposed.Url + } + + if !port.Served { + status = "not served" + } else if !accessible { if port.AutoExposure == supervisor.PortAutoExposure_failed { status = "failed to expose" statusColor = tablewriter.FgRedColor @@ -58,13 +67,24 @@ var listPortsCmd = &cobra.Command{ status = "detecting..." statusColor = tablewriter.FgYellowColor } - } else if port.Served { - status = "open (" + port.Exposed.Visibility.String() + ")" + } else if port.Exposed != nil { if port.Exposed.Visibility == supervisor.PortVisibility_public { + status = "open (public)" statusColor = tablewriter.FgHiGreenColor - } else { + } + if port.Exposed.Visibility == supervisor.PortVisibility_private { + status = "open (private)" statusColor = tablewriter.FgHiCyanColor } + } else if port.Tunneled != nil { + if port.Tunneled.Visibility == supervisor.TunnelVisiblity(supervisor.TunnelVisiblity_value["network"]) { + status = "open on all interfaces" + statusColor = tablewriter.FgHiGreenColor + } + if port.Tunneled.Visibility == supervisor.TunnelVisiblity(supervisor.TunnelVisiblity_value["host"]) { + status = "open on localhost" + statusColor = tablewriter.FgHiGreenColor + } } nameAndDescription := port.Name @@ -82,7 +102,7 @@ var listPortsCmd = &cobra.Command{ } table.Rich( - []string{fmt.Sprint(port.LocalPort), status, port.Exposed.Url, nameAndDescription}, + []string{fmt.Sprint(port.LocalPort), status, exposedUrl, nameAndDescription}, colors, ) }