Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit 3e4e4fa

Browse files
authored
Merge pull request #245 from Jimmy-Xu/update-vendor
update go-connection in vendor
2 parents 1a2d1cd + e8426bf commit 3e4e4fa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+4452
-201
lines changed

api/client/trust.go

100644100755
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func (cli *DockerCli) getNotaryRepository(repoInfo *registry.RepositoryInfo, aut
114114
return nil, err
115115
}
116116

117-
var cfg = tlsconfig.ClientDefault
117+
var cfg = tlsconfig.ClientDefault()
118118
cfg.InsecureSkipVerify = !repoInfo.Index.Secure
119119

120120
// Get certificate base directory
@@ -124,7 +124,7 @@ func (cli *DockerCli) getNotaryRepository(repoInfo *registry.RepositoryInfo, aut
124124
}
125125
logrus.Debugf("reading certificate directory: %s", certDir)
126126

127-
if err := registry.ReadCertsDirectory(&cfg, certDir); err != nil {
127+
if err := registry.ReadCertsDirectory(cfg, certDir); err != nil {
128128
return nil, err
129129
}
130130

@@ -136,7 +136,7 @@ func (cli *DockerCli) getNotaryRepository(repoInfo *registry.RepositoryInfo, aut
136136
DualStack: true,
137137
}).Dial,
138138
TLSHandshakeTimeout: 10 * time.Second,
139-
TLSClientConfig: &cfg,
139+
TLSClientConfig: cfg,
140140
DisableKeepAlives: true,
141141
}
142142

