GetTokenScopes returns deduplicated and sorted scopes from ctx.Value(tokenScopesKey{}) and common scopes.
(ctx context.Context, common []string)
| 74 | |
| 75 | // GetTokenScopes returns deduplicated and sorted scopes from ctx.Value(tokenScopesKey{}) and common scopes. |
| 76 | func 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 | } |
no outgoing calls
searching dependent graphs…