-
Notifications
You must be signed in to change notification settings - Fork 162
/
release_fetcher.go
55 lines (44 loc) · 1.37 KB
/
release_fetcher.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
package installation
import (
"fmt"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
"github.com/cloudfoundry/bosh-cli/installation/tarball"
boshrel "github.com/cloudfoundry/bosh-cli/release"
"github.com/cloudfoundry/bosh-cli/release/manifest"
"github.com/cloudfoundry/bosh-cli/ui"
)
type ReleaseFetcher struct {
tarballProvider tarball.Provider
releaseReader boshrel.Reader
releaseManager ReleaseManager
}
func NewReleaseFetcher(
tarballProvider tarball.Provider,
releaseReader boshrel.Reader,
releaseManager ReleaseManager,
) ReleaseFetcher {
return ReleaseFetcher{
tarballProvider: tarballProvider,
releaseReader: releaseReader,
releaseManager: releaseManager,
}
}
func (f ReleaseFetcher) DownloadAndExtract(releaseRef manifest.ReleaseRef, stage ui.Stage) error {
releasePath, err := f.tarballProvider.Get(releaseRef, stage)
if err != nil {
return err
}
err = stage.Perform(fmt.Sprintf("Validating release '%s'", releaseRef.Name), func() error {
release, err := f.releaseReader.Read(releasePath)
if err != nil {
return bosherr.WrapErrorf(err, "Extracting release '%s'", releasePath)
}
if release.Name() != releaseRef.Name {
errMsg := "Release name '%s' does not match the name in release tarball '%s'"
return bosherr.Errorf(errMsg, releaseRef.Name, release.Name())
}
f.releaseManager.Add(release)
return nil
})
return err
}