MCPcopy Create free account
hub / github.com/docker/cli / getHTTPTransport

Function getHTTPTransport

internal/registryclient/endpoint.go:68–100  ·  view source on GitHub ↗

getHTTPTransport builds a transport for use in communicating with a registry

(authConfig registrytypes.AuthConfig, endpoint registry.APIEndpoint, repoName, userAgent string, actions []string)

Source from the content-addressed store, hash-verified

66
67// getHTTPTransport builds a transport for use in communicating with a registry
68func getHTTPTransport(authConfig registrytypes.AuthConfig, endpoint registry.APIEndpoint, repoName, userAgent string, actions []string) (http.RoundTripper, error) {
69 // get the http transport, this will be used in a client to upload manifest
70 base := &http.Transport{
71 Proxy: http.ProxyFromEnvironment,
72 Dial: (&net.Dialer{
73 Timeout: 30 * time.Second,
74 KeepAlive: 30 * time.Second,
75 }).Dial,
76 TLSHandshakeTimeout: 10 * time.Second,
77 TLSClientConfig: endpoint.TLSConfig,
78 DisableKeepAlives: true,
79 }
80
81 modifiers := registry.Headers(userAgent, http.Header{})
82 authTransport := transport.NewTransport(base, modifiers...)
83 challengeManager, err := registry.PingV2Registry(endpoint.URL, authTransport)
84 if err != nil {
85 return nil, fmt.Errorf("error pinging v2 registry: %w", err)
86 }
87 if authConfig.RegistryToken != "" {
88 passThruTokenHandler := &existingTokenHandler{token: authConfig.RegistryToken}
89 modifiers = append(modifiers, auth.NewAuthorizer(challengeManager, passThruTokenHandler))
90 } else {
91 if len(actions) == 0 {
92 actions = []string{"pull"}
93 }
94 creds := &staticCredentialStore{authConfig: &authConfig}
95 tokenHandler := auth.NewTokenHandler(authTransport, creds, repoName, actions...)
96 basicHandler := auth.NewBasicHandler(creds)
97 modifiers = append(modifiers, auth.NewAuthorizer(challengeManager, tokenHandler, basicHandler))
98 }
99 return transport.NewTransport(base, modifiers...), nil
100}
101
102type existingTokenHandler struct {
103 token string

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…