mirror of https://github.com/artifacthub/hub.git
Use credentials when listing repository tags (#2595)
Signed-off-by: Sergio Castaño Arteaga <tegioz@icloud.com>
This commit is contained in:
parent
660ae59327
commit
b42de22e3c
|
|
@ -148,28 +148,28 @@ func (c *SignatureChecker) HasCosignSignature(
|
|||
return true, nil
|
||||
}
|
||||
|
||||
// OCITagsGetter provides a mechanism to get all the version tags available for
|
||||
// TagsGetter provides a mechanism to get all the version tags available for
|
||||
// a given repository in a OCI registry. Tags that aren't valid semver versions
|
||||
// will be filtered out.
|
||||
type TagsGetter struct{}
|
||||
type TagsGetter struct {
|
||||
cfg *viper.Viper
|
||||
}
|
||||
|
||||
// TagsGetter creates a new TagsGetter instance.
|
||||
func NewTagsGetter(cfg *viper.Viper) *TagsGetter {
|
||||
return &TagsGetter{
|
||||
cfg: cfg,
|
||||
}
|
||||
}
|
||||
|
||||
// Tags returns a list with the tags available for the provided repository.
|
||||
func (tg *TagsGetter) Tags(ctx context.Context, r *hub.Repository, onlySemver bool) ([]string, error) {
|
||||
u := strings.TrimPrefix(r.URL, hub.RepositoryOCIPrefix)
|
||||
ociRepo, err := name.NewRepository(u)
|
||||
ref, err := name.ParseReference(strings.TrimPrefix(r.URL, hub.RepositoryOCIPrefix))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
options := []remote.Option{
|
||||
remote.WithContext(ctx),
|
||||
}
|
||||
if r.AuthUser != "" || r.AuthPass != "" {
|
||||
options = append(options, remote.WithAuth(&authn.Basic{
|
||||
Username: r.AuthUser,
|
||||
Password: r.AuthPass,
|
||||
}))
|
||||
}
|
||||
tags, err := remote.List(ociRepo, options...)
|
||||
options := PrepareRemoteOptions(ctx, tg.cfg, ref, r.AuthUser, r.AuthPass)
|
||||
tags, err := remote.List(ref.Context(), options...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ func NewManager(
|
|||
cfg: cfg,
|
||||
db: db,
|
||||
il: &HelmIndexLoader{},
|
||||
tg: &oci.TagsGetter{},
|
||||
tg: oci.NewTagsGetter(cfg),
|
||||
op: oci.NewPuller(cfg),
|
||||
az: az,
|
||||
hc: hc,
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ func NewTrackerSource(i *hub.TrackerSourceInput, opts ...func(s *TrackerSource))
|
|||
s.il = &repo.HelmIndexLoader{}
|
||||
}
|
||||
if s.tg == nil {
|
||||
s.tg = &oci.TagsGetter{}
|
||||
s.tg = oci.NewTagsGetter(i.Svc.Cfg)
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue