Browse code

Fix govet for go1.7

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>

Tonis Tiigi authored on 2016/09/03 10:27:20
Showing 13 changed files
... ...
@@ -132,7 +132,7 @@ func (cli *DockerCli) getNotaryRepository(repoInfo *registry.RepositoryInfo, aut
132 132
 		return nil, err
133 133
 	}
134 134
 
135
-	var cfg = tlsconfig.ClientDefault
135
+	var cfg = tlsconfig.ClientDefault()
136 136
 	cfg.InsecureSkipVerify = !repoInfo.Index.Secure
137 137
 
138 138
 	// Get certificate base directory
... ...
@@ -142,7 +142,7 @@ func (cli *DockerCli) getNotaryRepository(repoInfo *registry.RepositoryInfo, aut
142 142
 	}
143 143
 	logrus.Debugf("reading certificate directory: %s", certDir)
144 144
 
145
-	if err := registry.ReadCertsDirectory(&cfg, certDir); err != nil {
145
+	if err := registry.ReadCertsDirectory(cfg, certDir); err != nil {
146 146
 		return nil, err
147 147
 	}
148 148
 
... ...
@@ -154,7 +154,7 @@ func (cli *DockerCli) getNotaryRepository(repoInfo *registry.RepositoryInfo, aut
154 154
 			DualStack: true,
155 155
 		}).Dial,
156 156
 		TLSHandshakeTimeout: 10 * time.Second,
157
-		TLSClientConfig:     &cfg,
157
+		TLSClientConfig:     cfg,
158 158
 		DisableKeepAlives:   true,
159 159
 	}
160 160
 
... ...
@@ -214,7 +214,7 @@ func TestFrom(t *testing.T) {
214 214
 		}
215 215
 
216 216
 		if b.noBaseImage != true {
217
-			t.Fatalf("Image should not have any base image, got: %s", b.noBaseImage)
217
+			t.Fatalf("Image should not have any base image, got: %v", b.noBaseImage)
218 218
 		}
219 219
 	}
220 220
 }
... ...
@@ -64,7 +64,7 @@ clone git github.com/vdemeester/shakers 24d7f1d6a71aa5d9cbe7390e4afb66b7eef9e1b3
64 64
 clone git golang.org/x/net 2beffdc2e92c8a3027590f898fe88f69af48a3f8 https://github.com/tonistiigi/net.git
65 65
 clone git golang.org/x/sys eb2c74142fd19a79b3f237334c7384d5167b1b46 https://github.com/golang/sys.git
66 66
 clone git github.com/docker/go-units eb879ae3e2b84e2a142af415b679ddeda47ec71c
67
-clone git github.com/docker/go-connections fa2850ff103453a9ad190da0df0af134f0314b3d
67
+clone git github.com/docker/go-connections 988efe982fdecb46f01d53465878ff1f2ff411ce
68 68
 
69 69
 clone git github.com/docker/engine-api 8d8fffdf863b12d03c76abf6ca1377e6f8f4e549
70 70
 clone git github.com/RackSec/srslog 259aed10dfa74ea2961eddd1d9847619f6e98837
... ...
@@ -17,9 +17,9 @@ import (
17 17
 	"github.com/docker/docker/opts"
18 18
 	"github.com/docker/docker/pkg/integration/checker"
19 19
 	"github.com/docker/docker/pkg/ioutils"
20
-	"github.com/docker/docker/pkg/tlsconfig"
21 20
 	"github.com/docker/engine-api/types/events"
22 21
 	"github.com/docker/go-connections/sockets"
22
+	"github.com/docker/go-connections/tlsconfig"
23 23
 	"github.com/go-check/check"
24 24
 )
25 25
 
... ...
@@ -13,7 +13,7 @@ import (
13 13
 
14 14
 	"github.com/docker/docker/cliconfig"
15 15
 	"github.com/docker/docker/pkg/integration/checker"
16
-	"github.com/docker/docker/pkg/tlsconfig"
16
+	"github.com/docker/go-connections/tlsconfig"
17 17
 	"github.com/go-check/check"
18 18
 )
19 19
 
... ...
@@ -136,7 +136,7 @@ func newTestNotary(c *check.C) (*testNotary, error) {
136 136
 }
137 137
 
138 138
 func (t *testNotary) Ping() error {
139
-	tlsConfig := tlsconfig.ClientDefault
139
+	tlsConfig := tlsconfig.ClientDefault()
140 140
 	tlsConfig.InsecureSkipVerify = true
141 141
 	client := http.Client{
142 142
 		Transport: &http.Transport{
... ...
@@ -146,7 +146,7 @@ func (t *testNotary) Ping() error {
146 146
 				KeepAlive: 30 * time.Second,
147 147
 			}).Dial,
148 148
 			TLSHandshakeTimeout: 10 * time.Second,
149
-			TLSClientConfig:     &tlsConfig,
149
+			TLSClientConfig:     tlsConfig,
150 150
 		},
151 151
 	}
