Skip to content

Commit e6fa97b

Browse files
committed
address comments
Signed-off-by: Lixia (Sylvia) Lei <lixlei@microsoft.com>
1 parent 56cc8e7 commit e6fa97b

File tree

4 files changed

+34
-34
lines changed

4 files changed

+34
-34
lines changed

content.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func TagN(ctx context.Context, target Target, srcReference string, dstReferences
9090
if err != nil {
9191
return ocispec.Descriptor{}, err
9292
}
93-
ctx = auth.AppendScopeHints(ctx, ref, auth.ActionPull, auth.ActionPush)
93+
ctx = auth.AppendRepositoryScope(ctx, ref, auth.ActionPull, auth.ActionPush)
9494
}
9595

9696
desc, contentBytes, err := FetchBytes(ctx, target, srcReference, FetchBytesOptions{
@@ -148,7 +148,7 @@ func Tag(ctx context.Context, target Target, src, dst string) (ocispec.Descripto
148148
if err != nil {
149149
return ocispec.Descriptor{}, err
150150
}
151-
ctx = auth.AppendScopeHints(ctx, ref, auth.ActionPull, auth.ActionPush)
151+
ctx = auth.AppendRepositoryScope(ctx, ref, auth.ActionPull, auth.ActionPush)
152152
}
153153
desc, rc, err := refFetcher.FetchReference(ctx, src)
154154
if err != nil {

registry/remote/auth/scope.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ func ScopeRepository(repository string, actions ...string) string {
5757
}, ":")
5858
}
5959

60-
// AppendScopeHints returns a new context containing scope hints for the auth
61-
// client to fetch bearer tokens with the given actions on the repository.
60+
// AppendRepositoryScope returns a new context containing scope hints for the
61+
// auth client to fetch bearer tokens with the given actions on the repository.
6262
// If called multiple times, the new scopes will be appended to the existing
6363
// scopes. The resulted scopes are de-duplicated.
6464
//
@@ -67,11 +67,11 @@ func ScopeRepository(repository string, actions ...string) string {
6767
// `repository:hello-world:pull`, and the auth client will fetch a token for
6868
// that challenge. Later, the POST request will return a challenge for scope
6969
// `repository:hello-world:push`, and the auth client will fetch a token for
70-
// that challenge again. By invoking AppendScopeHints with the actions
70+
// that challenge again. By invoking AppendRepositoryScope with the actions
7171
// [ActionPull] and [ActionPush] for the repository `hello-world`,
7272
// the auth client with cache is hinted to fetch a token via a single token
7373
// fetch request for all the HEAD, POST, PUT requests.
74-
func AppendScopeHints(ctx context.Context, ref registry.Reference, actions ...string) context.Context {
74+
func AppendRepositoryScope(ctx context.Context, ref registry.Reference, actions ...string) context.Context {
7575
if len(actions) == 0 {
7676
return ctx
7777
}
@@ -177,16 +177,16 @@ func getAllScopesForHost(ctx context.Context, host string) []string {
177177
scopes := GetScopesForHost(ctx, host)
178178
globalScopes := GetScopes(ctx)
179179

180-
switch {
181-
case len(scopes) == 0:
180+
if len(scopes) == 0 {
182181
return globalScopes
183-
case len(globalScopes) == 0:
182+
}
183+
if len(globalScopes) == 0 {
184184
return scopes
185-
default:
186-
// re-clean the scopes
187-
allScopes := append(scopes, globalScopes...)
188-
return CleanScopes(allScopes)
189185
}
186+
187+
// re-clean the scopes
188+
allScopes := append(scopes, globalScopes...)
189+
return CleanScopes(allScopes)
190190
}
191191

192192
// CleanScopes merges and sort the actions in ascending order if the scopes have

registry/remote/auth/scope_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ func TestWithScopeHints(t *testing.T) {
123123
want2 := []string{
124124
"repository:foo:push",
125125
}
126-
ctx = AppendScopeHints(ctx, ref1, ActionPull)
127-
ctx = AppendScopeHints(ctx, ref2, ActionPush)
126+
ctx = AppendRepositoryScope(ctx, ref1, ActionPull)
127+
ctx = AppendRepositoryScope(ctx, ref2, ActionPush)
128128
if got := GetScopesForHost(ctx, ref1.Host()); !reflect.DeepEqual(got, want1) {
129129
t.Errorf("GetScopesPerRegistry(WithScopeHints()) = %v, want %v", got, want1)
130130
}
@@ -149,8 +149,8 @@ func TestWithScopeHints(t *testing.T) {
149149
want2 = []string{
150150
"repository:foo:delete,push",
151151
}
152-
ctx = AppendScopeHints(ctx, ref1, scopes1...)
153-
ctx = AppendScopeHints(ctx, ref2, scopes2...)
152+
ctx = AppendRepositoryScope(ctx, ref1, scopes1...)
153+
ctx = AppendRepositoryScope(ctx, ref2, scopes2...)
154154
if got := GetScopesForHost(ctx, ref1.Host()); !reflect.DeepEqual(got, want1) {
155155
t.Errorf("GetScopesPerRegistry(WithScopeHints()) = %v, want %v", got, want1)
156156
}
@@ -159,8 +159,8 @@ func TestWithScopeHints(t *testing.T) {
159159
}
160160

161161
// append empty scopes
162-
ctx = AppendScopeHints(ctx, ref1)
163-
ctx = AppendScopeHints(ctx, ref2)
162+
ctx = AppendRepositoryScope(ctx, ref1)
163+
ctx = AppendRepositoryScope(ctx, ref2)
164164
if got := GetScopesForHost(ctx, ref1.Host()); !reflect.DeepEqual(got, want1) {
165165
t.Errorf("GetScopesPerRegistry(WithScopeHints()) = %v, want %v", got, want1)
166166
}

registry/remote/repository.go

+15-15
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ func (r *Repository) ParseReference(reference string) (registry.Reference, error
391391
// - https://github.com/opencontainers/distribution-spec/blob/v1.1.0-rc3/spec.md#content-discovery
392392
// - https://docs.docker.com/registry/spec/api/#tags
393393
func (r *Repository) Tags(ctx context.Context, last string, fn func(tags []string) error) error {
394-
ctx = auth.AppendScopeHints(ctx, r.Reference, auth.ActionPull)
394+
ctx = auth.AppendRepositoryScope(ctx, r.Reference, auth.ActionPull)
395395
url := buildRepositoryTagListURL(r.PlainHTTP, r.Reference)
396396
var err error
397397
for err == nil {
@@ -508,7 +508,7 @@ func (r *Repository) Referrers(ctx context.Context, desc ocispec.Descriptor, art
508508
func (r *Repository) referrersByAPI(ctx context.Context, desc ocispec.Descriptor, artifactType string, fn func(referrers []ocispec.Descriptor) error) error {
509509
ref := r.Reference
510510
ref.Reference = desc.Digest.String()
511-
ctx = auth.AppendScopeHints(ctx, ref, auth.ActionPull)
511+
ctx = auth.AppendRepositoryScope(ctx, ref, auth.ActionPull)
512512

513513
url := buildReferrersURL(r.PlainHTTP, ref, artifactType)
514514
var err error
@@ -642,7 +642,7 @@ func (r *Repository) pingReferrers(ctx context.Context) (bool, error) {
642642

643643
ref := r.Reference
644644
ref.Reference = zeroDigest
645-
ctx = auth.AppendScopeHints(ctx, ref, auth.ActionPull)
645+
ctx = auth.AppendRepositoryScope(ctx, ref, auth.ActionPull)
646646

647647
url := buildReferrersURL(r.PlainHTTP, ref, "")
648648
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
@@ -676,7 +676,7 @@ func (r *Repository) pingReferrers(ctx context.Context) (bool, error) {
676676
func (r *Repository) delete(ctx context.Context, target ocispec.Descriptor, isManifest bool) error {
677677
ref := r.Reference
678678
ref.Reference = target.Digest.String()
679-
ctx = auth.AppendScopeHints(ctx, ref, auth.ActionDelete)
679+
ctx = auth.AppendRepositoryScope(ctx, ref, auth.ActionDelete)
680680
buildURL := buildRepositoryBlobURL
681681
if isManifest {
682682
buildURL = buildRepositoryManifestURL
@@ -712,7 +712,7 @@ type blobStore struct {
712712
func (s *blobStore) Fetch(ctx context.Context, target ocispec.Descriptor) (rc io.ReadCloser, err error) {
713713
ref := s.repo.Reference
714714
ref.Reference = target.Digest.String()
715-
ctx = auth.AppendScopeHints(ctx, ref, auth.ActionPull)
715+
ctx = auth.AppendRepositoryScope(ctx, ref, auth.ActionPull)
716716
url := buildRepositoryBlobURL(s.repo.PlainHTTP, ref)
717717
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
718718
if err != nil {
@@ -754,12 +754,12 @@ func (s *blobStore) Fetch(ctx context.Context, target ocispec.Descriptor) (rc io
754754
func (s *blobStore) Mount(ctx context.Context, desc ocispec.Descriptor, fromRepo string, getContent func() (io.ReadCloser, error)) error {
755755
// pushing usually requires both pull and push actions.
756756
// Reference: https://github.com/distribution/distribution/blob/v2.7.1/registry/handlers/app.go#L921-L930
757-
ctx = auth.AppendScopeHints(ctx, s.repo.Reference, auth.ActionPull, auth.ActionPush)
757+
ctx = auth.AppendRepositoryScope(ctx, s.repo.Reference, auth.ActionPull, auth.ActionPush)
758758

759759
// We also need pull access to the source repo.
760760
fromRef := s.repo.Reference
761761
fromRef.Repository = fromRepo
762-
ctx = auth.AppendScopeHints(ctx, fromRef, auth.ActionPull)
762+
ctx = auth.AppendRepositoryScope(ctx, fromRef, auth.ActionPull)
763763

764764
url := buildRepositoryBlobMountURL(s.repo.PlainHTTP, s.repo.Reference, desc.Digest, fromRepo)
765765
req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, nil)
@@ -832,7 +832,7 @@ func (s *blobStore) Push(ctx context.Context, expected ocispec.Descriptor, conte
832832
// start an upload
833833
// pushing usually requires both pull and push actions.
834834
// Reference: https://github.com/distribution/distribution/blob/v2.7.1/registry/handlers/app.go#L921-L930
835-
ctx = auth.AppendScopeHints(ctx, s.repo.Reference, auth.ActionPull, auth.ActionPush)
835+
ctx = auth.AppendRepositoryScope(ctx, s.repo.Reference, auth.ActionPull, auth.ActionPush)
836836
url := buildRepositoryBlobUploadURL(s.repo.PlainHTTP, s.repo.Reference)
837837
req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, nil)
838838
if err != nil {
@@ -933,7 +933,7 @@ func (s *blobStore) Resolve(ctx context.Context, reference string) (ocispec.Desc
933933
if err != nil {
934934
return ocispec.Descriptor{}, err
935935
}
936-
ctx = auth.AppendScopeHints(ctx, ref, auth.ActionPull)
936+
ctx = auth.AppendRepositoryScope(ctx, ref, auth.ActionPull)
937937
url := buildRepositoryBlobURL(s.repo.PlainHTTP, ref)
938938
req, err := http.NewRequestWithContext(ctx, http.MethodHead, url, nil)
939939
if err != nil {
@@ -968,7 +968,7 @@ func (s *blobStore) FetchReference(ctx context.Context, reference string) (desc
968968
return ocispec.Descriptor{}, nil, err
969969
}
970970

971-
ctx = auth.AppendScopeHints(ctx, ref, auth.ActionPull)
971+
ctx = auth.AppendRepositoryScope(ctx, ref, auth.ActionPull)
972972
url := buildRepositoryBlobURL(s.repo.PlainHTTP, ref)
973973
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
974974
if err != nil {
@@ -1043,7 +1043,7 @@ type manifestStore struct {
10431043
func (s *manifestStore) Fetch(ctx context.Context, target ocispec.Descriptor) (rc io.ReadCloser, err error) {
10441044
ref := s.repo.Reference
10451045
ref.Reference = target.Digest.String()
1046-
ctx = auth.AppendScopeHints(ctx, ref, auth.ActionPull)
1046+
ctx = auth.AppendRepositoryScope(ctx, ref, auth.ActionPull)
10471047
url := buildRepositoryManifestURL(s.repo.PlainHTTP, ref)
10481048
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
10491049
if err != nil {
@@ -1169,7 +1169,7 @@ func (s *manifestStore) Resolve(ctx context.Context, reference string) (ocispec.
11691169
if err != nil {
11701170
return ocispec.Descriptor{}, err
11711171
}
1172-
ctx = auth.AppendScopeHints(ctx, ref, auth.ActionPull)
1172+
ctx = auth.AppendRepositoryScope(ctx, ref, auth.ActionPull)
11731173
url := buildRepositoryManifestURL(s.repo.PlainHTTP, ref)
11741174
req, err := http.NewRequestWithContext(ctx, http.MethodHead, url, nil)
11751175
if err != nil {
@@ -1201,7 +1201,7 @@ func (s *manifestStore) FetchReference(ctx context.Context, reference string) (d
12011201
return ocispec.Descriptor{}, nil, err
12021202
}
12031203

1204-
ctx = auth.AppendScopeHints(ctx, ref, auth.ActionPull)
1204+
ctx = auth.AppendRepositoryScope(ctx, ref, auth.ActionPull)
12051205
url := buildRepositoryManifestURL(s.repo.PlainHTTP, ref)
12061206
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
12071207
if err != nil {
@@ -1244,7 +1244,7 @@ func (s *manifestStore) Tag(ctx context.Context, desc ocispec.Descriptor, refere
12441244
return err
12451245
}
12461246

1247-
ctx = auth.AppendScopeHints(ctx, ref, auth.ActionPull, auth.ActionPush)
1247+
ctx = auth.AppendRepositoryScope(ctx, ref, auth.ActionPull, auth.ActionPush)
12481248
rc, err := s.Fetch(ctx, desc)
12491249
if err != nil {
12501250
return err
@@ -1269,7 +1269,7 @@ func (s *manifestStore) push(ctx context.Context, expected ocispec.Descriptor, c
12691269
ref.Reference = reference
12701270
// pushing usually requires both pull and push actions.
12711271
// Reference: https://github.com/distribution/distribution/blob/v2.7.1/registry/handlers/app.go#L921-L930
1272-
ctx = auth.AppendScopeHints(ctx, ref, auth.ActionPull, auth.ActionPush)
1272+
ctx = auth.AppendRepositoryScope(ctx, ref, auth.ActionPull, auth.ActionPush)
12731273
url := buildRepositoryManifestURL(s.repo.PlainHTTP, ref)
12741274
// unwrap the content for optimizations of built-in types.
12751275
body := ioutil.UnwrapNopCloser(content)

0 commit comments

Comments
 (0)