2021-08-06 13:40:23 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
2022-02-20 13:38:44 +00:00
|
|
|
"context"
|
2021-08-09 14:16:33 +00:00
|
|
|
"fmt"
|
|
|
|
|
2022-02-20 13:38:44 +00:00
|
|
|
"github.com/containers/image/docker"
|
|
|
|
"github.com/containers/image/types"
|
2021-08-10 10:21:42 +00:00
|
|
|
"github.com/docker/distribution/reference"
|
2021-08-06 13:40:23 +00:00
|
|
|
)
|
|
|
|
|
2022-02-20 13:38:44 +00:00
|
|
|
// GetRegistryTags retrieves all tags of an image from a container registry.
|
|
|
|
func GetRegistryTags(img reference.Named) ([]string, error) {
|
|
|
|
var tags []string
|
2021-12-26 02:44:29 +00:00
|
|
|
|
2022-02-20 13:38:44 +00:00
|
|
|
ref, err := docker.ParseReference(fmt.Sprintf("//%s", img))
|
2021-08-10 10:21:42 +00:00
|
|
|
if err != nil {
|
2022-02-20 13:38:44 +00:00
|
|
|
return tags, fmt.Errorf("failed to parse image %s, saw: %s", img, err.Error())
|
2021-12-26 02:44:29 +00:00
|
|
|
}
|
|
|
|
|
2022-02-20 13:38:44 +00:00
|
|
|
ctx := context.Background()
|
|
|
|
tags, err = docker.GetRepositoryTags(ctx, &types.SystemContext{}, ref)
|
2021-08-10 10:21:42 +00:00
|
|
|
if err != nil {
|
2022-02-20 13:38:44 +00:00
|
|
|
return tags, err
|
2021-08-10 10:21:42 +00:00
|
|
|
}
|
|
|
|
|
2022-02-20 13:38:44 +00:00
|
|
|
return tags, nil
|
2021-08-10 10:21:42 +00:00
|
|
|
}
|