Skip to content

Commit 6a03a88

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

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

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

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,40 @@ 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() + ")"
63-
if port.Exposed.Visibility == supervisor.PortVisibility_public {
70+
} else {
71+
if port.Tunneled != nil && port.Tunneled.Visibility == supervisor.TunnelVisiblity(supervisor.TunnelVisiblity_value["network"]) {
72+
status = "open on all interfaces"
6473
statusColor = tablewriter.FgHiGreenColor
65-
} else {
74+
}
75+
if port.Tunneled != nil && port.Tunneled.Visibility == supervisor.TunnelVisiblity(supervisor.TunnelVisiblity_value["host"]) {
76+
status = "open on localhost"
77+
statusColor = tablewriter.FgHiGreenColor
78+
}
79+
if port.Exposed != nil && port.Exposed.Visibility == supervisor.PortVisibility_public {
80+
status = "open (public)"
81+
statusColor = tablewriter.FgHiGreenColor
82+
}
83+
if port.Exposed != nil && port.Exposed.Visibility == supervisor.PortVisibility_private {
84+
status = "open (private)"
6685
statusColor = tablewriter.FgHiCyanColor
6786
}
6887
}
@@ -82,7 +101,7 @@ var listPortsCmd = &cobra.Command{
82101
}
83102

84103
table.Rich(
85-
[]string{fmt.Sprint(port.LocalPort), status, port.Exposed.Url, nameAndDescription},
104+
[]string{fmt.Sprint(port.LocalPort), status, exposedUrl, nameAndDescription},
86105
colors,
87106
)
88107
}

0 commit comments

Comments
 (0)