-
Notifications
You must be signed in to change notification settings - Fork 161
/
manifest_lock.go
41 lines (32 loc) · 1011 Bytes
/
manifest_lock.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
package manifest
import (
bosherr "github.com/cloudfoundry/bosh-utils/errors"
boshsys "github.com/cloudfoundry/bosh-utils/system"
"gopkg.in/yaml.v2"
)
type ManifestLock struct {
Name string `yaml:"name"`
Fingerprint string `yaml:"fingerprint"`
Dependencies []string `yaml:"dependencies,omitempty"`
}
func NewManifestLockFromPath(path string, fs boshsys.FileSystem) (ManifestLock, error) {
var manifest ManifestLock
bytes, err := fs.ReadFile(path)
if err != nil {
return manifest, bosherr.WrapErrorf(err, "Reading package spec lock '%s'", path)
}
err = yaml.Unmarshal(bytes, &manifest)
if err != nil {
return manifest, bosherr.WrapError(err, "Unmarshalling package spec lock")
}
return manifest, nil
}
func (m ManifestLock) AsBytes() ([]byte, error) {
if len(m.Name) == 0 {
return nil, bosherr.Errorf("Expected non-empty package name")
}
if len(m.Fingerprint) == 0 {
return nil, bosherr.Errorf("Expected non-empty package fingerprint")
}
return yaml.Marshal(m)
}