forked from cloudfoundry-attic/bosh-init
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser.go
53 lines (42 loc) · 1.21 KB
/
parser.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
package manifest
import (
"github.com/cloudfoundry-incubator/candiedyaml"
bosherr "github.com/cloudfoundry/bosh-agent/errors"
boshlog "github.com/cloudfoundry/bosh-agent/logger"
boshsys "github.com/cloudfoundry/bosh-agent/system"
bmrelmanifest "github.com/cloudfoundry/bosh-micro-cli/release/manifest"
)
type Parser interface {
Parse(path string) (Manifest, error)
}
type parser struct {
fs boshsys.FileSystem
logger boshlog.Logger
logTag string
}
type manifest struct {
Releases []bmrelmanifest.ReleaseRef
}
func NewParser(fs boshsys.FileSystem, logger boshlog.Logger) Parser {
return &parser{
fs: fs,
logger: logger,
logTag: "releaseSetParser",
}
}
func (p *parser) Parse(path string) (Manifest, error) {
contents, err := p.fs.ReadFile(path)
if err != nil {
return Manifest{}, bosherr.WrapErrorf(err, "Reading file %s", path)
}
comboManifest := manifest{}
err = candiedyaml.Unmarshal(contents, &comboManifest)
if err != nil {
return Manifest{}, bosherr.WrapError(err, "Unmarshalling release set manifest")
}
p.logger.Debug(p.logTag, "Parsed release set manifest: %#v", comboManifest)
releaseSetManifest := Manifest{
Releases: comboManifest.Releases,
}
return releaseSetManifest, nil
}