From 03b5a053ea0e00414fb90bc567ceacb3157eab11 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Wed, 29 Jul 2020 23:01:36 -0700 Subject: [PATCH] remotes: mark GetTokenScopes public MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Authorizer interface can’t be really implemented because scopes are passed in on a side channel via private value in context. Signed-off-by: Tonis Tiigi --- remotes/docker/authorizer.go | 2 +- remotes/docker/scope.go | 4 ++-- remotes/docker/scope_test.go | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/remotes/docker/authorizer.go b/remotes/docker/authorizer.go index 59d989eff..001423a0d 100644 --- a/remotes/docker/authorizer.go +++ b/remotes/docker/authorizer.go @@ -273,7 +273,7 @@ func (ah *authHandler) doBearerAuth(ctx context.Context) (string, error) { // copy common tokenOptions to := ah.common - to.scopes = getTokenScopes(ctx, to.scopes) + to.scopes = GetTokenScopes(ctx, to.scopes) // Docs: https://docs.docker.com/registry/spec/auth/scope scoped := strings.Join(to.scopes, " ") diff --git a/remotes/docker/scope.go b/remotes/docker/scope.go index fa8401433..c8541c455 100644 --- a/remotes/docker/scope.go +++ b/remotes/docker/scope.go @@ -72,8 +72,8 @@ func contextWithAppendPullRepositoryScope(ctx context.Context, repo string) cont return WithScope(ctx, fmt.Sprintf("repository:%s:pull", repo)) } -// getTokenScopes returns deduplicated and sorted scopes from ctx.Value(tokenScopesKey{}) and common scopes. -func getTokenScopes(ctx context.Context, common []string) []string { +// GetTokenScopes returns deduplicated and sorted scopes from ctx.Value(tokenScopesKey{}) and common scopes. +func GetTokenScopes(ctx context.Context, common []string) []string { var scopes []string if x := ctx.Value(tokenScopesKey{}); x != nil { scopes = append(scopes, x.([]string)...) diff --git a/remotes/docker/scope_test.go b/remotes/docker/scope_test.go index e9995a6a4..ea6ade963 100644 --- a/remotes/docker/scope_test.go +++ b/remotes/docker/scope_test.go @@ -91,7 +91,7 @@ func TestGetTokenScopes(t *testing.T) { } for _, tc := range testCases { ctx := context.WithValue(context.TODO(), tokenScopesKey{}, tc.scopesInCtx) - actual := getTokenScopes(ctx, tc.commonScopes) + actual := GetTokenScopes(ctx, tc.commonScopes) assert.DeepEqual(t, tc.expected, actual) } } @@ -101,7 +101,7 @@ func TestCustomScope(t *testing.T) { ctx := WithScope(context.Background(), scope) ctx = contextWithAppendPullRepositoryScope(ctx, "foo/bar") - scopes := getTokenScopes(ctx, []string{}) + scopes := GetTokenScopes(ctx, []string{}) assert.Assert(t, cmp.Len(scopes, 2)) assert.Check(t, cmp.Equal(scopes[0], "repository:foo/bar:pull")) assert.Check(t, cmp.Equal(scopes[1], scope))