-
Notifications
You must be signed in to change notification settings - Fork 67
/
aws_validator.go
64 lines (53 loc) · 2 KB
/
aws_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
package validate
import (
"github.com/armory/spinnaker-operator/pkg/apis/spinnaker/interfaces"
"github.com/mitchellh/mapstructure"
)
const (
awsAccountType = "aws"
awsAccountsEnabledKey = "providers.aws.enabled"
awsAccountsKey = "providers.aws.accounts"
)
type AwsAccount struct {
DefaultKeyPair string `json:"defaultKeyPair,omitempty"`
Edda string `json:"edda,omitempty"`
Discovery string `json:"discovery,omitempty"`
AccountId string `json:"accountId,omitempty"`
Regions []AwsRegion `json:"regions,omitempty"`
AssumeRole string `json:"assumeRole,omitempty"`
ExternalId string `json:"externalId,omitempty"`
SessionName string `json:"sessionName,omitempty"`
LifecycleHooks []AwsLifecycleHook `json:"lifecycleHooks,omitempty"`
}
type AwsRegion struct {
Name string `json:"name,omitempty"`
}
type awsAccountValidator struct {
awsLifecycleHookValidation awsLifecycleHookValidation
}
func (d *awsAccountValidator) Validate(spinSvc interfaces.SpinnakerService, options Options) ValidationResult {
accountEnabled, err := spinSvc.GetSpinnakerConfig().GetHalConfigPropBool(awsAccountsEnabledKey, false)
if err != nil {
return ValidationResult{}
}
if !spinSvc.GetSpinnakerValidation().IsProviderValidationEnabled(awsAccountType) || !accountEnabled {
return ValidationResult{}
}
awsAccounts, err := spinSvc.GetSpinnakerConfig().GetHalConfigObjectArray(options.Ctx, awsAccountsKey)
if err != nil {
// Ignore, key or format don't match expectations
return ValidationResult{}
}
for _, a := range awsAccounts {
var awsAccount AwsAccount
if err := mapstructure.Decode(a, &awsAccount); err != nil {
return NewResultFromError(err, true)
}
for _, hook := range awsAccount.LifecycleHooks {
if errs := d.awsLifecycleHookValidation.validate(hook); errs != nil && len(errs) > 0 {
return NewResultFromErrors(errs, true)
}
}
}
return ValidationResult{}
}