-
Notifications
You must be signed in to change notification settings - Fork 162
/
provider.go
52 lines (38 loc) · 1.61 KB
/
provider.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
package ssh
import (
"os/signal"
boshlog "github.com/cloudfoundry/bosh-utils/logger"
boshsys "github.com/cloudfoundry/bosh-utils/system"
boshdir "github.com/cloudfoundry/bosh-cli/v7/director"
boshui "github.com/cloudfoundry/bosh-cli/v7/ui"
)
type Provider struct {
streamingSSH ComboRunner
resultsSSH ComboRunner
scp ComboRunner
}
func NewProvider(cmdRunner boshsys.CmdRunner, fs boshsys.FileSystem, ui boshui.UI, logger boshlog.Logger) Provider {
sshSessionFactory := func(connOpts ConnectionOpts, result boshdir.SSHResult) Session {
return NewSessionImpl(connOpts, SessionImplOpts{ForceTTY: true}, result, fs)
}
streamingWriter := NewStreamingWriter(boshui.NewComboWriter(ui))
streamingSSH := NewComboRunner(
cmdRunner, sshSessionFactory, signal.Notify, streamingWriter, fs, ui, logger)
resultsSSH := NewComboRunner(
cmdRunner, sshSessionFactory, signal.Notify, NewResultsWriter(ui), fs, ui, logger)
scpSessionFactory := func(connOpts ConnectionOpts, result boshdir.SSHResult) Session {
return NewSessionImpl(connOpts, SessionImplOpts{}, result, fs)
}
scp := NewComboRunner(cmdRunner, scpSessionFactory, signal.Notify, streamingWriter, fs, ui, logger)
return Provider{streamingSSH: streamingSSH, resultsSSH: resultsSSH, scp: scp}
}
func (p Provider) NewResultsSSHRunner(interactive bool) Runner {
return NewNonInteractiveRunner(p.resultsSSH)
}
func (p Provider) NewSSHRunner(interactive bool) Runner {
if interactive {
return NewInteractiveRunner(p.streamingSSH)
}
return NewNonInteractiveRunner(p.streamingSSH)
}
func (p Provider) NewSCPRunner() SCPRunner { return NewSCPRunner(p.scp) }