-
Notifications
You must be signed in to change notification settings - Fork 2
/
dependency_checker.go
48 lines (38 loc) · 1.66 KB
/
dependency_checker.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
package dependency
import (
"context"
"github.com/cloudogu/cesapp-lib/core"
"github.com/cloudogu/cesapp-lib/registry"
"github.com/hashicorp/go-multierror"
)
// DependencyValidator is responsible to validate the dependencies of a dogu
type DependencyValidator interface {
ValidateAllDependencies(ctx context.Context, dogu *core.Dogu) error
}
// CompositeDependencyValidator is a composite validator responsible to validate the dogu and client dependencies of dogus.
type CompositeDependencyValidator struct {
Validators []DependencyValidator `json:"validators"`
}
// NewCompositeDependencyValidator create a new composite validator checking the dogu and client dependencies
func NewCompositeDependencyValidator(version *core.Version, doguRegistry registry.DoguRegistry) *CompositeDependencyValidator {
validators := []DependencyValidator{}
operatorDependencyValidator := NewOperatorDependencyValidator(version)
validators = append(validators, operatorDependencyValidator)
doguDependencyValidator := NewDoguDependencyValidator(doguRegistry)
validators = append(validators, doguDependencyValidator)
return &CompositeDependencyValidator{
Validators: validators,
}
}
// ValidateDependencies validates all kinds of dependencies for dogus. An error is returned when any invalid
// dependencies were detected.
func (dv *CompositeDependencyValidator) ValidateDependencies(ctx context.Context, dogu *core.Dogu) error {
var result error
for _, validator := range dv.Validators {
err := validator.ValidateAllDependencies(ctx, dogu)
if err != nil {
result = multierror.Append(result, err)
}
}
return result // contains all errors that occurred when checking the dependencies.
}