-
Notifications
You must be signed in to change notification settings - Fork 0
/
startupConfigValidator.go
77 lines (63 loc) · 2.36 KB
/
startupConfigValidator.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
package validation
import (
"fmt"
"github.com/cloudogu/cesapp-lib/remote"
"github.com/cloudogu/k8s-ces-setup/app/context"
)
type validator struct {
namingValidator NamingValidator
userBackenValidator UserBackendValidator
adminValidator AdminValidator
doguValidator DoguValidator
}
// NamingValidator is used to validate the naming section of the setup configuration
type NamingValidator interface {
ValidateNaming(naming context.Naming) error
}
// UserBackendValidator is used to validate the user backend section of the setup configuration
type UserBackendValidator interface {
ValidateUserBackend(backend context.UserBackend) error
}
// AdminValidator is used to validate the admin section of the setup configuration
type AdminValidator interface {
ValidateAdmin(admin context.User, dsType string) error
}
// DoguValidator is used to validate the dogu section of the setup configuration
type DoguValidator interface {
ValidateDogus(dogus context.Dogus) error
}
// NewStartupConfigurationValidator creates a new setup json validator
func NewStartupConfigurationValidator(registry remote.Registry) *validator {
doguValidator := NewDoguValidator(registry)
return &validator{
namingValidator: NewNamingValidator(),
userBackenValidator: NewUserBackendValidator(),
adminValidator: NewAdminValidator(),
doguValidator: doguValidator,
}
}
// ValidateConfiguration checks the section naming, user backend and user from the setup.json configuration
// see: https://docs.cloudogu.com/docs/system-components/ces-setup/operations/setup-json_de/
func (v *validator) ValidateConfiguration(configuration *context.SetupConfiguration) error {
dogus := configuration.Dogus
err := v.doguValidator.ValidateDogus(dogus)
if err != nil {
return fmt.Errorf("failed to validate dogu section: %w", err)
}
naming := configuration.Naming
err = v.namingValidator.ValidateNaming(naming)
if err != nil {
return fmt.Errorf("failed to validate naming section: %w", err)
}
userBackend := configuration.UserBackend
err = v.userBackenValidator.ValidateUserBackend(userBackend)
if err != nil {
return fmt.Errorf("failed to validate user backend section: %w", err)
}
admin := configuration.Admin
err = v.adminValidator.ValidateAdmin(admin, userBackend.DsType)
if err != nil {
return fmt.Errorf("failed to validate admin user section: %w", err)
}
return nil
}