registry/registry.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,19 @@ func init() {
3838

3939
func newTLSConfig(hostname string, isSecure bool) (*tls.Config, error) {
4040
// PreferredServerCipherSuites should have no effect
41-
tlsConfig := tlsconfig.ServerDefault
41+
tlsConfig := tlsconfig.ServerDefault()
4242

4343
tlsConfig.InsecureSkipVerify = !isSecure
4444

4545
if isSecure && CertsDir != "" {
4646
hostDir := filepath.Join(CertsDir, cleanPath(hostname))
4747
logrus.Debugf("hostDir: %s", hostDir)
48-
if err := ReadCertsDirectory(&tlsConfig, hostDir); err != nil {
48+
if err := ReadCertsDirectory(tlsConfig, hostDir); err != nil {
4949
return nil, err
5050
}
5151
}
5252

53-
return &tlsConfig, nil
53+
return tlsConfig, nil
5454
}
5555

5656
func hasFile(files []os.FileInfo, name string) bool {
@@ -218,8 +218,8 @@ func ContinueOnError(err error) bool {
218218
// default TLS configuration.
219219
func NewTransport(tlsConfig *tls.Config) *http.Transport {
220220
if tlsConfig == nil {
221-
var cfg = tlsconfig.ServerDefault
222-
tlsConfig = &cfg
221+
var cfg = tlsconfig.ServerDefault()
222+
tlsConfig = cfg
223223
}
224224
return &http.Transport{
225225
Proxy: http.ProxyFromEnvironment,

registry/service_v1.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99
)
1010

1111
func (s *Service) lookupV1Endpoints(repoName reference.Named) (endpoints []APIEndpoint, err error) {
12-
var cfg = tlsconfig.ServerDefault
13-
tlsConfig := &cfg
12+
var cfg = tlsconfig.ServerDefault()
13+
tlsConfig := cfg
1414
nameString := repoName.FullName()
1515
if strings.HasPrefix(nameString, DefaultNamespace+"/") {
1616
endpoints = append(endpoints, APIEndpoint{

registry/service_v2.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99
)
1010

1111
func (s *Service) lookupV2Endpoints(repoName reference.Named) (endpoints []APIEndpoint, err error) {
12-
var cfg = tlsconfig.ServerDefault
13-
tlsConfig := &cfg
12+
var cfg = tlsconfig.ServerDefault()
13+
tlsConfig := cfg
1414
nameString := repoName.FullName()
1515
if strings.HasPrefix(nameString, DefaultNamespace+"/") {
1616
// v2 mirrors
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Contributing to Docker
2+
3+
### Sign your work
4+
5+
The sign-off is a simple line at the end of the explanation for the patch. Your
6+
signature certifies that you wrote the patch or otherwise have the right to pass
7+
it on as an open-source patch. The rules are pretty simple: if you can certify
8+
the below (from [developercertificate.org](http://developercertificate.org/)):
9+
10+
```
11+
Developer Certificate of Origin
12+
Version 1.1
13+
14+
Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
15+
660 York Street, Suite 102,
16+
San Francisco, CA 94110 USA
17+
18+
Everyone is permitted to copy and distribute verbatim copies of this
19+
license document, but changing it is not allowed.
20+
21+
Developer's Certificate of Origin 1.1
22+
23+
By making a contribution to this project, I certify that:
24+
25+
(a) The contribution was created in whole or in part by me and I
26+
have the right to submit it under the open source license
27+
indicated in the file; or
28+
29+
(b) The contribution is based upon previous work that, to the best
30+
of my knowledge, is covered under an appropriate open source
31+
license and I have the right under that license to submit that
32+
work with modifications, whether created in whole or in part
33+
by me, under the same open source license (unless I am
34+
permitted to submit under a different license), as indicated
35+
in the file; or
36+
37+
(c) The contribution was provided directly to me by some other
38+
person who certified (a), (b) or (c) and I have not modified
39+
it.
40+
41+
(d) I understand and agree that this project and the contribution
42+
are public and that a record of the contribution (including all
43+
personal information I submit with it, including my sign-off) is
44+
maintained indefinitely and may be redistributed consistent with
45+
this project or the open source license(s) involved.
46+
```
47+
48+
Then you just add a line to every git commit message:
49+
50+
Signed-off-by: Joe Smith <joe.smith@email.com>
51+
52+
Use your real name (sorry, no pseudonyms or anonymous contributions.)
53+
54+
If you set your `user.name` and `user.email` git configs, you can sign your
55+
commit automatically with `git commit -s`.

vendor/src/github.com/docker/go-connections/LICENSE

100644100755
File mode changed.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# go-connections maintainers file
2+
#
3+
# This file describes who runs the docker/go-connections project and how.
4+
# This is a living document - if you see something out of date or missing, speak up!
5+
#
6+
# It is structured to be consumable by both humans and programs.
7+
# To extract its contents programmatically, use any TOML-compliant parser.
8+
#
9+
# This file is compiled into the MAINTAINERS file in docker/opensource.
10+
#
11+
[Org]
12+
[Org."Core maintainers"]
13+
people = [
14+
"calavera",
15+
]
16+
17+
[people]
18+
19+
# A reference list of all people associated with the project.
20+
# All other sections should refer to people by their canonical key
21+
# in the people section.
22+
23+
# ADD YOURSELF HERE IN ALPHABETICAL ORDER
24+
[people.calavera]
25+
Name = "David Calavera"
26+
Email = "david.calavera@gmail.com"
27+
GitHub = "calavera"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[![GoDoc](https://godoc.org/github.com/docker/go-connections?status.svg)](https://godoc.org/github.com/docker/go-connections)
2+
3+
# Introduction
4+
5+
go-connections provides common package to work with network connections.
6+
7+
## Usage
8+
9+
See the [docs in godoc](https://godoc.org/github.com/docker/go-connections) for examples and documentation.
10+
11+
## License
12+
13+
go-connections is licensed under the Apache License, Version 2.0. See [LICENSE](LICENSE) for the full license text.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Package connections provides libraries to work with network connections.
2+
// This library is divided in several components for specific usage.
3+
package connections

vendor/src/github.com/docker/go-connections/nat/nat.go

100644100755
Lines changed: 96 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,10 @@ func (p Port) Port() string {
8585
// Int returns the port number of a Port as an int
8686
func (p Port) Int() int {
8787
portStr := p.Port()
88-
if len(portStr) == 0 {
89-
return 0
90-
}
91-
9288
// We don't need to check for an error because we're going to
9389
// 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
9692
}
9793

9894
// Range returns the start/end port numbers of a Port range as ints
@@ -132,92 +128,115 @@ func ParsePortSpecs(ports []string) (map[Port]struct{}, map[Port][]PortBinding,
132128
exposedPorts = make(map[Port]struct{}, len(ports))
133129
bindings = make(map[Port][]PortBinding)
134130
)
135-
136131
for _, rawPort := range ports {
137-
proto := "tcp"
138-
139-
if i := strings.LastIndex(rawPort, "/"); i != -1 {
140-
proto = rawPort[i+1:]
141-
rawPort = rawPort[:i]
142-
}
143-
if !strings.Contains(rawPort, ":") {
144-
rawPort = fmt.Sprintf("::%s", rawPort)
145-
} else if len(strings.Split(rawPort, ":")) == 2 {
146-
rawPort = fmt.Sprintf(":%s", rawPort)
147-
}
148-
149-
parts, err := PartParser(portSpecTemplate, rawPort)
132+
portMappings, err := ParsePortSpec(rawPort)
150133
if err != nil {
151134
return nil, nil, err
152135
}
153136

154-
var (
155-
containerPort = parts["containerPort"]
156-
rawIP = parts["ip"]
157-
hostPort = parts["hostPort"]
158-
)
159-
160-
if rawIP != "" && net.ParseIP(rawIP) == nil {
161-
return nil, nil, fmt.Errorf("Invalid ip address: %s", rawIP)
162-
}
163-
if containerPort == "" {
164-
return nil, nil, fmt.Errorf("No port specified: %s<empty>", rawPort)
137+
for _, portMapping := range portMappings {
138+
port := portMapping.Port
139+
if _, exists := exposedPorts[port]; !exists {
140+
exposedPorts[port] = struct{}{}
141+
}
142+
bslice, exists := bindings[port]
143+
if !exists {
144+
bslice = []PortBinding{}
145+
}
146+
bindings[port] = append(bslice, portMapping.Binding)
165147
}
148+
}
149+
return exposedPorts, bindings, nil
150+
}
151+
152+
// PortMapping is a data object mapping a Port to a PortBinding
153+
type PortMapping struct {
154+
Port Port
155+
Binding PortBinding
156+
}
157+
158+
func splitParts(rawport string) (string, string, string) {
159+
parts := strings.Split(rawport, ":")
160+
n := len(parts)
161+
containerport := parts[n-1]
162+
163+
switch n {
164+
case 1:
165+
return "", "", containerport
166+
case 2:
167+
return "", parts[0], containerport
168+
case 3:
169+
return parts[0], parts[1], containerport
170+
default:
171+
return strings.Join(parts[:n-2], ":"), parts[n-2], containerport
172+
}
173+
}
174+
175+
// ParsePortSpec parses a port specification string into a slice of PortMappings
176+
func ParsePortSpec(rawPort string) ([]PortMapping, error) {
177+
var proto string
178+
rawIP, hostPort, containerPort := splitParts(rawPort)
179+
proto, containerPort = SplitProtoPort(containerPort)
180+
181+
// Strip [] from IPV6 addresses
182+
ip, _, err := net.SplitHostPort(rawIP + ":")
183+
if err != nil {
184+
return nil, fmt.Errorf("Invalid ip address %v: %s", rawIP, err)
185+
}
186+
if ip != "" && net.ParseIP(ip) == nil {
187+
return nil, fmt.Errorf("Invalid ip address: %s", ip)
188+
}
189+
if containerPort == "" {
190+
return nil, fmt.Errorf("No port specified: %s<empty>", rawPort)
191+
}
192+
193+
startPort, endPort, err := ParsePortRange(containerPort)
194+
if err != nil {
195+
return nil, fmt.Errorf("Invalid containerPort: %s", containerPort)
196+
}
166197

167-
startPort, endPort, err := ParsePortRange(containerPort)
198+
var startHostPort, endHostPort uint64 = 0, 0
199+
if len(hostPort) > 0 {
200+
startHostPort, endHostPort, err = ParsePortRange(hostPort)
168201
if err != nil {
169-
return nil, nil, fmt.Errorf("Invalid containerPort: %s", containerPort)
202+
return nil, fmt.Errorf("Invalid hostPort: %s", hostPort)
170203
}
204+
}
171205

172-
var startHostPort, endHostPort uint64 = 0, 0
173-
if len(hostPort) > 0 {
174-
startHostPort, endHostPort, err = ParsePortRange(hostPort)
175-
if err != nil {
176-
return nil, nil, fmt.Errorf("Invalid hostPort: %s", hostPort)
177-
}
206+
if hostPort != "" && (endPort-startPort) != (endHostPort-startHostPort) {
207+
// Allow host port range iff containerPort is not a range.
208+
// In this case, use the host port range as the dynamic
209+
// host port range to allocate into.
210+
if endPort != startPort {
211+
return nil, fmt.Errorf("Invalid ranges specified for container and host Ports: %s and %s", containerPort, hostPort)
178212
}
213+
}
179214

180-
if hostPort != "" && (endPort-startPort) != (endHostPort-startHostPort) {
181-
// Allow host port range iff containerPort is not a range.
182-
// In this case, use the host port range as the dynamic
183-
// host port range to allocate into.
184-
if endPort != startPort {
185-
return nil, nil, fmt.Errorf("Invalid ranges specified for container and host Ports: %s and %s", containerPort, hostPort)
186-
}
187-
}
215+
if !validateProto(strings.ToLower(proto)) {
216+
return nil, fmt.Errorf("Invalid proto: %s", proto)
217+
}
188218

189-
if !validateProto(strings.ToLower(proto)) {
190-
return nil, nil, fmt.Errorf("Invalid proto: %s", proto)
219+
ports := []PortMapping{}
220+
for i := uint64(0); i <= (endPort - startPort); i++ {
221+
containerPort = strconv.FormatUint(startPort+i, 10)
222+
if len(hostPort) > 0 {
223+
hostPort = strconv.FormatUint(startHostPort+i, 10)
224+
}
225+
// Set hostPort to a range only if there is a single container port
226+
// and a dynamic host port.
227+
if startPort == endPort && startHostPort != endHostPort {
228+
hostPort = fmt.Sprintf("%s-%s", hostPort, strconv.FormatUint(endHostPort, 10))
229+
}
230+
port, err := NewPort(strings.ToLower(proto), containerPort)
231+
if err != nil {
232+
return nil, err
191233
}
192234

193-
for i := uint64(0); i <= (endPort - startPort); i++ {
194-
containerPort = strconv.FormatUint(startPort+i, 10)
195-
if len(hostPort) > 0 {
196-
hostPort = strconv.FormatUint(startHostPort+i, 10)
197-
}
198-
// Set hostPort to a range only if there is a single container port
199-
// and a dynamic host port.
200-
if startPort == endPort && startHostPort != endHostPort {
201-
hostPort = fmt.Sprintf("%s-%s", hostPort, strconv.FormatUint(endHostPort, 10))
202-
}
203-
port, err := NewPort(strings.ToLower(proto), containerPort)
204-
if err != nil {
205-
return nil, nil, err
206-
}
207-
if _, exists := exposedPorts[port]; !exists {
208-
exposedPorts[port] = struct{}{}
209-
}
210-
211-
binding := PortBinding{
212-
HostIP: rawIP,
213-
HostPort: hostPort,
214-
}
215-
bslice, exists := bindings[port]
216-
if !exists {
217-
bslice = []PortBinding{}
218-
}
219-
bindings[port] = append(bslice, binding)
235+
binding := PortBinding{
236+
HostIP: ip,
237+
HostPort: hostPort,
220238
}
239+
ports = append(ports, PortMapping{Port: port, Binding: binding})
221240
}
222-
return exposedPorts, bindings, nil
241+
return ports, nil
223242
}

0 commit comments

Comments
 (0)