This repository has been archived by the owner on Sep 6, 2021. It is now read-only.
forked from cloudfoundry/bosh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deployment_manifest_parser.go
79 lines (64 loc) · 2.64 KB
/
deployment_manifest_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
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 cmd
import (
bosherr "github.com/cloudfoundry/bosh-utils/errors"
bideplmanifest "github.com/cloudfoundry/bosh-cli/deployment/manifest"
bidepltpl "github.com/cloudfoundry/bosh-cli/deployment/template"
boshtpl "github.com/cloudfoundry/bosh-cli/director/template"
birel "github.com/cloudfoundry/bosh-cli/release"
birelsetmanifest "github.com/cloudfoundry/bosh-cli/release/set/manifest"
biui "github.com/cloudfoundry/bosh-cli/ui"
)
type DeploymentManifestParser interface {
GetDeploymentManifest(path string, vars boshtpl.Variables, releaseSetManifest birelsetmanifest.Manifest, stage biui.Stage) (bideplmanifest.Manifest, string, error)
}
type deploymentManifestParser struct {
deploymentParser bideplmanifest.Parser
deploymentValidator bideplmanifest.Validator
releaseManager birel.Manager
templateFactory bidepltpl.DeploymentTemplateFactory
}
func NewDeploymentManifestParser(
deploymentParser bideplmanifest.Parser,
deploymentValidator bideplmanifest.Validator,
releaseManager birel.Manager,
templateFactory bidepltpl.DeploymentTemplateFactory) DeploymentManifestParser {
return deploymentManifestParser{
deploymentParser: deploymentParser,
deploymentValidator: deploymentValidator,
releaseManager: releaseManager,
templateFactory: templateFactory,
}
}
func (y deploymentManifestParser) GetDeploymentManifest(path string, vars boshtpl.Variables, releaseSetManifest birelsetmanifest.Manifest, stage biui.Stage) (bideplmanifest.Manifest, string, error) {
var deploymentManifest bideplmanifest.Manifest
var manifestSHA string
err := stage.Perform("Validating deployment manifest", func() error {
var err error
template, err := y.templateFactory.NewDeploymentTemplateFromPath(path)
if err != nil {
return bosherr.WrapErrorf(err, "Evaluating manifest")
}
interpolatedTemplate, err := template.Evaluate(vars)
if err != nil {
return bosherr.WrapErrorf(err, "Interpolating manifest '%s'", path)
}
manifestSHA = interpolatedTemplate.SHA()
deploymentManifest, err = y.deploymentParser.Parse(interpolatedTemplate, path)
if err != nil {
return bosherr.WrapErrorf(err, "Parsing deployment manifest '%s'", path)
}
err = y.deploymentValidator.Validate(deploymentManifest, releaseSetManifest)
if err != nil {
return bosherr.WrapError(err, "Validating deployment manifest")
}
err = y.deploymentValidator.ValidateReleaseJobs(deploymentManifest, y.releaseManager)
if err != nil {
return bosherr.WrapError(err, "Validating deployment jobs refer to jobs in release")
}
return nil
})
if err != nil {
return bideplmanifest.Manifest{}, "", err
}
return deploymentManifest, manifestSHA, nil
}