forked from rancher/rancher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tls_dialer.go
48 lines (39 loc) · 962 Bytes
/
tls_dialer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package dialer
import (
"crypto/tls"
"errors"
"net"
"strings"
"github.com/rancher/rancher/pkg/nodeconfig"
"github.com/rancher/types/apis/management.cattle.io/v3"
"github.com/rancher/types/config/dialer"
)
func (f *Factory) tlsDialer(machine *v3.Node) (dialer.Dialer, error) {
config, err := nodeconfig.NewNodeConfig(f.store, machine)
if err != nil {
return nil, err
}
tlsConfig, err := config.TLSConfig()
if err != nil {
return nil, err
}
realTLSConfig, err := tlsConfig.ToConfig()
if err != nil {
return nil, err
}
d := &tlsDialer{
Config: realTLSConfig,
Address: tlsConfig.Address,
}
return d.Dial, nil
}
type tlsDialer struct {
Config *tls.Config
Address string
}
func (t *tlsDialer) Dial(network, address string) (net.Conn, error) {
if !strings.Contains(address, "docker.sock") {
return nil, errors.New("only docker.sock connections are supported for this node")
}
return tls.Dial("tcp", t.Address, t.Config)
}