@@ -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,21 +220,22 @@ 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 isSameImage (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
225+ }
226+ location := convertLocations (& img .ImageLocations )
227+ filePath := ""
228+ if len (img .ImageLocations ) > 0 {
229+ filePath = img .ImageLocations [0 ].Path
229230 }
231+ * images = append ((* images )[:i ], (* images )[i + 1 :]... )
232+ return location , filePath
230233 }
231234 return []realtimeengine.Location {}, ""
232235}
233236
234237func isSameImage (curImage , imageName , imageTag string ) bool {
235- return curImage == imageName + ":" + imageTag || curImage == imageName + "@" + imageTag || curImage == imageName && imageTag == "latest"
238+ return curImage == imageName + ":" + imageTag || curImage == imageName + "@" + imageTag || curImage == imageName && imageTag == defaultTag
236239}
237240
238241// splitToImageAndTag splits the image string into name and tag components.
@@ -241,7 +244,7 @@ func splitToImageAndTag(image string) (imageName, imageTag string) {
241244 lastColonIndex := strings .LastIndex (image , ":" )
242245
243246 if lastColonIndex == len (image )- 1 || lastColonIndex == - 1 {
244- return image , "latest" // No tag specified, default to "latest"
247+ return image , defaultTag // No tag specified, default to "latest"
245248 }
246249
247250 imageName = image [:lastColonIndex ]
0 commit comments