@@ -105,7 +105,7 @@ func parseContainersFile(filePath string) ([]types.ImageModel, error) {
105105 return nil , errors .Errorf ("directory does not exist: %s" , scanPath )
106106 }
107107
108- files , envVars , _ , err := extractor .ExtractFiles (scanPath )
108+ files , envVars , _ , err := extractor .ExtractFiles (scanPath , false )
109109 if err != nil {
110110 return nil , errors .Wrap (err , "error extracting files" )
111111 }
@@ -199,11 +199,14 @@ func (c *ContainersRealtimeService) buildContainerImageResults(responseImages, i
199199
200200func mergeImagesToResults (listOfImages []wrappers.ContainerImageResponseItem , result ContainerImageResults , images * []types.ImageModel , filePath string ) ContainerImageResults {
201201 for _ , respImg := range listOfImages {
202- locations := getImageLocations (images , respImg .ImageName , respImg .ImageTag )
202+ locations , specificFilePath := getImageLocations (images , respImg .ImageName , respImg .ImageTag )
203+ if specificFilePath == "" {
204+ specificFilePath = filePath
205+ }
203206 containerImage := ContainerImage {
204207 ImageName : respImg .ImageName ,
205208 ImageTag : respImg .ImageTag ,
206- FilePath : filePath ,
209+ FilePath : specificFilePath ,
207210 Locations : locations ,
208211 Status : respImg .Status ,
209212 Vulnerabilities : convertVulnerabilities (respImg .Vulnerabilities ),
@@ -213,23 +216,27 @@ func mergeImagesToResults(listOfImages []wrappers.ContainerImageResponseItem, re
213216 return result
214217}
215218
216- func getImageLocations (images * []types.ImageModel , imageName , imageTag string ) []realtimeengine.Location {
219+ func getImageLocations (images * []types.ImageModel , imageName , imageTag string ) ( location []realtimeengine.Location , filePath string ) {
217220 for i , img := range * images {
218221 if img .Name == imageName + ":" + imageTag || img .Name == imageName + "@" + imageTag {
219222 location := convertLocations (& img .ImageLocations )
223+ filePath := ""
224+ if len (img .ImageLocations ) > 0 {
225+ filePath = img .ImageLocations [0 ].Path
226+ }
220227 * images = append ((* images )[:i ], (* images )[i + 1 :]... )
221- return location
228+ return location , filePath
222229 }
223230 }
224- return []realtimeengine.Location {}
231+ return []realtimeengine.Location {}, ""
225232}
226233
227234// splitToImageAndTag splits the image string into name and tag components.
228235func splitToImageAndTag (image string ) (imageName , imageTag string ) {
229236 // Split the image string by the last colon to separate name and tag
230237 lastColonIndex := strings .LastIndex (image , ":" )
231238
232- if lastColonIndex == len (image )- 1 {
239+ if lastColonIndex == len (image )- 1 || lastColonIndex == - 1 {
233240 return image , "latest" // No tag specified, default to "latest"
234241 }
235242
0 commit comments