-
Notifications
You must be signed in to change notification settings - Fork 111
/
manifest.go
76 lines (60 loc) · 1.95 KB
/
manifest.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
package backup
import (
"context"
"io/ioutil"
"github.com/pkg/errors"
"github.com/chef/automate/components/automate-deployment/pkg/manifest"
manifest_client "github.com/chef/automate/components/automate-deployment/pkg/manifest/client"
)
const (
relativeManifestPath = "deployment-service/package-manifest/package-manifest.json"
)
type ReleaseManifestLocation interface {
Provider() manifest.ReleaseManifestProvider
}
type latestManifestLocation struct {
hartifactsPath string
overrideOrigin string
}
func (m *latestManifestLocation) Provider() manifest.ReleaseManifestProvider {
return manifest.NewLocalHartManifestProvider(
manifest_client.NewHTTPClient(),
m.hartifactsPath,
m.overrideOrigin,
)
}
func NewLatestManifestLocation(hartifacts, origin string) ReleaseManifestLocation {
return &latestManifestLocation{
hartifactsPath: hartifacts,
overrideOrigin: origin,
}
}
type onDiskManifestLocation struct {
path string
}
func (m *onDiskManifestLocation) Provider() manifest.ReleaseManifestProvider {
return manifest_client.NewDefaultClient(m.path)
}
func NewOnDiskManifestLocation(path string) ReleaseManifestLocation {
return &onDiskManifestLocation{path}
}
type bucketManifestLocation struct {
data []byte
}
func (m *bucketManifestLocation) Provider() manifest.ReleaseManifestProvider {
return manifest_client.NewInMemoryClient(m.data)
}
func NewBucketManifestLocation(ctx context.Context, bucket Bucket) (ReleaseManifestLocation, error) {
// TODO: currently we don't have a way to validate the manifest itself;
// when we do, this needs to not use NoOpObjectVerifier
reader, err := bucket.NewReader(ctx, relativeManifestPath, &NoOpObjectVerifier{})
if err != nil {
return nil, errors.Wrap(err, "failed to open package manifest from backup")
}
defer reader.Close()
data, err := ioutil.ReadAll(reader)
if err != nil {
return nil, errors.Wrap(err, "failed to read package manifest from backup")
}
return &bucketManifestLocation{data}, nil
}