Skip to content

Commit

Permalink
feat: ensure only unique images are returned
Browse files Browse the repository at this point in the history
Signed-off-by: Bradley Jones <bradley.jones@anchore.com>
  • Loading branch information
bradleyjones committed Dec 21, 2022
1 parent be175cd commit 58d1628
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions ecg/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ func fetchImagesFromTasks(client *ecs.ECS, cluster string, tasks []*string) ([]i
return []inventory.ReportImage{}, err
}

images := []inventory.ReportImage{}
// build a map to ensure only unique images are returned
uniqueImages := make(map[string]inventory.ReportImage)

for r := range results.Tasks {
task := results.Tasks[r]
for c := range task.Containers {
Expand All @@ -160,12 +162,19 @@ func fetchImagesFromTasks(client *ecs.ECS, cluster string, tasks []*string) ([]i
if container.ImageDigest != nil {
digest = *container.ImageDigest
}
images = append(images, inventory.ReportImage{
uniqueName := fmt.Sprintf("%s@%s", *container.Image, digest)
uniqueImages[uniqueName] = inventory.ReportImage{
Tag: *container.Image,
RepoDigest: digest,
})
}
}
}

// convert map of unique images to a slice
images := []inventory.ReportImage{}
for _, image := range uniqueImages {
images = append(images, image)
}

return images, nil
}

0 comments on commit 58d1628

Please sign in to comment.