-
Notifications
You must be signed in to change notification settings - Fork 9.3k
/
verify.go
132 lines (105 loc) · 3.6 KB
/
verify.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package verify
import (
"github.com/aws/aws-sdk-go/aws/endpoints"
"github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr"
"gopkg.in/yaml.v2"
)
const UUIDRegexPattern = `[a-f0-9]{8}-[a-f0-9]{4}-[1-5][a-f0-9]{3}-[ab89][a-f0-9]{3}-[a-f0-9]{12}`
func SliceContainsString(slice []interface{}, s string) (int, bool) {
for idx, value := range slice {
v := value.(string)
if v == s {
return idx, true
}
}
return -1, false
}
// Takes a value containing YAML string and passes it through
// the YAML parser. Returns either a parsing
// error or original YAML string.
func checkYAMLString(yamlString interface{}) (string, error) {
var y interface{}
if yamlString == nil || yamlString.(string) == "" {
return "", nil
}
s := yamlString.(string)
err := yaml.Unmarshal([]byte(s), &y)
return s, err
}
const (
ErrCodeAccessDenied = "AccessDenied"
ErrCodeAuthorizationError = "AuthorizationError"
ErrCodeInternalException = "InternalException"
ErrCodeInternalServiceError = "InternalServiceError"
ErrCodeInvalidAction = "InvalidAction"
ErrCodeInvalidParameterException = "InvalidParameterException"
ErrCodeInvalidParameterValue = "InvalidParameterValue"
ErrCodeInvalidRequest = "InvalidRequest"
ErrCodeOperationDisabledException = "OperationDisabledException"
ErrCodeOperationNotPermitted = "OperationNotPermitted"
ErrCodeUnknownOperationException = "UnknownOperationException"
ErrCodeUnsupportedFeatureException = "UnsupportedFeatureException"
ErrCodeUnsupportedOperation = "UnsupportedOperation"
ErrCodeValidationError = "ValidationError"
ErrCodeValidationException = "ValidationException"
)
// ErrorISOUnsupported checks the partition and specific error to make
// an educated guess about whether the problem stems from a feature not being
// available in ISO (or non standard partitions) that is normally available.
// true means that there is an error AND it suggests a feature is not supported
// in ISO. Be careful with false, which means either there is NO error or there
// is an error but not one that suggests an unsupported feature in ISO.
func ErrorISOUnsupported(partition string, err error) bool {
if partition == endpoints.AwsPartitionID {
return false
}
if err == nil { // not strictly necessary but make logic clearer
return false
}
if tfawserr.ErrCodeContains(err, ErrCodeAccessDenied) {
return true
}
if tfawserr.ErrCodeContains(err, ErrCodeAuthorizationError) {
return true
}
if tfawserr.ErrCodeContains(err, ErrCodeInternalException) {
return true
}
if tfawserr.ErrCodeContains(err, ErrCodeInternalServiceError) {
return true
}
if tfawserr.ErrCodeContains(err, ErrCodeInvalidAction) {
return true
}
if tfawserr.ErrCodeContains(err, ErrCodeInvalidParameterException) {
return true
}
if tfawserr.ErrCodeContains(err, ErrCodeInvalidParameterValue) {
return true
}
if tfawserr.ErrCodeContains(err, ErrCodeInvalidRequest) {
return true
}
if tfawserr.ErrCodeContains(err, ErrCodeOperationDisabledException) {
return true
}
if tfawserr.ErrCodeContains(err, ErrCodeOperationNotPermitted) {
return true
}
if tfawserr.ErrCodeContains(err, ErrCodeUnknownOperationException) {
return true
}
if tfawserr.ErrCodeContains(err, ErrCodeUnsupportedFeatureException) {
return true
}
if tfawserr.ErrCodeContains(err, ErrCodeUnsupportedOperation) {
return true
}
if tfawserr.ErrMessageContains(err, ErrCodeValidationError, "not support tagging") {
return true
}
if tfawserr.ErrCodeContains(err, ErrCodeValidationException) {
return true
}
return false
}