Skip to content

Commit cc3b49a

Browse files
authored
Merge pull request #228 from ivanilves/ISSUE-222
fix: Do NOT require list permissions on a single set of tags
2 parents 0c09910 + 3872f9b commit cc3b49a

File tree

4 files changed

+31
-8
lines changed

4 files changed

+31
-8
lines changed

api/v1/registry/client/client.go

Lines changed: 28 additions & 6 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"`
@@ -172,8 +172,6 @@ func decodeTagData(body io.ReadCloser) ([]string, map[string]manifest.Manifest,
172172
return nil, nil, err
173173
}
174174

175-
tagManifests = manifest.MapByTag(tagManifests)
176-
177175
return tagData.TagNames, manifest.MapByTag(tagManifests), nil
178176
}
179177

@@ -206,8 +204,21 @@ func (cli *RegistryClient) repoToken(repoPath string) (auth.Token, error) {
206204
return cli.RepoTokens[repoPath], nil
207205
}
208206

209-
// TagData gets list of all tag names and all additional data for the repository path specified
210-
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) {
211222
repoToken, err := cli.repoToken(repoPath)
212223
if err != nil {
213224
return nil, nil, err
@@ -230,7 +241,7 @@ func (cli *RegistryClient) TagData(repoPath string) ([]string, map[string]manife
230241
return nil, nil, err
231242
}
232243

233-
tagNames, tagManifests, err := decodeTagData(resp.Body)
244+
tagNames, tagManifests, err := decodeAllTagData(resp.Body)
234245
if err != nil {
235246
return nil, nil, err
236247
}
@@ -248,6 +259,17 @@ func (cli *RegistryClient) TagData(repoPath string) ([]string, map[string]manife
248259
return allTagNames, allTagManifests, nil
249260
}
250261

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+
251273
func (cli *RegistryClient) tagDigest(repoPath, tagName string) (string, error) {
252274
repoToken, err := cli.repoToken(repoPath)
253275
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)