Skip to content

Commit 4b882eb

Browse files
committed
Export repository scope helper functions
`docker.Authorizer` requires library clients to configure scope via context. It is helpful for the clients to use the helper (currently private) functions for generating scope string and to use that function with the combination of other scope-related ones (e.g. `docker.WithScope`). Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
1 parent d852786 commit 4b882eb

File tree

5 files changed

+13
-13
lines changed

5 files changed

+13
-13
lines changed

remotes/docker/fetcher.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func (r dockerFetcher) Fetch(ctx context.Context, desc ocispec.Descriptor) (io.R
4545
return nil, errors.Wrap(errdefs.ErrNotFound, "no pull hosts")
4646
}
4747

48-
ctx, err := contextWithRepositoryScope(ctx, r.refspec, false)
48+
ctx, err := ContextWithRepositoryScope(ctx, r.refspec, false)
4949
if err != nil {
5050
return nil, err
5151
}

remotes/docker/pusher.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ type dockerPusher struct {
4545
}
4646

4747
func (p dockerPusher) Push(ctx context.Context, desc ocispec.Descriptor) (content.Writer, error) {
48-
ctx, err := contextWithRepositoryScope(ctx, p.refspec, true)
48+
ctx, err := ContextWithRepositoryScope(ctx, p.refspec, true)
4949
if err != nil {
5050
return nil, err
5151
}
@@ -130,7 +130,7 @@ func (p dockerPusher) Push(ctx context.Context, desc ocispec.Descriptor) (conten
130130
var resp *http.Response
131131
if fromRepo := selectRepositoryMountCandidate(p.refspec, desc.Annotations); fromRepo != "" {
132132
preq := requestWithMountFrom(req, desc.Digest.String(), fromRepo)
133-
pctx := contextWithAppendPullRepositoryScope(ctx, fromRepo)
133+
pctx := ContextWithAppendPullRepositoryScope(ctx, fromRepo)
134134

135135
// NOTE: the fromRepo might be private repo and
136136
// auth service still can grant token without error.

remotes/docker/resolver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ func (r *dockerResolver) Resolve(ctx context.Context, ref string) (string, ocisp
263263
return "", ocispec.Descriptor{}, errors.Wrap(errdefs.ErrNotFound, "no resolve hosts")
264264
}
265265

266-
ctx, err = contextWithRepositoryScope(ctx, refspec, false)
266+
ctx, err = ContextWithRepositoryScope(ctx, refspec, false)
267267
if err != nil {
268268
return "", ocispec.Descriptor{}, err
269269
}

remotes/docker/scope.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ import (
2626
"github.com/containerd/containerd/reference"
2727
)
2828

29-
// repositoryScope returns a repository scope string such as "repository:foo/bar:pull"
29+
// RepositoryScope returns a repository scope string such as "repository:foo/bar:pull"
3030
// for "host/foo/bar:baz".
3131
// When push is true, both pull and push are added to the scope.
32-
func repositoryScope(refspec reference.Spec, push bool) (string, error) {
32+
func RepositoryScope(refspec reference.Spec, push bool) (string, error) {
3333
u, err := url.Parse("dummy://" + refspec.Locator)
3434
if err != nil {
3535
return "", err
@@ -45,9 +45,9 @@ func repositoryScope(refspec reference.Spec, push bool) (string, error) {
4545
// value: []string (e.g. {"registry:foo/bar:pull"})
4646
type tokenScopesKey struct{}
4747

48-
// contextWithRepositoryScope returns a context with tokenScopesKey{} and the repository scope value.
49-
func contextWithRepositoryScope(ctx context.Context, refspec reference.Spec, push bool) (context.Context, error) {
50-
s, err := repositoryScope(refspec, push)
48+
// ContextWithRepositoryScope returns a context with tokenScopesKey{} and the repository scope value.
49+
func ContextWithRepositoryScope(ctx context.Context, refspec reference.Spec, push bool) (context.Context, error) {
50+
s, err := RepositoryScope(refspec, push)
5151
if err != nil {
5252
return nil, err
5353
}
@@ -66,9 +66,9 @@ func WithScope(ctx context.Context, scope string) context.Context {
6666
return context.WithValue(ctx, tokenScopesKey{}, scopes)
6767
}
6868

69-
// contextWithAppendPullRepositoryScope is used to append repository pull
69+
// ContextWithAppendPullRepositoryScope is used to append repository pull
7070
// scope into existing scopes indexed by the tokenScopesKey{}.
71-
func contextWithAppendPullRepositoryScope(ctx context.Context, repo string) context.Context {
71+
func ContextWithAppendPullRepositoryScope(ctx context.Context, repo string) context.Context {
7272
return WithScope(ctx, fmt.Sprintf("repository:%s:pull", repo))
7373
}
7474

remotes/docker/scope_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func TestRepositoryScope(t *testing.T) {
5050
}
5151
for _, x := range testCases {
5252
t.Run(x.refspec.String(), func(t *testing.T) {
53-
actual, err := repositoryScope(x.refspec, x.push)
53+
actual, err := RepositoryScope(x.refspec, x.push)
5454
assert.NilError(t, err)
5555
assert.Equal(t, x.expected, actual)
5656
})
@@ -99,7 +99,7 @@ func TestGetTokenScopes(t *testing.T) {
9999
func TestCustomScope(t *testing.T) {
100100
scope := "whatever:foo/bar:pull"
101101
ctx := WithScope(context.Background(), scope)
102-
ctx = contextWithAppendPullRepositoryScope(ctx, "foo/bar")
102+
ctx = ContextWithAppendPullRepositoryScope(ctx, "foo/bar")
103103

104104
scopes := GetTokenScopes(ctx, []string{})
105105
assert.Assert(t, cmp.Len(scopes, 2))

0 commit comments

Comments
 (0)