forked from cloudfoundry/bosh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
basic_deps.go
59 lines (48 loc) · 1.83 KB
/
basic_deps.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 cmd
import (
boshcrypto "github.com/cloudfoundry/bosh-utils/crypto"
boshcmd "github.com/cloudfoundry/bosh-utils/fileutil"
boshlog "github.com/cloudfoundry/bosh-utils/logger"
boshsys "github.com/cloudfoundry/bosh-utils/system"
boshuuid "github.com/cloudfoundry/bosh-utils/uuid"
"github.com/pivotal-golang/clock"
bicrypto "github.com/cloudfoundry/bosh-cli/crypto"
boshui "github.com/cloudfoundry/bosh-cli/ui"
)
type BasicDeps struct {
FS boshsys.FileSystem
UI *boshui.ConfUI
Logger boshlog.Logger
UUIDGen boshuuid.Generator
CmdRunner boshsys.CmdRunner
Compressor boshcmd.Compressor
DigestCalculator bicrypto.DigestCalculator
DigestCreationAlgorithms []boshcrypto.Algorithm
Time clock.Clock
}
func NewBasicDeps(ui *boshui.ConfUI, logger boshlog.Logger) BasicDeps {
return NewBasicDepsWithFS(ui, boshsys.NewOsFileSystemWithStrictTempRoot(logger), logger)
}
func NewBasicDepsWithFS(ui *boshui.ConfUI, fs boshsys.FileSystem, logger boshlog.Logger) BasicDeps {
cmdRunner := boshsys.NewExecCmdRunner(logger)
digestCreationAlgorithms := []boshcrypto.Algorithm{boshcrypto.DigestAlgorithmSHA1}
digestCalculator := bicrypto.NewDigestCalculator(fs, digestCreationAlgorithms)
return BasicDeps{
FS: fs,
UI: ui,
Logger: logger,
UUIDGen: boshuuid.NewGenerator(),
CmdRunner: cmdRunner,
Compressor: boshcmd.NewTarballCompressor(cmdRunner, fs),
DigestCalculator: digestCalculator,
DigestCreationAlgorithms: digestCreationAlgorithms,
Time: clock.NewClock(),
}
}
func (b BasicDeps) WithSha2CheckSumming() BasicDeps {
b.DigestCreationAlgorithms = []boshcrypto.Algorithm{
boshcrypto.DigestAlgorithmSHA256,
}
b.DigestCalculator = bicrypto.NewDigestCalculator(b.FS, b.DigestCreationAlgorithms)
return b
}