Skip to content

Commit 967149e

Browse files
author
Andrea Falzetti
committed
fix(gitpod-cli): ports list safe access to exposed url
1 parent 4c6b224 commit 967149e

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

components/gitpod-cli/cmd/ports-list.go

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,43 @@ var listPortsCmd = &cobra.Command{
4848
table.SetCenterSeparator("|")
4949

5050
for _, port := range ports {
51-
status := "not served"
51+
status := ""
5252
statusColor := tablewriter.FgHiBlackColor
53-
if port.Exposed == nil && port.Tunneled == nil {
53+
accessible := port.Exposed != nil || port.Tunneled != nil
54+
55+
exposedUrl := ""
56+
if port.Exposed != nil {
57+
exposedUrl = port.Exposed.Url
58+
}
59+
60+
if !port.Served {
61+
status = "not served"
62+
} else if !accessible {
5463
if port.AutoExposure == supervisor.PortAutoExposure_failed {
5564
status = "failed to expose"
5665
statusColor = tablewriter.FgRedColor
5766
} else {
5867
status = "detecting..."
5968
statusColor = tablewriter.FgYellowColor
6069
}
61-
} else if port.Served {
62-
status = "open (" + port.Exposed.Visibility.String() + ")"
70+
} else if port.Exposed != nil {
6371
if port.Exposed.Visibility == supervisor.PortVisibility_public {
72+
status = "open (public)"
6473
statusColor = tablewriter.FgHiGreenColor
65-
} else {
74+
}
75+
if port.Exposed.Visibility == supervisor.PortVisibility_private {
76+
status = "open (private)"
6677
statusColor = tablewriter.FgHiCyanColor
6778
}
79+
} else if port.Tunneled != nil {
80+
if port.Tunneled.Visibility == supervisor.TunnelVisiblity(supervisor.TunnelVisiblity_value["network"]) {
81+
status = "open on all interfaces"
82+
statusColor = tablewriter.FgHiGreenColor
83+
}
84+
if port.Tunneled.Visibility == supervisor.TunnelVisiblity(supervisor.TunnelVisiblity_value["host"]) {
85+
status = "open on localhost"
86+
statusColor = tablewriter.FgHiGreenColor
87+
}
6888
}
6989

7090
nameAndDescription := port.Name
@@ -82,7 +102,7 @@ var listPortsCmd = &cobra.Command{
82102
}
83103

84104
table.Rich(
85-
[]string{fmt.Sprint(port.LocalPort), status, port.Exposed.Url, nameAndDescription},
105+
[]string{fmt.Sprint(port.LocalPort), status, exposedUrl, nameAndDescription},
86106
colors,
87107
)
88108
}

0 commit comments

Comments
 (0)