Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
"github.com/pkg/errors"
)

const defaultTag = "latest"

// ContainersRealtimeService is the service responsible for performing real-time container scanning.
type ContainersRealtimeService struct {
JwtWrapper wrappers.JWTWrapper
Expand Down Expand Up @@ -218,26 +220,31 @@ func mergeImagesToResults(listOfImages []wrappers.ContainerImageResponseItem, re

func getImageLocations(images *[]types.ImageModel, imageName, imageTag string) (location []realtimeengine.Location, filePath string) {
for i, img := range *images {
if img.Name == imageName+":"+imageTag || img.Name == imageName+"@"+imageTag {
location := convertLocations(&img.ImageLocations)
filePath := ""
if len(img.ImageLocations) > 0 {
filePath = img.ImageLocations[0].Path
}
*images = append((*images)[:i], (*images)[i+1:]...)
return location, filePath
if !isSameImage(img.Name, imageName, imageTag) {
continue
}
location := convertLocations(&img.ImageLocations)
filePath := ""
if len(img.ImageLocations) > 0 {
filePath = img.ImageLocations[0].Path
}
*images = append((*images)[:i], (*images)[i+1:]...)
return location, filePath
}
return []realtimeengine.Location{}, ""
}

func isSameImage(curImage, imageName, imageTag string) bool {
return curImage == imageName+":"+imageTag || curImage == imageName+"@"+imageTag || curImage == imageName && imageTag == defaultTag
}

// splitToImageAndTag splits the image string into name and tag components.
func splitToImageAndTag(image string) (imageName, imageTag string) {
// Split the image string by the last colon to separate name and tag
lastColonIndex := strings.LastIndex(image, ":")

if lastColonIndex == len(image)-1 || lastColonIndex == -1 {
return image, "latest" // No tag specified, default to "latest"
return image, defaultTag // No tag specified, default to "latest"
}

imageName = image[:lastColonIndex]
Expand Down
Loading