MCPcopy
hub / github.com/containerd/containerd / GetTokenScopes

Function GetTokenScopes

core/remotes/docker/scope.go:76–101  ·  view source on GitHub ↗

GetTokenScopes returns deduplicated and sorted scopes from ctx.Value(tokenScopesKey{}) and common scopes.

(ctx context.Context, common []string)

Source from the content-addressed store, hash-verified

74
75// GetTokenScopes returns deduplicated and sorted scopes from ctx.Value(tokenScopesKey{}) and common scopes.
76func GetTokenScopes(ctx context.Context, common []string) []string {
77 scopes := []string{}
78 if x := ctx.Value(tokenScopesKey{}); x != nil {
79 scopes = append(scopes, x.([]string)...)
80 }
81
82 scopes = append(scopes, common...)
83 sort.Strings(scopes)
84
85 if len(scopes) == 0 {
86 return scopes
87 }
88
89 l := 0
90 for idx := 1; idx < len(scopes); idx++ {
91 // Note: this comparison is unaware of the scope grammar (https://distribution.github.io/distribution/spec/auth/scope/)
92 // So, "repository:foo/bar:pull,push" != "repository:foo/bar:push,pull", although semantically they are equal.
93 if scopes[l] == scopes[idx] {
94 continue
95 }
96
97 l++
98 scopes[l] = scopes[idx]
99 }
100 return scopes[:l+1]
101}

Callers 3

doBearerAuthMethod · 0.85
TestGetTokenScopesFunction · 0.85
TestCustomScopeFunction · 0.85

Calls

no outgoing calls

Tested by 2

TestGetTokenScopesFunction · 0.68
TestCustomScopeFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…