// cachedTransport reuses an underlying transport for the given round tripper based
// on the set of passed scopes. It will always return a transport that has at least the
// provided scope list.
cachedTransport reuses an underlying transport for the given round tripper based
on the set of passed scopes. It will always return a transport that has at least the
provided scope list.
// cachedTransport reuses an underlying transport for the given round tripper based // on the set of passed scopes . It will always return a transport that has at least the // provided scope list .
func (c *Context) cachedTransport(rt http.RoundTripper, scopes []auth.Scope) http.RoundTripper {
	scopeNames := make(map[string]struct{})
	for _, scope := range scopes {
		scopeNames[scope.String()] = struct{}{}
	}
	c.lock.Lock()
	defer c.lock.Unlock()
	for _, c := range c.cachedTransports {
		if c.rt == rt && hasAll(c.scopes, scopeNames) {
			return c.transport
		}
	}
	names := make([]string, 0, len(scopeNames))
	for s := range scopeNames {
		names = append(names, s)
	}
	sort.Strings(names)
	scopes = make([]auth.Scope, 0, len(scopeNames))
	for _, s := range names {
		scopes = append(scopes, stringScope(s))
	}
	t := transport.NewTransport(
		rt,
		auth.NewAuthorizer(
			c.Challenges,
			auth.NewTokenHandlerWithOptions(auth.TokenHandlerOptions{
				Transport:   rt,
				Credentials: c.Credentials,
				Scopes:      scopes,
			}),
			auth.NewBasicHandler(c.Credentials),
		),
	)
	c.cachedTransports = append(c.cachedTransports, transportCache{
		rt:        rt,
		scopes:    scopeNames,
		transport: t,
	})
	return t
}
func ( c * Context ) cachedTransport ( rt http . RoundTripper , scopes [ ] auth . Scope ) http . RoundTripper { scopeNames := make ( map [ string ] struct { } ) for _ , scope := range scopes { scopeNames [ scope . String ( ) ] = struct { } { } } c . lock . Lock ( ) defer c . lock . Unlock ( ) for _ , c := range c . cachedTransports { if c . rt == rt && hasAll ( c . scopes , scopeNames ) { return c . transport } } names := make ( [ ] string , 0 , len ( scopeNames ) ) for s := range scopeNames { names = append ( names , s ) } sort . Strings ( names ) scopes = make ( [ ] auth . Scope , 0 , len ( scopeNames ) ) for _ , s := range names { scopes = append ( scopes , stringScope ( s ) ) } t := transport . NewTransport ( rt , auth . NewAuthorizer ( c . Challenges , auth . NewTokenHandlerWithOptions ( auth . TokenHandlerOptions { Transport : rt , Credentials : c . Credentials , Scopes : scopes , } ) , auth . NewBasicHandler ( c . Credentials ) , ) , ) c . cachedTransports = append ( c . cachedTransports , transportCache { rt : rt , scopes : scopeNames , transport : t , } ) return t }
cachedTransport reuses an underlying transport for the given round tripper based
on the set of passed scopes.
cachedTransport reuses an underlying transport for the given round tripper based on the set of passed scopes .
// avoid taking a dependency on kube sets.String for minimal dependencies // TODO: slightly smarter authorizer that retries unauthenticated requests // TODO: make multiple attempts if the first credential fails