Skip to content

Commit

Permalink
feat: ability to set page size for tags list and catalog calls (#1102)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-igrychev committed Aug 11, 2021
1 parent 54c3445 commit bcbf8d3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
7 changes: 4 additions & 3 deletions pkg/v1/remote/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
7 changes: 4 additions & 3 deletions pkg/v1/remote/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
21 changes: 20 additions & 1 deletion pkg/v1/remote/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,21 @@ type options struct {
userAgent string
allowNondistributableArtifacts bool
updates chan<- v1.Update
pageSize int
}

var defaultPlatform = v1.Platform{
Architecture: "amd64",
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{
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}
}

0 comments on commit bcbf8d3

Please sign in to comment.