-
Notifications
You must be signed in to change notification settings - Fork 162
/
scp.go
71 lines (57 loc) · 1.5 KB
/
scp.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
60
61
62
63
64
65
66
67
68
69
70
71
package cmd
import (
bosherr "github.com/cloudfoundry/bosh-utils/errors"
boshuuid "github.com/cloudfoundry/bosh-utils/uuid"
boshdir "github.com/cloudfoundry/bosh-cli/director"
boshssh "github.com/cloudfoundry/bosh-cli/ssh"
biui "github.com/cloudfoundry/bosh-cli/ui"
)
type SCPCmd struct {
deployment boshdir.Deployment
uuidGen boshuuid.Generator
scpRunner boshssh.SCPRunner
ui biui.UI
}
func NewSCPCmd(
deployment boshdir.Deployment,
uuidGen boshuuid.Generator,
scpRunner boshssh.SCPRunner,
ui biui.UI,
) SCPCmd {
return SCPCmd{
deployment: deployment,
uuidGen: uuidGen,
scpRunner: scpRunner,
ui: ui,
}
}
func (c SCPCmd) Run(opts SCPOpts) error {
scpArgs := boshssh.NewSCPArgs(opts.Args.Paths, opts.Recursive)
slug, err := scpArgs.AllOrPoolOrInstanceSlug()
if err != nil {
return err
}
sshOpts, privKey, err := boshdir.NewSSHOpts(c.uuidGen)
if err != nil {
return bosherr.WrapErrorf(err, "Generating SSH options")
}
connOpts := boshssh.ConnectionOpts{
PrivateKey: privKey,
GatewayDisable: opts.GatewayFlags.Disable,
GatewayUsername: opts.GatewayFlags.Username,
GatewayHost: opts.GatewayFlags.Host,
GatewayPrivateKeyPath: opts.GatewayFlags.PrivateKeyPath,
}
result, err := c.deployment.SetUpSSH(slug, sshOpts)
if err != nil {
return err
}
defer func() {
_ = c.deployment.CleanUpSSH(slug, sshOpts)
}()
err = c.scpRunner.Run(connOpts, result, scpArgs)
if err != nil {
return bosherr.WrapErrorf(err, "Running SCP")
}
return nil
}