|
1 | 1 | package registry
|
2 | 2 |
|
3 |
| -import "context" |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "net/url" |
| 6 | + |
| 7 | + "github.com/peterhellberg/link" |
| 8 | +) |
4 | 9 |
|
5 | 10 | type tagsResponse struct {
|
6 | 11 | Tags []string `json:"tags"`
|
7 | 12 | }
|
8 | 13 |
|
9 |
| -// Tags returns the tags for a specific repository. |
10 |
| -func (r *Registry) Tags(ctx context.Context, repository string) ([]string, error) { |
11 |
| - url := r.url("/v2/%s/tags/list", repository) |
12 |
| - r.Logf("registry.tags url=%s repository=%s", url, repository) |
| 14 | +func (r *Registry) tags(ctx context.Context, u string, repository string) ([]string, error) { |
| 15 | + var uri string |
| 16 | + if u == "" { |
| 17 | + r.Logf("registry.tags url=%s repository=%s", u, repository) |
| 18 | + uri = r.url("/v2/%s/tags/list", repository) |
| 19 | + } else { |
| 20 | + uri = r.url(u) |
| 21 | + } |
13 | 22 |
|
14 | 23 | var response tagsResponse
|
15 |
| - if _, err := r.getJSON(ctx, url, &response); err != nil { |
| 24 | + h, err := r.getJSON(ctx, uri, &response) |
| 25 | + if err != nil { |
16 | 26 | return nil, err
|
17 | 27 | }
|
18 | 28 |
|
| 29 | + for _, l := range link.ParseHeader(h) { |
| 30 | + if l.Rel == "next" { |
| 31 | + unescaped, _ := url.QueryUnescape(l.URI) |
| 32 | + tags, err := r.tags(ctx, unescaped, repository) |
| 33 | + if err != nil { |
| 34 | + return nil, err |
| 35 | + } |
| 36 | + response.Tags = append(response.Tags, tags...) |
| 37 | + } |
| 38 | + } |
| 39 | + |
19 | 40 | return response.Tags, nil
|
20 | 41 | }
|
| 42 | + |
| 43 | +// Tags returns the tags for a specific repository. |
| 44 | +func (r *Registry) Tags(ctx context.Context, repository string) ([]string, error) { |
| 45 | + return r.tags(ctx, "", repository) |
| 46 | +} |
0 commit comments