Skip to content

Commit 7c5dc44

Browse files
Andrea Falzettiroboquat
Andrea Falzetti
authored andcommitted
fix(gitpod-cli): ports list safe access to exposed url
1 parent f732037 commit 7c5dc44

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
@@ -43,23 +43,43 @@ var listPortsCmd = &cobra.Command{
4343
table.SetCenterSeparator("|")
4444

4545
for _, port := range ports {
46-
status := "not served"
46+
status := ""
4747
statusColor := tablewriter.FgHiBlackColor
48-
if port.Exposed == nil && port.Tunneled == nil {
48+
accessible := port.Exposed != nil || port.Tunneled != nil
49+
50+
exposedUrl := ""
51+
if port.Exposed != nil {
52+
exposedUrl = port.Exposed.Url
53+
}
54+
55+
if !port.Served {
56+
status = "not served"
57+
} else if !accessible {
4958
if port.AutoExposure == supervisor.PortAutoExposure_failed {
5059
status = "failed to expose"
5160
statusColor = tablewriter.FgRedColor
5261
} else {
5362
status = "detecting..."
5463
statusColor = tablewriter.FgYellowColor
5564
}
56-
} else if port.Served {
57-
status = "open (" + port.Exposed.Visibility.String() + ")"
65+
} else if port.Exposed != nil {
5866
if port.Exposed.Visibility == supervisor.PortVisibility_public {
67+
status = "open (public)"
5968
statusColor = tablewriter.FgHiGreenColor
60-
} else {
69+
}
70+
if port.Exposed.Visibility == supervisor.PortVisibility_private {
71+
status = "open (private)"
6172
statusColor = tablewriter.FgHiCyanColor
6273
}
74+
} else if port.Tunneled != nil {
75+
if port.Tunneled.Visibility == supervisor.TunnelVisiblity(supervisor.TunnelVisiblity_value["network"]) {
76+
status = "open on all interfaces"
77+
statusColor = tablewriter.FgHiGreenColor
78+
}
79+
if port.Tunneled.Visibility == supervisor.TunnelVisiblity(supervisor.TunnelVisiblity_value["host"]) {
80+
status = "open on localhost"
81+
statusColor = tablewriter.FgHiGreenColor
82+
}
6383
}
6484

6585
nameAndDescription := port.Name
@@ -77,7 +97,7 @@ var listPortsCmd = &cobra.Command{
7797
}
7898

7999
table.Rich(
80-
[]string{fmt.Sprint(port.LocalPort), status, port.Exposed.Url, nameAndDescription},
100+
[]string{fmt.Sprint(port.LocalPort), status, exposedUrl, nameAndDescription},
81101
colors,
82102
)
83103
}

0 commit comments

Comments
 (0)