152 152
 	resp, err := client.Get(fmt.Sprintf("%s/v2/", notaryURL))
... ...
@@ -59,7 +59,7 @@ func TestFileSpecPlugin(t *testing.T) {
59 59
 		}
60 60
 
61 61
 		if p.name != c.name {
62
-			t.Fatalf("Expected plugin `%s`, got %s\n", c.name, p.Name)
62
+			t.Fatalf("Expected plugin `%s`, got %s\n", c.name, p.name)
63 63
 		}
64 64
 
65 65
 		if p.Addr != c.addr {
... ...
@@ -97,8 +97,8 @@ func TestFileJSONSpecPlugin(t *testing.T) {
97 97
 		t.Fatal(err)
98 98
 	}
99 99
 
100
-	if plugin.name != "example" {
101
-		t.Fatalf("Expected plugin `plugin-example`, got %s\n", plugin.Name)
100
+	if expected, actual := "example", plugin.name; expected != actual {
101
+		t.Fatalf("Expected plugin %q, got %s\n", expected, actual)
102 102
 	}
103 103
 
104 104
 	if plugin.Addr != "https://example.com/docker/plugin" {
... ...
@@ -138,8 +138,8 @@ func TestFileJSONSpecPluginWithoutTLSConfig(t *testing.T) {
138 138
 		t.Fatal(err)
139 139
 	}
140 140
 
141
-	if plugin.name != "example" {
142
-		t.Fatalf("Expected plugin `plugin-example`, got %s\n", plugin.Name)
141
+	if expected, actual := "example", plugin.name; expected != actual {
142
+		t.Fatalf("Expected plugin %q, got %s\n", expected, actual)
143 143
 	}
144 144
 
145 145
 	if plugin.Addr != "https://example.com/docker/plugin" {
... ...
@@ -46,7 +46,7 @@ func TestLocalSocket(t *testing.T) {
46 46
 		}
47 47
 
48 48
 		if p.name != "echo" {
49
-			t.Fatalf("Expected plugin `echo`, got %s\n", p.Name)
49
+			t.Fatalf("Expected plugin `echo`, got %s\n", p.name)
50 50
 		}
51 51
 
52 52
 		addr := fmt.Sprintf("unix://%s", c)
... ...
@@ -52,19 +52,23 @@ var clientCipherSuites = []uint16{
52 52
 // known weak algorithms removed.
53 53
 var DefaultServerAcceptedCiphers = append(clientCipherSuites, acceptedCBCCiphers...)
54 54
 
55
-// ServerDefault is a secure-enough TLS configuration for the server TLS configuration.
56
-var ServerDefault = tls.Config{
57
-	// Avoid fallback to SSL protocols < TLS1.0
58
-	MinVersion:               tls.VersionTLS10,
59
-	PreferServerCipherSuites: true,
60
-	CipherSuites:             DefaultServerAcceptedCiphers,
55
+// ServerDefault returns a secure-enough TLS configuration for the server TLS configuration.
56
+func ServerDefault() *tls.Config {
57
+	return &tls.Config{
58
+		// Avoid fallback to SSL protocols < TLS1.0
59
+		MinVersion:               tls.VersionTLS10,
60
+		PreferServerCipherSuites: true,
61
+		CipherSuites:             DefaultServerAcceptedCiphers,
62
+	}
61 63
 }
62 64
 
63
-// ClientDefault is a secure-enough TLS configuration for the client TLS configuration.
64
-var ClientDefault = tls.Config{
65
-	// Prefer TLS1.2 as the client minimum
66
-	MinVersion:   tls.VersionTLS12,
67
-	CipherSuites: clientCipherSuites,
65
+// ClientDefault returns a secure-enough TLS configuration for the client TLS configuration.
66
+func ClientDefault() *tls.Config {
67
+	return &tls.Config{
68
+		// Prefer TLS1.2 as the client minimum
69
+		MinVersion:   tls.VersionTLS12,
70
+		CipherSuites: clientCipherSuites,
71
+	}
68 72
 }
69 73
 
70 74
 // certPool returns an X.509 certificate pool from `caFile`, the certificate file.
... ...
@@ -78,20 +82,15 @@ func certPool(caFile string) (*x509.CertPool, error) {
78 78
 	if !certPool.AppendCertsFromPEM(pem) {
79 79
 		return nil, fmt.Errorf("failed to append certificates from PEM file: %q", caFile)
80 80
 	}
81
-	s := certPool.Subjects()
82
-	subjects := make([]string, len(s))
83
-	for i, subject := range s {
84
-		subjects[i] = string(subject)
85
-	}
86
-	logrus.Debugf("Trusting certs with subjects: %v", subjects)
81
+	logrus.Debugf("Trusting %d certs", len(certPool.Subjects()))
87 82
 	return certPool, nil
88 83
 }
89 84
 
90 85
 // Client returns a TLS configuration meant to be used by a client.
91 86
 func Client(options Options) (*tls.Config, error) {
92
-	tlsConfig := ClientDefault
87
+	tlsConfig := ClientDefault()
93 88
 	tlsConfig.InsecureSkipVerify = options.InsecureSkipVerify
94
-	if !options.InsecureSkipVerify {
89
+	if !options.InsecureSkipVerify && options.CAFile != "" {
95 90
 		CAs, err := certPool(options.CAFile)
96 91
 		if err != nil {
97 92
 			return nil, err
... ...
@@ -99,7 +98,7 @@ func Client(options Options) (*tls.Config, error) {
99 99
 		tlsConfig.RootCAs = CAs
100 100
 	}
101 101
 
102
-	if options.CertFile != "" && options.KeyFile != "" {
102
+	if options.CertFile != "" || options.KeyFile != "" {
103 103
 		tlsCert, err := tls.LoadX509KeyPair(options.CertFile, options.KeyFile)
104 104
 		if err != nil {
105 105
 			return nil, fmt.Errorf("Could not load X509 key pair: %v. Make sure the key is not encrypted", err)
... ...
@@ -107,12 +106,12 @@ func Client(options Options) (*tls.Config, error) {
107 107
 		tlsConfig.Certificates = []tls.Certificate{tlsCert}
108 108
 	}
109 109
 
110
-	return &tlsConfig, nil
110
+	return tlsConfig, nil
111 111
 }
112 112
 
113 113
 // Server returns a TLS configuration meant to be used by a server.
114 114
 func Server(options Options) (*tls.Config, error) {
115
-	tlsConfig := ServerDefault
115
+	tlsConfig := ServerDefault()
116 116
 	tlsConfig.ClientAuth = options.ClientAuth
117 117
 	tlsCert, err := tls.LoadX509KeyPair(options.CertFile, options.KeyFile)
118 118
 	if err != nil {
... ...
@@ -129,5 +128,5 @@ func Server(options Options) (*tls.Config, error) {
129 129
 		}
130 130
 		tlsConfig.ClientCAs = CAs
131 131
 	}
132
-	return &tlsConfig, nil
132
+	return tlsConfig, nil
133 133
 }
... ...
@@ -28,19 +28,19 @@ var (
28 28
 
29 29
 func newTLSConfig(hostname string, isSecure bool) (*tls.Config, error) {
30 30
 	// PreferredServerCipherSuites should have no effect
31
-	tlsConfig := tlsconfig.ServerDefault
31
+	tlsConfig := tlsconfig.ServerDefault()
32 32
 
33 33
 	tlsConfig.InsecureSkipVerify = !isSecure
34 34
 
35 35
 	if isSecure && CertsDir != "" {
36 36
 		hostDir := filepath.Join(CertsDir, cleanPath(hostname))
37 37
 		logrus.Debugf("hostDir: %s", hostDir)
38
-		if err := ReadCertsDirectory(&tlsConfig, hostDir); err != nil {
38
+		if err := ReadCertsDirectory(tlsConfig, hostDir); err != nil {
39 39
 			return nil, err
40 40
 		}
41 41
 	}
42 42
 
43
-	return &tlsConfig, nil
43
+	return tlsConfig, nil
44 44
 }
45 45
 
46 46
 func hasFile(files []os.FileInfo, name string) bool {
... ...
@@ -163,8 +163,7 @@ func addRequiredHeadersToRedirectedRequests(req *http.Request, via []*http.Reque
163 163
 // default TLS configuration.
164 164
 func NewTransport(tlsConfig *tls.Config) *http.Transport {
165 165
 	if tlsConfig == nil {
166
-		var cfg = tlsconfig.ServerDefault
167
-		tlsConfig = &cfg
166
+		tlsConfig = tlsconfig.ServerDefault()
168 167
 	}
169 168
 
170 169
 	direct := &net.Dialer{
... ...
@@ -7,8 +7,7 @@ import (
7 7
 )
8 8
 
9 9
 func (s *DefaultService) lookupV1Endpoints(hostname string) (endpoints []APIEndpoint, err error) {
10
-	var cfg = tlsconfig.ServerDefault
11
-	tlsConfig := &cfg
10
+	tlsConfig := tlsconfig.ServerDefault()
12 11
 	if hostname == DefaultNamespace {
13 12
 		endpoints = append(endpoints, APIEndpoint{
14 13
 			URL:          DefaultV1Registry,
... ...
@@ -8,8 +8,7 @@ import (
8 8
 )
9 9
 
10 10
 func (s *DefaultService) lookupV2Endpoints(hostname string) (endpoints []APIEndpoint, err error) {
11
-	var cfg = tlsconfig.ServerDefault
12
-	tlsConfig := &cfg
11
+	tlsConfig := tlsconfig.ServerDefault()
13 12
 	if hostname == DefaultNamespace || hostname == DefaultV1Registry.Host {
14 13
 		// v2 mirrors
15 14
 		for _, mirror := range s.config.Mirrors {
... ...
@@ -85,14 +85,10 @@ func (p Port) Port() string {
85 85
 // Int returns the port number of a Port as an int
86 86
 func (p Port) Int() int {
87 87
 	portStr := p.Port()
88
-	if len(portStr) == 0 {
89
-		return 0
90
-	}
91
-
92 88
 	// We don't need to check for an error because we're going to
93 89
 	// assume that any error would have been found, and reported, in NewPort()
94
-	port, _ := strconv.ParseUint(portStr, 10, 16)
95
-	return int(port)
90
+	port, _ := ParsePort(portStr)
91
+	return port
96 92
 }
97 93
 
98 94
 // Range returns the start/end port numbers of a Port range as ints
... ...
@@ -46,19 +46,23 @@ var acceptedCBCCiphers = []uint16{
46 46
 // known weak algorithms removed.
47 47
 var DefaultServerAcceptedCiphers = append(clientCipherSuites, acceptedCBCCiphers...)
48 48
 
49
-// ServerDefault is a secure-enough TLS configuration for the server TLS configuration.
50
-var ServerDefault = tls.Config{
51
-	// Avoid fallback to SSL protocols < TLS1.0
52
-	MinVersion:               tls.VersionTLS10,
53
-	PreferServerCipherSuites: true,
54
-	CipherSuites:             DefaultServerAcceptedCiphers,
49
+// ServerDefault returns a secure-enough TLS configuration for the server TLS configuration.
50
+func ServerDefault() *tls.Config {
51
+	return &tls.Config{
52
+		// Avoid fallback to SSL protocols < TLS1.0
53
+		MinVersion:               tls.VersionTLS10,
54
+		PreferServerCipherSuites: true,
55
+		CipherSuites:             DefaultServerAcceptedCiphers,
56
+	}
55 57
 }
56 58
 
57
-// ClientDefault is a secure-enough TLS configuration for the client TLS configuration.
58
-var ClientDefault = tls.Config{
59
-	// Prefer TLS1.2 as the client minimum
60
-	MinVersion:   tls.VersionTLS12,
61
-	CipherSuites: clientCipherSuites,
59
+// ClientDefault returns a secure-enough TLS configuration for the client TLS configuration.
60
+func ClientDefault() *tls.Config {
61
+	return &tls.Config{
62
+		// Prefer TLS1.2 as the client minimum
63
+		MinVersion:   tls.VersionTLS12,
64
+		CipherSuites: clientCipherSuites,
65
+	}
62 66
 }
63 67
 
64 68
 // certPool returns an X.509 certificate pool from `caFile`, the certificate file.
... ...
@@ -78,7 +82,7 @@ func certPool(caFile string) (*x509.CertPool, error) {
78 78
 
79 79
 // Client returns a TLS configuration meant to be used by a client.
80 80
 func Client(options Options) (*tls.Config, error) {
81
-	tlsConfig := ClientDefault
81
+	tlsConfig := ClientDefault()
82 82
 	tlsConfig.InsecureSkipVerify = options.InsecureSkipVerify
83 83
 	if !options.InsecureSkipVerify && options.CAFile != "" {
84 84
 		CAs, err := certPool(options.CAFile)
... ...
@@ -96,12 +100,12 @@ func Client(options Options) (*tls.Config, error) {
96 96
 		tlsConfig.Certificates = []tls.Certificate{tlsCert}
97 97
 	}
98 98
 
99
-	return &tlsConfig, nil
99
+	return tlsConfig, nil
100 100
 }
101 101
 
102 102
 // Server returns a TLS configuration meant to be used by a server.
103 103
 func Server(options Options) (*tls.Config, error) {
104
-	tlsConfig := ServerDefault
104
+	tlsConfig := ServerDefault()
105 105
 	tlsConfig.ClientAuth = options.ClientAuth
106 106
 	tlsCert, err := tls.LoadX509KeyPair(options.CertFile, options.KeyFile)
107 107
 	if err != nil {
... ...
@@ -118,5 +122,5 @@ func Server(options Options) (*tls.Config, error) {
118 118
 		}
119 119
 		tlsConfig.ClientCAs = CAs
120 120
 	}
121
-	return &tlsConfig, nil
121
+	return tlsConfig, nil
122 122
 }