This repository has been archived by the owner on Mar 24, 2022. It is now read-only.
forked from cloudfoundry/bosh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
provider.go
127 lines (106 loc) · 4.29 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package releasedir
import (
"path/filepath"
"code.cloudfoundry.org/clock"
boshblob "github.com/cloudfoundry/bosh-utils/blobstore"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
boshlog "github.com/cloudfoundry/bosh-utils/logger"
boshsys "github.com/cloudfoundry/bosh-utils/system"
boshuuid "github.com/cloudfoundry/bosh-utils/uuid"
bicrypto "github.com/cloudfoundry/bosh-cli/crypto"
boshrel "github.com/cloudfoundry/bosh-cli/release"
boshidx "github.com/cloudfoundry/bosh-cli/releasedir/index"
boshcrypto "github.com/cloudfoundry/bosh-utils/crypto"
)
type Provider struct {
indexReporter boshidx.Reporter
releaseIndexReporter ReleaseIndexReporter
blobsReporter BlobsDirReporter
releaseProvider boshrel.Provider
digestCalculator bicrypto.DigestCalculator
cmdRunner boshsys.CmdRunner
uuidGen boshuuid.Generator
timeService clock.Clock
fs boshsys.FileSystem
logger boshlog.Logger
digestCreateAlgorithms []boshcrypto.Algorithm
}
func NewProvider(
indexReporter boshidx.Reporter,
releaseIndexReporter ReleaseIndexReporter,
blobsReporter BlobsDirReporter,
releaseProvider boshrel.Provider,
digestCalculator bicrypto.DigestCalculator,
cmdRunner boshsys.CmdRunner,
uuidGen boshuuid.Generator,
timeService clock.Clock,
fs boshsys.FileSystem,
digestCreateAlgorithms []boshcrypto.Algorithm,
logger boshlog.Logger,
) Provider {
return Provider{
indexReporter: indexReporter,
releaseIndexReporter: releaseIndexReporter,
blobsReporter: blobsReporter,
releaseProvider: releaseProvider,
digestCalculator: digestCalculator,
cmdRunner: cmdRunner,
uuidGen: uuidGen,
timeService: timeService,
fs: fs,
digestCreateAlgorithms: digestCreateAlgorithms,
logger: logger,
}
}
func (p Provider) NewFSReleaseDir(dirPath string) FSReleaseDir {
gitRepo := NewFSGitRepo(dirPath, p.cmdRunner, p.fs)
blobsDir := p.NewFSBlobsDir(dirPath)
generator := NewFSGenerator(dirPath, p.fs)
devRelsPath := filepath.Join(dirPath, "dev_releases")
devReleases := NewFSReleaseIndex("dev", devRelsPath, p.releaseIndexReporter, p.uuidGen, p.fs)
finalRelsPath := filepath.Join(dirPath, "releases")
finalReleases := NewFSReleaseIndex("final", finalRelsPath, p.releaseIndexReporter, p.uuidGen, p.fs)
indiciesProvider := boshidx.NewProvider(p.indexReporter, p.newBlobstore(dirPath), p.fs)
_, finalIndex := indiciesProvider.DevAndFinalIndicies(dirPath)
releaseReader := p.NewReleaseReader(dirPath)
return NewFSReleaseDir(dirPath, p.newConfig(dirPath), gitRepo, blobsDir,
generator, devReleases, finalReleases, finalIndex, releaseReader, p.timeService, p.fs)
}
func (p Provider) NewFSBlobsDir(dirPath string) FSBlobsDir {
return NewFSBlobsDir(dirPath, p.blobsReporter, p.newBlobstore(dirPath), p.digestCalculator, p.fs, p.logger)
}
func (p Provider) NewReleaseReader(dirPath string) boshrel.BuiltReader {
multiReader := p.releaseProvider.NewMultiReader(dirPath)
indiciesProvider := boshidx.NewProvider(p.indexReporter, p.newBlobstore(dirPath), p.fs)
devIndex, finalIndex := indiciesProvider.DevAndFinalIndicies(dirPath)
return boshrel.NewBuiltReader(multiReader, devIndex, finalIndex)
}
func (p Provider) newBlobstore(dirPath string) boshblob.DigestBlobstore {
provider, options, err := p.newConfig(dirPath).Blobstore()
if err != nil {
return NewErrBlobstore(err)
}
var blobstore boshblob.Blobstore
switch provider {
case "local":
blobstore = boshblob.NewLocalBlobstore(p.fs, p.uuidGen, options)
case "s3":
blobstore = NewS3Blobstore(p.fs, p.uuidGen, options)
case "gcs":
blobstore = NewGCSBlobstore(p.fs, p.uuidGen, options)
default:
return NewErrBlobstore(bosherr.Error("Expected release blobstore to be configured"))
}
digestBlobstore := boshblob.NewDigestVerifiableBlobstore(blobstore, p.fs, p.digestCreateAlgorithms)
digestBlobstore = boshblob.NewRetryableBlobstore(digestBlobstore, 3, p.logger)
err = digestBlobstore.Validate()
if err != nil {
return NewErrBlobstore(err)
}
return digestBlobstore
}
func (p Provider) newConfig(dirPath string) FSConfig {
publicPath := filepath.Join(dirPath, "config", "final.yml")
privatePath := filepath.Join(dirPath, "config", "private.yml")
return NewFSConfig(publicPath, privatePath, p.fs)
}