@@ -51,21 +51,27 @@ func contextWithRepositoryScope(ctx context.Context, refspec reference.Spec, pus
5151 if err != nil {
5252 return nil , err
5353 }
54- return context . WithValue (ctx , tokenScopesKey {}, [] string { s } ), nil
54+ return WithScope (ctx , s ), nil
5555}
5656
57- // contextWithAppendPullRepositoryScope is used to append repository pull
58- // scope into existing scopes indexed by the tokenScopesKey{}.
59- func contextWithAppendPullRepositoryScope (ctx context.Context , repo string ) context.Context {
57+ // WithScope appends a custom registry auth scope to the context.
58+ func WithScope (ctx context.Context , scope string ) context.Context {
6059 var scopes []string
61-
6260 if v := ctx .Value (tokenScopesKey {}); v != nil {
63- scopes = append (scopes , v .([]string )... )
61+ scopes = v .([]string )
62+ scopes = append (scopes , scope )
63+ } else {
64+ scopes = []string {scope }
6465 }
65- scopes = append (scopes , fmt .Sprintf ("repository:%s:pull" , repo ))
6666 return context .WithValue (ctx , tokenScopesKey {}, scopes )
6767}
6868
69+ // contextWithAppendPullRepositoryScope is used to append repository pull
70+ // scope into existing scopes indexed by the tokenScopesKey{}.
71+ func contextWithAppendPullRepositoryScope (ctx context.Context , repo string ) context.Context {
72+ return WithScope (ctx , fmt .Sprintf ("repository:%s:pull" , repo ))
73+ }
74+
6975// getTokenScopes returns deduplicated and sorted scopes from ctx.Value(tokenScopesKey{}) and common scopes.
7076func getTokenScopes (ctx context.Context , common []string ) []string {
7177 var scopes []string
0 commit comments