-
Notifications
You must be signed in to change notification settings - Fork 162
/
validator.go
52 lines (40 loc) · 1.25 KB
/
validator.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
package manifest
import (
"strings"
birelsetmanifest "github.com/cloudfoundry/bosh-cli/release/set/manifest"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
boshlog "github.com/cloudfoundry/bosh-utils/logger"
)
type Validator interface {
Validate(Manifest, birelsetmanifest.Manifest) error
}
type validator struct {
logger boshlog.Logger
}
func NewValidator(logger boshlog.Logger) Validator {
return &validator{
logger: logger,
}
}
func (v *validator) Validate(manifest Manifest, releaseSetManifest birelsetmanifest.Manifest) error {
errs := []error{}
cpiJobName := manifest.Template.Name
if v.isBlank(cpiJobName) {
errs = append(errs, bosherr.Error("cloud_provider.template.name must be provided"))
}
cpiReleaseName := manifest.Template.Release
if v.isBlank(cpiReleaseName) {
errs = append(errs, bosherr.Error("cloud_provider.template.release must be provided"))
}
_, found := releaseSetManifest.FindByName(cpiReleaseName)
if !found {
errs = append(errs, bosherr.Errorf("cloud_provider.template.release '%s' must refer to a release in releases", cpiReleaseName))
}
if len(errs) > 0 {
return bosherr.NewMultiError(errs...)
}
return nil
}
func (v *validator) isBlank(str string) bool {
return str == "" || strings.TrimSpace(str) == ""
}