Merge pull request #4436 from tonistiigi/tokenscopes-public
remotes: mark GetTokenScopes public
This commit is contained in:
commit
fa1220fce3
@ -273,7 +273,7 @@ func (ah *authHandler) doBearerAuth(ctx context.Context) (string, error) {
|
|||||||
// copy common tokenOptions
|
// copy common tokenOptions
|
||||||
to := ah.common
|
to := ah.common
|
||||||
|
|
||||||
to.scopes = getTokenScopes(ctx, to.scopes)
|
to.scopes = GetTokenScopes(ctx, to.scopes)
|
||||||
|
|
||||||
// Docs: https://docs.docker.com/registry/spec/auth/scope
|
// Docs: https://docs.docker.com/registry/spec/auth/scope
|
||||||
scoped := strings.Join(to.scopes, " ")
|
scoped := strings.Join(to.scopes, " ")
|
||||||
|
@ -72,8 +72,8 @@ func contextWithAppendPullRepositoryScope(ctx context.Context, repo string) cont
|
|||||||
return WithScope(ctx, fmt.Sprintf("repository:%s:pull", repo))
|
return WithScope(ctx, fmt.Sprintf("repository:%s:pull", repo))
|
||||||
}
|
}
|
||||||
|
|
||||||
// getTokenScopes returns deduplicated and sorted scopes from ctx.Value(tokenScopesKey{}) and common scopes.
|
// GetTokenScopes returns deduplicated and sorted scopes from ctx.Value(tokenScopesKey{}) and common scopes.
|
||||||
func getTokenScopes(ctx context.Context, common []string) []string {
|
func GetTokenScopes(ctx context.Context, common []string) []string {
|
||||||
var scopes []string
|
var scopes []string
|
||||||
if x := ctx.Value(tokenScopesKey{}); x != nil {
|
if x := ctx.Value(tokenScopesKey{}); x != nil {
|
||||||
scopes = append(scopes, x.([]string)...)
|
scopes = append(scopes, x.([]string)...)
|
||||||
|
@ -91,7 +91,7 @@ func TestGetTokenScopes(t *testing.T) {
|
|||||||
}
|
}
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
ctx := context.WithValue(context.TODO(), tokenScopesKey{}, tc.scopesInCtx)
|
ctx := context.WithValue(context.TODO(), tokenScopesKey{}, tc.scopesInCtx)
|
||||||
actual := getTokenScopes(ctx, tc.commonScopes)
|
actual := GetTokenScopes(ctx, tc.commonScopes)
|
||||||
assert.DeepEqual(t, tc.expected, actual)
|
assert.DeepEqual(t, tc.expected, actual)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -101,7 +101,7 @@ func TestCustomScope(t *testing.T) {
|
|||||||
ctx := WithScope(context.Background(), scope)
|
ctx := WithScope(context.Background(), scope)
|
||||||
ctx = contextWithAppendPullRepositoryScope(ctx, "foo/bar")
|
ctx = contextWithAppendPullRepositoryScope(ctx, "foo/bar")
|
||||||
|
|
||||||
scopes := getTokenScopes(ctx, []string{})
|
scopes := GetTokenScopes(ctx, []string{})
|
||||||
assert.Assert(t, cmp.Len(scopes, 2))
|
assert.Assert(t, cmp.Len(scopes, 2))
|
||||||
assert.Check(t, cmp.Equal(scopes[0], "repository:foo/bar:pull"))
|
assert.Check(t, cmp.Equal(scopes[0], "repository:foo/bar:pull"))
|
||||||
assert.Check(t, cmp.Equal(scopes[1], scope))
|
assert.Check(t, cmp.Equal(scopes[1], scope))
|
||||||
|
Loading…
Reference in New Issue
Block a user