소스 검색

Merge pull request #2827 from smallstep/mariano/lint

Remove http2.Transport support from ca.Client
Mariano Cano 1 개월 전
부모
커밋
7c07d21b1c
1개의 변경된 파일과 14개의 추가작업 그리고 36개의 파일을 삭제
  1. 14 36
      ca/client.go

+ 14 - 36
ca/client.go

@@ -25,7 +25,6 @@ import (
 	"time"
 
 	"github.com/pkg/errors"
-	"golang.org/x/net/http2"
 	"google.golang.org/protobuf/encoding/protojson"
 	"google.golang.org/protobuf/proto"
 
@@ -251,30 +250,19 @@ func (o *clientOptions) getTransport(endpoint string) (tr http.RoundTripper, err
 
 	// Add client certificate if available
 	if o.certificate.Certificate != nil {
-		switch tr := tr.(type) {
-		case *http.Transport:
-			if tr.TLSClientConfig == nil {
-				tr.TLSClientConfig = &tls.Config{
-					MinVersion: tls.VersionTLS12,
-				}
-			}
-			if len(tr.TLSClientConfig.Certificates) == 0 && tr.TLSClientConfig.GetClientCertificate == nil {
-				tr.TLSClientConfig.Certificates = []tls.Certificate{o.certificate}
-				tr.TLSClientConfig.GetClientCertificate = o.getClientCertificate
-			}
-		case *http2.Transport:
-			if tr.TLSClientConfig == nil {
-				tr.TLSClientConfig = &tls.Config{
-					MinVersion: tls.VersionTLS12,
-				}
-			}
-			if len(tr.TLSClientConfig.Certificates) == 0 && tr.TLSClientConfig.GetClientCertificate == nil {
-				tr.TLSClientConfig.Certificates = []tls.Certificate{o.certificate}
-				tr.TLSClientConfig.GetClientCertificate = o.getClientCertificate
-			}
-		default:
+		t, ok := tr.(*http.Transport)
+		if !ok {
 			return nil, errors.Errorf("unsupported transport type %T", tr)
 		}
+		if t.TLSClientConfig == nil {
+			t.TLSClientConfig = &tls.Config{
+				MinVersion: tls.VersionTLS12,
+			}
+		}
+		if len(t.TLSClientConfig.Certificates) == 0 && t.TLSClientConfig.GetClientCertificate == nil {
+			t.TLSClientConfig.Certificates = []tls.Certificate{o.certificate}
+			t.TLSClientConfig.GetClientCertificate = o.getClientCertificate
+		}
 	}
 
 	// Wrap the transport using the decorator function if necessary
@@ -637,20 +625,10 @@ func (c *Client) GetCaURL() string {
 // GetRootCAs returns the RootCAs certificate pool from the configured
 // transport.
 func (c *Client) GetRootCAs() *x509.CertPool {
-	switch t := c.client.GetTransport().(type) {
-	case *http.Transport:
-		if t.TLSClientConfig != nil {
-			return t.TLSClientConfig.RootCAs
-		}
-		return nil
-	case *http2.Transport:
-		if t.TLSClientConfig != nil {
-			return t.TLSClientConfig.RootCAs
-		}
-		return nil
-	default:
-		return nil
+	if t, ok := c.client.GetTransport().(*http.Transport); ok && t.TLSClientConfig != nil {
+		return t.TLSClientConfig.RootCAs
 	}
+	return nil
 }
 
 // SetTransport updates the transport of the internal HTTP client.