-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathregistry.go
More file actions
80 lines (71 loc) · 1.83 KB
/
registry.go
File metadata and controls
80 lines (71 loc) · 1.83 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package client
import (
"crypto/tls"
"fmt"
"net"
"net/http"
"strings"
"time"
"github.com/coreos/fleet/client"
"github.com/coreos/fleet/machine"
"github.com/coreos/fleet/registry"
"github.com/coreos/fleet/ssh"
)
// Flags used for Fleet API connectivity
var Flags = struct {
Debug bool
Verbosity int
Version bool
Endpoint string
EtcdKeyPrefix string
UseAPI bool
KnownHostsFile string
StrictHostKeyChecking bool
Tunnel string
}{}
// global API client used by commands
var cAPI client.API
// used to cache MachineStates
var machineStates map[string]*machine.MachineState
var requestTimeout = time.Duration(10) * time.Second
func getTunnelFlag() string {
tun := Flags.Tunnel
if tun != "" && !strings.Contains(tun, ":") {
tun += ":22"
}
return tun
}
func getChecker() *ssh.HostKeyChecker {
if !Flags.StrictHostKeyChecking {
return nil
}
keyFile := ssh.NewHostKeyFile(Flags.KnownHostsFile)
return ssh.NewHostKeyChecker(keyFile)
}
func getFakeClient() (*registry.FakeRegistry, error) {
return registry.NewFakeRegistry(), nil
}
func getRegistryClient() (client.API, error) {
var dial func(string, string) (net.Conn, error)
tun := getTunnelFlag()
if tun != "" {
sshClient, err := ssh.NewSSHClient("core", tun, getChecker(), false)
if err != nil {
return nil, fmt.Errorf("failed initializing SSH client: %v", err)
}
dial = func(network, addr string) (net.Conn, error) {
tcpaddr, err := net.ResolveTCPAddr(network, addr)
if err != nil {
return nil, err
}
return sshClient.DialTCP(network, nil, tcpaddr)
}
}
trans := http.Transport{
Dial: dial,
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
}
return client.NewRegistryClient(&trans, Flags.Endpoint, Flags.EtcdKeyPrefix, requestTimeout)
}