-
Notifications
You must be signed in to change notification settings - Fork 73
/
manifest_validator.go
71 lines (58 loc) · 1.83 KB
/
manifest_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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package discovery
import (
"fmt"
"github.com/newrelic/newrelic-cli/internal/install/types"
)
type ManifestValidator struct {
validators []validator
}
type validator interface {
Validate(m *types.DiscoveryManifest) error
}
var (
errorPrefix = "Installation requirements error:"
errorPrefixFormat = errorPrefix + " %s"
)
// NewManifestValidator returns a new instance of ManifestValidator.
func NewManifestValidator() *ManifestValidator {
mv := ManifestValidator{
validators: []validator{},
}
mv.validators = append(mv.validators, NewOsValidator())
mv.validators = append(mv.validators, NewOsVersionValidator("windows", "", 6, 2))
mv.validators = append(mv.validators, NewOsVersionValidator("linux", "ubuntu", 16, 04))
mv.validators = append(mv.validators, NewOsVersionValidator("linux", "centos", 7, 0))
mv.validators = append(mv.validators, NewOsVersionValidator("linux", "debian", 8, 0))
mv.validators = append(mv.validators, NewOsVersionValidator("linux", "redhat", 6, 0))
mv.validators = append(mv.validators, NewOsVersionValidator("darwin", "", 10, 14))
return &mv
}
func (mv *ManifestValidator) Validate(m *types.DiscoveryManifest) error {
var accumulator error
errors := mv.FindAllValidationErrors(m)
for _, single := range errors {
if accumulator == nil {
accumulator = single
} else {
accumulator = fmt.Errorf("%s, %s", accumulator, single.Error())
}
}
if accumulator != nil {
// Flag as unsupported OS
m.IsUnsupported = true
return &types.UnsupportedOperatingSytemError{
Err: fmt.Errorf(errorPrefixFormat, accumulator),
}
}
return nil
}
func (mv *ManifestValidator) FindAllValidationErrors(m *types.DiscoveryManifest) []error {
errors := []error{}
for _, validator := range mv.validators {
err := validator.Validate(m)
if err != nil {
errors = append(errors, err)
}
}
return errors
}