Skip to content

Commit ba573ed

Browse files
Merge pull request #1240 from Checkmarx/feature/MiryamFoifer/DCDefaultLatestTag
Support Case For Default Latest Tag In Docker-Compose (AST-000)
2 parents 2ea7356 + bfc4c71 commit ba573ed

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

internal/services/realtimeengine/containersrealtime/containers-realtime.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
1921
type ContainersRealtimeService struct {
2022
JwtWrapper wrappers.JWTWrapper
@@ -218,26 +220,31 @@ func mergeImagesToResults(listOfImages []wrappers.ContainerImageResponseItem, re
218220

219221
func 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.
235242
func 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

Comments
 (0)