forked from cloudfoundry/bosh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ssh_tunnel_factory.go
59 lines (44 loc) · 1.01 KB
/
ssh_tunnel_factory.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
49
50
51
52
53
54
55
56
57
58
59
package sshtunnel
import (
boshssh "github.com/cloudfoundry/bosh-cli/ssh"
boshlog "github.com/cloudfoundry/bosh-utils/logger"
)
type Options struct {
Host string
Port int
User string
Password string
PrivateKey string
LocalForwardPort int
RemoteForwardPort int
}
func (o Options) IsEmpty() bool {
return o == Options{}
}
type Factory interface {
NewSSHTunnel(Options) SSHTunnel
}
type factory struct {
logger boshlog.Logger
}
func NewFactory(logger boshlog.Logger) Factory {
return &factory{logger: logger}
}
func (f *factory) NewSSHTunnel(opts Options) SSHTunnel {
clientFactory := boshssh.NewClientFactory(f.logger)
clientOpts := boshssh.ClientOpts{
Host: opts.Host,
Port: opts.Port,
User: opts.User,
Password: opts.Password,
PrivateKey: opts.PrivateKey,
}
tunnel := &sshTunnel{
client: clientFactory.New(clientOpts),
localForwardPort: opts.LocalForwardPort,
remoteForwardPort: opts.RemoteForwardPort,
logTag: "sshTunnel",
logger: f.logger,
}
return tunnel
}