@@ -15,6 +15,8 @@ import (
15
15
"github.com/pkg/errors"
16
16
)
17
17
18
+ const defaultTag = "latest"
19
+
18
20
// ContainersRealtimeService is the service responsible for performing real-time container scanning.
19
21
type ContainersRealtimeService struct {
20
22
JwtWrapper wrappers.JWTWrapper
@@ -218,26 +220,31 @@ func mergeImagesToResults(listOfImages []wrappers.ContainerImageResponseItem, re
218
220
219
221
func getImageLocations (images * []types.ImageModel , imageName , imageTag string ) (location []realtimeengine.Location , filePath string ) {
220
222
for i , img := range * images {
221
- if img .Name == imageName + ":" + imageTag || img .Name == imageName + "@" + imageTag {
222
- location := convertLocations (& img .ImageLocations )
223
- filePath := ""
224
- if len (img .ImageLocations ) > 0 {
225
- filePath = img .ImageLocations [0 ].Path
226
- }
227
- * images = append ((* images )[:i ], (* images )[i + 1 :]... )
228
- return location , filePath
223
+ if ! isSameImage (img .Name , imageName , imageTag ) {
224
+ continue
229
225
}
226
+ location := convertLocations (& img .ImageLocations )
227
+ filePath := ""
228
+ if len (img .ImageLocations ) > 0 {
229
+ filePath = img .ImageLocations [0 ].Path
230
+ }
231
+ * images = append ((* images )[:i ], (* images )[i + 1 :]... )
232
+ return location , filePath
230
233
}
231
234
return []realtimeengine.Location {}, ""
232
235
}
233
236
237
+ func isSameImage (curImage , imageName , imageTag string ) bool {
238
+ return curImage == imageName + ":" + imageTag || curImage == imageName + "@" + imageTag || curImage == imageName && imageTag == defaultTag
239
+ }
240
+
234
241
// splitToImageAndTag splits the image string into name and tag components.
235
242
func splitToImageAndTag (image string ) (imageName , imageTag string ) {
236
243
// Split the image string by the last colon to separate name and tag
237
244
lastColonIndex := strings .LastIndex (image , ":" )
238
245
239
246
if lastColonIndex == len (image )- 1 || lastColonIndex == - 1 {
240
- return image , "latest" // No tag specified, default to "latest"
247
+ return image , defaultTag // No tag specified, default to "latest"
241
248
}
242
249
243
250
imageName = image [:lastColonIndex ]
0 commit comments