@@ -18,26 +18,32 @@ import (
18
18
19
19
// RangeConfig is a port range config.
20
20
type RangeConfig struct {
21
- * gitpod.PortsItems
21
+ gitpod.PortsItems
22
22
Start uint32
23
23
End uint32
24
24
Sort uint32
25
25
}
26
26
27
+ // SortConfig is a port with a sort field
28
+ type SortConfig struct {
29
+ gitpod.PortConfig
30
+ Sort uint32
31
+ }
32
+
27
33
// Configs provides access to port configurations.
28
34
type Configs struct {
29
- workspaceConfigs map [uint32 ]* gitpod. PortConfig
30
- instancePortConfigs map [uint32 ]* gitpod. PortConfig
35
+ workspaceConfigs map [uint32 ]* SortConfig
36
+ instancePortConfigs map [uint32 ]* SortConfig
31
37
instanceRangeConfigs []* RangeConfig
32
38
}
33
39
34
40
// ForEach iterates over all configured ports.
35
- func (configs * Configs ) ForEach (callback func (port uint32 , config * gitpod. PortConfig )) {
41
+ func (configs * Configs ) ForEach (callback func (port uint32 , config * SortConfig )) {
36
42
if configs == nil {
37
43
return
38
44
}
39
45
visited := make (map [uint32 ]struct {})
40
- for _ , configs := range []map [uint32 ]* gitpod. PortConfig {configs .instancePortConfigs , configs .workspaceConfigs } {
46
+ for _ , configs := range []map [uint32 ]* SortConfig {configs .instancePortConfigs , configs .workspaceConfigs } {
41
47
for port , config := range configs {
42
48
_ , exists := visited [port ]
43
49
if exists {
60
66
)
61
67
62
68
// Get returns the config for the give port.
63
- func (configs * Configs ) Get (port uint32 ) (* gitpod. PortConfig , ConfigKind , bool ) {
69
+ func (configs * Configs ) Get (port uint32 ) (* SortConfig , ConfigKind , bool ) {
64
70
if configs == nil {
65
71
return nil , PortConfigKind , false
66
72
}
@@ -74,13 +80,15 @@ func (configs *Configs) Get(port uint32) (*gitpod.PortConfig, ConfigKind, bool)
74
80
}
75
81
for _ , rangeConfig := range configs .instanceRangeConfigs {
76
82
if rangeConfig .Start <= port && port <= rangeConfig .End {
77
- return & gitpod.PortConfig {
78
- Port : float64 (port ),
79
- OnOpen : rangeConfig .OnOpen ,
80
- Visibility : rangeConfig .Visibility ,
81
- Description : rangeConfig .Description ,
82
- Name : rangeConfig .Name ,
83
- Sort : rangeConfig .Sort ,
83
+ return & SortConfig {
84
+ PortConfig : gitpod.PortConfig {
85
+ Port : float64 (port ),
86
+ OnOpen : rangeConfig .OnOpen ,
87
+ Visibility : rangeConfig .Visibility ,
88
+ Description : rangeConfig .Description ,
89
+ Name : rangeConfig .Name ,
90
+ },
91
+ Sort : rangeConfig .Sort ,
84
92
}, RangeConfigKind , true
85
93
}
86
94
}
@@ -170,22 +178,26 @@ func (service *ConfigService) update(config *gitpod.GitpodConfig, current *Confi
170
178
171
179
var portRangeRegexp = regexp .MustCompile (`^(\d+)[-:](\d+)$` )
172
180
173
- func parseWorkspaceConfigs (ports []* gitpod.PortConfig ) (portConfigs map [uint32 ]* gitpod. PortConfig ) {
181
+ func parseWorkspaceConfigs (ports []* gitpod.PortConfig ) (portConfigs map [uint32 ]* SortConfig ) {
174
182
if len (ports ) == 0 {
175
183
return nil
176
184
}
177
- portConfigs = make (map [uint32 ]* gitpod. PortConfig )
185
+ portConfigs = make (map [uint32 ]* SortConfig )
178
186
for _ , config := range ports {
179
187
port := uint32 (config .Port )
180
188
_ , exists := portConfigs [port ]
181
189
if ! exists {
182
- portConfigs [port ] = config
190
+ portConfigs [port ] = & SortConfig {
191
+ PortConfig : * config ,
192
+ // We don't care about workspace configs but instance config
193
+ Sort : 0 ,
194
+ }
183
195
}
184
196
}
185
197
return portConfigs
186
198
}
187
199
188
- func parseInstanceConfigs (ports []* gitpod.PortsItems ) (portConfigs map [uint32 ]* gitpod. PortConfig , rangeConfigs []* RangeConfig ) {
200
+ func parseInstanceConfigs (ports []* gitpod.PortsItems ) (portConfigs map [uint32 ]* SortConfig , rangeConfigs []* RangeConfig ) {
189
201
for index , config := range ports {
190
202
if config == nil {
191
203
continue
@@ -195,18 +207,20 @@ func parseInstanceConfigs(ports []*gitpod.PortsItems) (portConfigs map[uint32]*g
195
207
Port , err := strconv .ParseUint (rawPort , 10 , 16 )
196
208
if err == nil {
197
209
if portConfigs == nil {
198
- portConfigs = make (map [uint32 ]* gitpod. PortConfig )
210
+ portConfigs = make (map [uint32 ]* SortConfig )
199
211
}
200
212
port := uint32 (Port )
201
213
_ , exists := portConfigs [port ]
202
214
if ! exists {
203
- portConfigs [port ] = & gitpod.PortConfig {
204
- OnOpen : config .OnOpen ,
205
- Port : float64 (Port ),
206
- Visibility : config .Visibility ,
207
- Description : config .Description ,
208
- Name : config .Name ,
209
- Sort : uint32 (index ),
215
+ portConfigs [port ] = & SortConfig {
216
+ PortConfig : gitpod.PortConfig {
217
+ OnOpen : config .OnOpen ,
218
+ Port : float64 (Port ),
219
+ Visibility : config .Visibility ,
220
+ Description : config .Description ,
221
+ Name : config .Name ,
222
+ },
223
+ Sort : uint32 (index ),
210
224
}
211
225
}
212
226
continue
@@ -224,7 +238,7 @@ func parseInstanceConfigs(ports []*gitpod.PortsItems) (portConfigs map[uint32]*g
224
238
continue
225
239
}
226
240
rangeConfigs = append (rangeConfigs , & RangeConfig {
227
- PortsItems : config ,
241
+ PortsItems : * config ,
228
242
Start : uint32 (start ),
229
243
End : uint32 (end ),
230
244
Sort : uint32 (index ),
0 commit comments