forked from cloudfoundry/bosh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.go
79 lines (64 loc) · 2.2 KB
/
release.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
package manifest
import (
"strings"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
boshsys "github.com/cloudfoundry/bosh-utils/system"
"gopkg.in/yaml.v2"
)
type Manifest struct {
Name string `yaml:"name"`
Version string `yaml:"version"`
CommitHash string `yaml:"commit_hash"`
UncommittedChanges bool `yaml:"uncommitted_changes"`
Jobs []JobRef `yaml:"jobs,omitempty"`
Packages []PackageRef `yaml:"packages,omitempty"`
CompiledPkgs []CompiledPackageRef `yaml:"compiled_packages,omitempty"`
License *LicenseRef `yaml:"license,omitempty"`
}
type JobRef struct {
Name string `yaml:"name"`
Version string `yaml:"version"` // todo deprecate
Fingerprint string `yaml:"fingerprint"`
SHA1 string `yaml:"sha1"`
}
type PackageRef struct {
Name string `yaml:"name"`
Version string `yaml:"version"` // todo deprecate
Fingerprint string `yaml:"fingerprint"`
SHA1 string `yaml:"sha1"`
Dependencies []string `yaml:"dependencies"`
}
type CompiledPackageRef struct {
Name string `yaml:"name"`
Version string `yaml:"version"` // todo deprecate
Fingerprint string `yaml:"fingerprint"`
SHA1 string `yaml:"sha1"`
OSVersionSlug string `yaml:"stemcell"`
Dependencies []string `yaml:"dependencies"`
}
type LicenseRef struct {
Version string `yaml:"version"` // todo deprecate
Fingerprint string `yaml:"fingerprint"`
SHA1 string `yaml:"sha1"`
}
var (
// Ruby CLI for some reason produces invalid annotations
invalidBinaryAnnotationReplacer = strings.NewReplacer(
"sha1: !binary |-", "sha1: !!binary |-",
"version: !binary |-", "version: !!binary |-",
"fingerprint: !binary |-", "fingerprint: !!binary |-",
)
)
func NewManifestFromPath(path string, fs boshsys.FileSystem) (Manifest, error) {
var manifest Manifest
bytes, err := fs.ReadFile(path)
if err != nil {
return Manifest{}, bosherr.WrapErrorf(err, "Reading manifest '%s'", path)
}
str := invalidBinaryAnnotationReplacer.Replace(string(bytes))
err = yaml.Unmarshal([]byte(str), &manifest)
if err != nil {
return Manifest{}, bosherr.WrapError(err, "Parsing release manifest")
}
return manifest, nil
}