@@ -138,6 +138,7 @@ func (c *ScalewayCache) LookUpImages(needle string, acceptUUID bool) []string {
138
138
defer c .Lock .Unlock ()
139
139
140
140
var res []string
141
+ var exactMatches []string
141
142
142
143
if acceptUUID && uuid .Parse (needle ) != nil {
143
144
res = append (res , needle )
@@ -147,11 +148,18 @@ func (c *ScalewayCache) LookUpImages(needle string, acceptUUID bool) []string {
147
148
// FIXME: if 'user/' is in needle, only watch for a user image
148
149
nameRegex := regexp .MustCompile (`(?i)` + regexp .MustCompile (`[_-]` ).ReplaceAllString (needle , ".*" ))
149
150
for identifier , name := range c .Images {
151
+ if name == needle {
152
+ exactMatches = append (exactMatches , identifier )
153
+ }
150
154
if strings .HasPrefix (identifier , needle ) || nameRegex .MatchString (name ) {
151
155
res = append (res , identifier )
152
156
}
153
157
}
154
158
159
+ if len (exactMatches ) == 1 {
160
+ return exactMatches
161
+ }
162
+
155
163
return RemoveDuplicates (res )
156
164
}
157
165
@@ -161,6 +169,7 @@ func (c *ScalewayCache) LookUpSnapshots(needle string, acceptUUID bool) []string
161
169
defer c .Lock .Unlock ()
162
170
163
171
var res []string
172
+ var exactMatches []string
164
173
165
174
if acceptUUID && uuid .Parse (needle ) != nil {
166
175
res = append (res , needle )
@@ -169,11 +178,18 @@ func (c *ScalewayCache) LookUpSnapshots(needle string, acceptUUID bool) []string
169
178
needle = regexp .MustCompile (`^user/` ).ReplaceAllString (needle , "" )
170
179
nameRegex := regexp .MustCompile (`(?i)` + regexp .MustCompile (`[_-]` ).ReplaceAllString (needle , ".*" ))
171
180
for identifier , name := range c .Snapshots {
181
+ if name == needle {
182
+ exactMatches = append (exactMatches , identifier )
183
+ }
172
184
if strings .HasPrefix (identifier , needle ) || nameRegex .MatchString (name ) {
173
185
res = append (res , identifier )
174
186
}
175
187
}
176
188
189
+ if len (exactMatches ) == 1 {
190
+ return exactMatches
191
+ }
192
+
177
193
return RemoveDuplicates (res )
178
194
}
179
195
@@ -183,18 +199,26 @@ func (c *ScalewayCache) LookUpVolumes(needle string, acceptUUID bool) []string {
183
199
defer c .Lock .Unlock ()
184
200
185
201
var res []string
202
+ var exactMatches []string
186
203
187
204
if acceptUUID && uuid .Parse (needle ) != nil {
188
205
res = append (res , needle )
189
206
}
190
207
191
208
nameRegex := regexp .MustCompile (`(?i)` + regexp .MustCompile (`[_-]` ).ReplaceAllString (needle , ".*" ))
192
209
for identifier , name := range c .Volumes {
210
+ if name == needle {
211
+ exactMatches = append (exactMatches , identifier )
212
+ }
193
213
if strings .HasPrefix (identifier , needle ) || nameRegex .MatchString (name ) {
194
214
res = append (res , identifier )
195
215
}
196
216
}
197
217
218
+ if len (exactMatches ) == 1 {
219
+ return exactMatches
220
+ }
221
+
198
222
return RemoveDuplicates (res )
199
223
}
200
224
@@ -204,18 +228,26 @@ func (c *ScalewayCache) LookUpBootscripts(needle string, acceptUUID bool) []stri
204
228
defer c .Lock .Unlock ()
205
229
206
230
var res []string
231
+ var exactMatches []string
207
232
208
233
if acceptUUID && uuid .Parse (needle ) != nil {
209
234
res = append (res , needle )
210
235
}
211
236
212
237
nameRegex := regexp .MustCompile (`(?i)` + regexp .MustCompile (`[_-]` ).ReplaceAllString (needle , ".*" ))
213
238
for identifier , name := range c .Bootscripts {
239
+ if name == needle {
240
+ exactMatches = append (exactMatches , identifier )
241
+ }
214
242
if strings .HasPrefix (identifier , needle ) || nameRegex .MatchString (name ) {
215
243
res = append (res , identifier )
216
244
}
217
245
}
218
246
247
+ if len (exactMatches ) == 1 {
248
+ return exactMatches
249
+ }
250
+
219
251
return RemoveDuplicates (res )
220
252
}
221
253
@@ -225,18 +257,26 @@ func (c *ScalewayCache) LookUpServers(needle string, acceptUUID bool) []string {
225
257
defer c .Lock .Unlock ()
226
258
227
259
var res []string
260
+ var exactMatches []string
228
261
229
262
if acceptUUID && uuid .Parse (needle ) != nil {
230
263
res = append (res , needle )
231
264
}
232
265
233
266
nameRegex := regexp .MustCompile (`(?i)` + regexp .MustCompile (`[_-]` ).ReplaceAllString (needle , ".*" ))
234
267
for identifier , name := range c .Servers {
268
+ if name == needle {
269
+ exactMatches = append (exactMatches , identifier )
270
+ }
235
271
if strings .HasPrefix (identifier , needle ) || nameRegex .MatchString (name ) {
236
272
res = append (res , identifier )
237
273
}
238
274
}
239
275
276
+ if len (exactMatches ) == 1 {
277
+ return exactMatches
278
+ }
279
+
240
280
return RemoveDuplicates (res )
241
281
}
242
282
0 commit comments