fix empty scopes return
Signed-off-by: ye.sijun <junnplus@gmail.com>
This commit is contained in:
parent
753f95e23f
commit
936faf9c98
@ -74,7 +74,7 @@ func ContextWithAppendPullRepositoryScope(ctx context.Context, repo string) cont
|
|||||||
|
|
||||||
// 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
|
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)...)
|
||||||
}
|
}
|
||||||
@ -82,6 +82,10 @@ func GetTokenScopes(ctx context.Context, common []string) []string {
|
|||||||
scopes = append(scopes, common...)
|
scopes = append(scopes, common...)
|
||||||
sort.Strings(scopes)
|
sort.Strings(scopes)
|
||||||
|
|
||||||
|
if len(scopes) == 0 {
|
||||||
|
return scopes
|
||||||
|
}
|
||||||
|
|
||||||
l := 0
|
l := 0
|
||||||
for idx := 1; idx < len(scopes); idx++ {
|
for idx := 1; idx < len(scopes); idx++ {
|
||||||
// Note: this comparison is unaware of the scope grammar (https://docs.docker.com/registry/spec/auth/scope/)
|
// Note: this comparison is unaware of the scope grammar (https://docs.docker.com/registry/spec/auth/scope/)
|
||||||
|
@ -63,6 +63,11 @@ func TestGetTokenScopes(t *testing.T) {
|
|||||||
commonScopes []string
|
commonScopes []string
|
||||||
expected []string
|
expected []string
|
||||||
}{
|
}{
|
||||||
|
{
|
||||||
|
scopesInCtx: []string{},
|
||||||
|
commonScopes: []string{},
|
||||||
|
expected: []string{},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
scopesInCtx: []string{},
|
scopesInCtx: []string{},
|
||||||
commonScopes: []string{"repository:foo/bar:pull"},
|
commonScopes: []string{"repository:foo/bar:pull"},
|
||||||
|
Loading…
Reference in New Issue
Block a user