@@ -15,6 +15,8 @@ import (
1515 "github.com/pkg/errors"
1616)
1717
18+ const defaultTag = "latest"
19+
1820// ContainersRealtimeService is the service responsible for performing real-time container scanning.
1921type ContainersRealtimeService struct {
2022 JwtWrapper wrappers.JWTWrapper
@@ -218,26 +220,31 @@ func mergeImagesToResults(listOfImages []wrappers.ContainerImageResponseItem, re
218220
219221func getImageLocations (images * []types.ImageModel , imageName , imageTag string ) (location []realtimeengine.Location , filePath string ) {
220222 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
229225 }
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
230233 }
231234 return []realtimeengine.Location {}, ""
232235}
233236
237+ func isSameImage (curImage , imageName , imageTag string ) bool {
238+ return curImage == imageName + ":" + imageTag || curImage == imageName + "@" + imageTag || curImage == imageName && imageTag == defaultTag
239+ }
240+
234241// splitToImageAndTag splits the image string into name and tag components.
235242func splitToImageAndTag (image string ) (imageName , imageTag string ) {
236243 // Split the image string by the last colon to separate name and tag
237244 lastColonIndex := strings .LastIndex (image , ":" )
238245
239246 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"
241248 }
242249
243250 imageName = image [:lastColonIndex ]
0 commit comments