Jelajahi Sumber

Fix base.Dial is deprecated: Use DialContext instead

1.Change base.Dial to base.DailContext.
2.Remove proxyDialer that was previously used to configure a
net.Dialer to route proxy.Dialer which will route the connections
through the proxy using the connections through a SOCKS proxy.
SOCKS proxies are now supported by configuring only http.Transport.Proxy,
and no longer require changing http.Transport.Dial.

Signed-off-by: HuanHuan Ye <logindaveye@gmail.com>
HuanHuan Ye 5 tahun lalu
induk
melakukan
a57fd5488d
3 mengubah file dengan 6 tambahan dan 18 penghapusan
  1. 5 8
      distribution/registry.go
  2. 0 4
      hack/validate/golangci-lint.yml
  3. 1 6
      registry/registry.go

+ 5 - 8
distribution/registry.go

@@ -16,7 +16,6 @@ import (
 	"github.com/docker/docker/api/types"
 	"github.com/docker/docker/api/types"
 	"github.com/docker/docker/dockerversion"
 	"github.com/docker/docker/dockerversion"
 	"github.com/docker/docker/registry"
 	"github.com/docker/docker/registry"
-	"github.com/docker/go-connections/sockets"
 	ocispec "github.com/opencontainers/image-spec/specs-go/v1"
 	ocispec "github.com/opencontainers/image-spec/specs-go/v1"
 )
 )
 
 
@@ -56,7 +55,10 @@ func init() {
 // NewV2Repository returns a repository (v2 only). It creates an HTTP transport
 // NewV2Repository returns a repository (v2 only). It creates an HTTP transport
 // providing timeout settings and authentication support, and also verifies the
 // providing timeout settings and authentication support, and also verifies the
 // remote API version.
 // remote API version.
-func NewV2Repository(ctx context.Context, repoInfo *registry.RepositoryInfo, endpoint registry.APIEndpoint, metaHeaders http.Header, authConfig *types.AuthConfig, actions ...string) (repo distribution.Repository, foundVersion bool, err error) {
+func NewV2Repository(
+	ctx context.Context, repoInfo *registry.RepositoryInfo, endpoint registry.APIEndpoint,
+	metaHeaders http.Header, authConfig *types.AuthConfig, actions ...string,
+) (repo distribution.Repository, foundVersion bool, err error) {
 	repoName := repoInfo.Name.Name()
 	repoName := repoInfo.Name.Name()
 	// If endpoint does not support CanonicalName, use the RemoteName instead
 	// If endpoint does not support CanonicalName, use the RemoteName instead
 	if endpoint.TrimHostname {
 	if endpoint.TrimHostname {
@@ -72,18 +74,13 @@ func NewV2Repository(ctx context.Context, repoInfo *registry.RepositoryInfo, end
 	// TODO(dmcgowan): Call close idle connections when complete, use keep alive
 	// TODO(dmcgowan): Call close idle connections when complete, use keep alive
 	base := &http.Transport{
 	base := &http.Transport{
 		Proxy:               http.ProxyFromEnvironment,
 		Proxy:               http.ProxyFromEnvironment,
-		Dial:                direct.Dial,
+		DialContext:         direct.DialContext,
 		TLSHandshakeTimeout: 10 * time.Second,
 		TLSHandshakeTimeout: 10 * time.Second,
 		TLSClientConfig:     endpoint.TLSConfig,
 		TLSClientConfig:     endpoint.TLSConfig,
 		// TODO(dmcgowan): Call close idle connections when complete and use keep alive
 		// TODO(dmcgowan): Call close idle connections when complete and use keep alive
 		DisableKeepAlives: true,
 		DisableKeepAlives: true,
 	}
 	}
 
 
-	proxyDialer, err := sockets.DialerFromEnvironment(direct)
-	if err == nil {
-		base.Dial = proxyDialer.Dial
-	}
-
 	modifiers := registry.Headers(dockerversion.DockerUserAgent(ctx), metaHeaders)
 	modifiers := registry.Headers(dockerversion.DockerUserAgent(ctx), metaHeaders)
 	authTransport := transport.NewTransport(base, modifiers...)
 	authTransport := transport.NewTransport(base, modifiers...)
 
 

+ 0 - 4
hack/validate/golangci-lint.yml

@@ -46,10 +46,6 @@ issues:
     - text: "G202: SQL string concatenation"
     - text: "G202: SQL string concatenation"
       linters:
       linters:
         - gosec
         - gosec
-    # FIXME temporarily suppress these. See #39925
-    - text: "SA1019: base.Dial is deprecated"
-      linters:
-        - staticcheck
     # FIXME temporarily suppress these. See #39928
     # FIXME temporarily suppress these. See #39928
     - text: "SA1019: grpc.WithDialer is deprecated"
     - text: "SA1019: grpc.WithDialer is deprecated"
       linters:
       linters:

+ 1 - 6
registry/registry.go

@@ -14,7 +14,6 @@ import (
 	"time"
 	"time"
 
 
 	"github.com/docker/distribution/registry/client/transport"
 	"github.com/docker/distribution/registry/client/transport"
-	"github.com/docker/go-connections/sockets"
 	"github.com/docker/go-connections/tlsconfig"
 	"github.com/docker/go-connections/tlsconfig"
 	"github.com/sirupsen/logrus"
 	"github.com/sirupsen/logrus"
 )
 )
@@ -176,16 +175,12 @@ func NewTransport(tlsConfig *tls.Config) *http.Transport {
 
 
 	base := &http.Transport{
 	base := &http.Transport{
 		Proxy:               http.ProxyFromEnvironment,
 		Proxy:               http.ProxyFromEnvironment,
-		Dial:                direct.Dial,
+		DialContext:         direct.DialContext,
 		TLSHandshakeTimeout: 10 * time.Second,
 		TLSHandshakeTimeout: 10 * time.Second,
 		TLSClientConfig:     tlsConfig,
 		TLSClientConfig:     tlsConfig,
 		// TODO(dmcgowan): Call close idle connections when complete and use keep alive
 		// TODO(dmcgowan): Call close idle connections when complete and use keep alive
 		DisableKeepAlives: true,
 		DisableKeepAlives: true,
 	}
 	}
 
 
-	proxyDialer, err := sockets.DialerFromEnvironment(direct)
-	if err == nil {
-		base.Dial = proxyDialer.Dial
-	}
 	return base
 	return base
 }
 }