Skip to content

Commit 67cd926

Browse files
fixes for linter
1 parent 68dfa11 commit 67cd926

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

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

Lines changed: 13 additions & 10 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,21 +220,22 @@ 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 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

234237
func 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

Comments
 (0)