forked from cloudfoundry/bosh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scp.go
61 lines (50 loc) · 1.2 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
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.AllOrInstanceGroupOrInstanceSlug()
if err != nil {
return err
}
sshOpts, connOpts, err := opts.GatewayFlags.AsSSHOpts()
if err != nil {
return err
}
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
}