in generatebundlefile/ecr.go [130:161]
func (c *ecrClient) tagFromSha(repository, sha, substringTag string) (string, error) {
if repository == "" || sha == "" {
return "", fmt.Errorf("empty repository, or sha passed to the function")
}
var imagelookup []ecrtypes.ImageIdentifier
imagelookup = append(imagelookup, ecrtypes.ImageIdentifier{ImageDigest: &sha})
BundleLog.Info("Looking up ECR for image SHA", "Repository", repository)
ImageDetails, err := c.Describe(&ecr.DescribeImagesInput{
RepositoryName: aws.String(repository),
ImageIds: imagelookup,
})
if err != nil {
if strings.Contains(err.Error(), "does not exist within the repository") {
return "", nil
} else {
return "", fmt.Errorf("looking up image details %v", err)
}
}
for _, detail := range ImageDetails {
// We can return the first tag for an image, if it has multiple tags
if len(detail.ImageTags) > 0 {
detail.ImageTags = removeStringSlice(detail.ImageTags, "latest")
for j, tag := range detail.ImageTags {
if strings.HasSuffix(tag, substringTag) {
return detail.ImageTags[j], nil
}
}
return detail.ImageTags[0], nil
}
}
return "", nil
}