diff --git a/pkg/v1/remote/catalog.go b/pkg/v1/remote/catalog.go index 2f9ee11db..eb4306f28 100644 --- a/pkg/v1/remote/catalog.go +++ b/pkg/v1/remote/catalog.go @@ -91,9 +91,10 @@ func Catalog(ctx context.Context, target name.Registry, options ...Option) ([]st Scheme: target.Scheme(), Host: target.RegistryStr(), Path: "/v2/_catalog", - // ECR returns an error if n > 1000: - // https://github.com/google/go-containerregistry/issues/1091 - RawQuery: "n=1000", + } + + if o.pageSize > 0 { + uri.RawQuery = fmt.Sprintf("n=%d", o.pageSize) } client := http.Client{Transport: tr} diff --git a/pkg/v1/remote/list.go b/pkg/v1/remote/list.go index 433ccd1e7..e643c49aa 100644 --- a/pkg/v1/remote/list.go +++ b/pkg/v1/remote/list.go @@ -55,9 +55,10 @@ func List(repo name.Repository, options ...Option) ([]string, error) { Scheme: repo.Registry.Scheme(), Host: repo.Registry.RegistryStr(), Path: fmt.Sprintf("/v2/%s/tags/list", repo.RepositoryStr()), - // ECR returns an error if n > 1000: - // https://github.com/google/go-containerregistry/issues/681 - RawQuery: "n=1000", + } + + if o.pageSize > 0 { + uri.RawQuery = fmt.Sprintf("n=%d", o.pageSize) } client := http.Client{Transport: tr} diff --git a/pkg/v1/remote/options.go b/pkg/v1/remote/options.go index 7edebdf77..6be4b666f 100644 --- a/pkg/v1/remote/options.go +++ b/pkg/v1/remote/options.go @@ -38,6 +38,7 @@ type options struct { userAgent string allowNondistributableArtifacts bool updates chan<- v1.Update + pageSize int } var defaultPlatform = v1.Platform{ @@ -45,7 +46,13 @@ var defaultPlatform = v1.Platform{ OS: "linux", } -const defaultJobs = 4 +const ( + defaultJobs = 4 + + // ECR returns an error if n > 1000: + // https://github.com/google/go-containerregistry/issues/1091 + defaultPageSize = 1000 +) func makeOptions(target authn.Resource, opts ...Option) (*options, error) { o := &options{ @@ -54,6 +61,7 @@ func makeOptions(target authn.Resource, opts ...Option) (*options, error) { platform: defaultPlatform, context: context.Background(), jobs: defaultJobs, + pageSize: defaultPageSize, } for _, option := range opts { @@ -193,3 +201,14 @@ func WithProgress(updates chan<- v1.Update) Option { return nil } } + +// WithPageSize sets the given size as the value of parameter 'n' in the request. +// +// To omit the `n` parameter entirely, use WithPageSize(0). +// The default value is 1000. +func WithPageSize(size int) Option { + return func(o *options) error { + o.pageSize = size + return nil + } +}