Skip to content

Commit 3872f9b

Browse files
committed
fix: Do NOT require list permissions on a single set of tags
1 parent 557e38b commit 3872f9b

File tree

4 files changed

+31
-6
lines changed

4 files changed

+31
-6
lines changed

api/v1/registry/client/client.go

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func (cli *RegistryClient) IsLoggedIn() bool {
157157
return cli.Token != nil
158158
}
159159

160-
func decodeTagData(body io.ReadCloser) ([]string, map[string]manifest.Manifest, error) {
160+
func decodeAllTagData(body io.ReadCloser) ([]string, map[string]manifest.Manifest, error) {
161161
tagData := struct {
162162
TagNames []string `json:"tags"`
163163
RawManifests map[string]manifest.Raw `json:"manifest,omitempty"`
@@ -204,8 +204,21 @@ func (cli *RegistryClient) repoToken(repoPath string) (auth.Token, error) {
204204
return cli.RepoTokens[repoPath], nil
205205
}
206206

207-
// TagData gets list of all tag names and all additional data for the repository path specified
208-
func (cli *RegistryClient) TagData(repoPath string) ([]string, map[string]manifest.Manifest, error) {
207+
// TagData gets data of either all tags (list+get) or a set of single tags only (blind "get")
208+
func (cli *RegistryClient) TagData(
209+
repoPath string,
210+
isSingle bool,
211+
repoTags []string,
212+
) ([]string, map[string]manifest.Manifest, error) {
213+
if isSingle {
214+
return cli.SingleTagData(repoTags)
215+
}
216+
217+
return cli.AllTagData(repoPath)
218+
}
219+
220+
// AllTagData gets list of all tag names and all additional data for the repository path specified
221+
func (cli *RegistryClient) AllTagData(repoPath string) ([]string, map[string]manifest.Manifest, error) {
209222
repoToken, err := cli.repoToken(repoPath)
210223
if err != nil {
211224
return nil, nil, err
@@ -228,7 +241,7 @@ func (cli *RegistryClient) TagData(repoPath string) ([]string, map[string]manife
228241
return nil, nil, err
229242
}
230243

231-
tagNames, tagManifests, err := decodeTagData(resp.Body)
244+
tagNames, tagManifests, err := decodeAllTagData(resp.Body)
232245
if err != nil {
233246
return nil, nil, err
234247
}
@@ -246,6 +259,17 @@ func (cli *RegistryClient) TagData(repoPath string) ([]string, map[string]manife
246259
return allTagNames, allTagManifests, nil
247260
}
248261

262+
// SingleTagData gets data for a set of single tags
263+
func (cli *RegistryClient) SingleTagData(repoTags []string) ([]string, map[string]manifest.Manifest, error) {
264+
tagManifests := make(map[string]manifest.Manifest)
265+
266+
for _, tagName := range repoTags {
267+
tagManifests[tagName] = manifest.Manifest{}
268+
}
269+
270+
return repoTags, tagManifests, nil
271+
}
272+
249273
func (cli *RegistryClient) tagDigest(repoPath, tagName string) (string, error) {
250274
repoToken, err := cli.repoToken(repoPath)
251275
if err != nil {

repository/repository.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ func ParseRef(ref string) (*Repository, error) {
263263
refParts := strings.Split(fullRef, "=")
264264
fullRepo = refParts[0]
265265
repoTags = strings.Split(refParts[1], ",")
266+
isSingle = true
266267
case refWithFilter:
267268
refParts := strings.Split(fullRef, "~")
268269
fullRepo = refParts[0]

repository/repository_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func TestParseRef(t *testing.T) {
2727
"localhost:5000/nada/mindundi": {"localhost:5000", false, "localhost:5000/nada/mindundi", "localhost:5000/nada/mindundi", "nada/mindundi", []string{}, ".*", "http://", false, true},
2828
"localhost:7eff/nada/mindundi": {"", true, "", "", "", []string{}, "", "", false, false},
2929
"quay.io/coreos/awscli:master": {"quay.io", false, "quay.io/coreos/awscli", "quay.io/coreos/awscli", "coreos/awscli", []string{"master"}, "", "https://", true, true},
30-
"registry.org/some/repo=latest,stable": {"registry.org", false, "registry.org/some/repo", "registry.org/some/repo", "some/repo", []string{"latest", "stable"}, "", "https://", false, true},
30+
"registry.org/some/repo=latest,stable": {"registry.org", false, "registry.org/some/repo", "registry.org/some/repo", "some/repo", []string{"latest", "stable"}, "", "https://", true, true},
3131
"registry.org/some/repo=lat!st,stable": {"", true, "", "", "", []string{}, "", "", false, false},
3232
"registry.org/some/repo~/^v1/": {"registry.org", false, "registry.org/some/repo", "registry.org/some/repo", "some/repo", []string{}, "^v1", "https://", false, true},
3333
"registry.org/some/repo~|^v1|": {"", true, "", "", "", []string{}, "", "", false, false},

tag/remote/remote.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func FetchTags(repo *repository.Repository, username, password string) (map[stri
6666
return nil, err
6767
}
6868

69-
allTagNames, allTagManifests, err := cli.TagData(repo.Path())
69+
allTagNames, allTagManifests, err := cli.TagData(repo.Path(), repo.IsSingle(), repo.Tags())
7070
if err != nil {
7171
return nil, err
7272
}

0 commit comments

Comments
 (0)