/
errors.go
131 lines (123 loc) · 3.5 KB
/
errors.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
package ssm
import (
"github.com/aws/aws-sdk-go/aws/awserr"
awsssm "github.com/aws/aws-sdk-go/service/ssm"
)
// checkSSMError is the entry point for check all of the based and call specific errors
func checkSSMError(a action, err error) error {
awsErr := checkBaseSSMErrors(err)
switch a {
case Get:
return checkSSMGetParameterError(err)
case Save:
return checkSSMPutParameterError(err)
case Delete:
return checkDeleteParameterError(err)
}
return awsErr
}
// checkRegion catches if the aws region isn't configured
func checkRegion(err error) error {
if awsErr, ok := err.(awserr.Error); ok {
switch awsErr.Code() {
case "MissingRegion":
return awsErr
}
}
return nil
}
// checkBaseSSMErrors checks for the common errors all SSM API calls might return
func checkBaseSSMErrors(err error) error {
if awsErr, ok := err.(awserr.Error); ok {
switch awsErr.Code() {
case awsssm.ErrCodeInvalidKeyId:
return awsErr
case awsssm.ErrCodeInternalServerError:
return awsErr
}
}
return checkRegion(err)
}
func checkDeleteParameterError(err error) error {
if awsErr, ok := err.(awserr.Error); ok {
switch awsErr.Code() {
case awsssm.ErrCodeParameterNotFound:
return awsErr
default:
// this means we are missing a check and we can print it out in the calling function
return awsErr
}
}
return nil
}
// checkSSMGetParameterError checks for errors the GetParameter API call might return
func checkSSMGetParameterError(err error) error {
if awsErr, ok := err.(awserr.Error); ok {
switch awsErr.Code() {
case awsssm.ErrCodeParameterNotFound:
return awsErr
default:
// this means we are missing a check and we can print it out in the calling function
return awsErr
}
}
//return errors.New("SSM Get Param error")
return nil
}
// checkSSMPutParameterError checks for errors the PutParameter API call might return
func checkSSMPutParameterError(err error) error {
if awsErr, ok := err.(awserr.Error); ok {
switch awsErr.Code() {
//case awsssm.ErrCodeInvalidPa:
// return awsErr
case awsssm.ErrCodeParameterLimitExceeded:
return awsErr
case awsssm.ErrCodeTooManyUpdates:
return awsErr
case awsssm.ErrCodeHierarchyTypeMismatchException:
return awsErr
case awsssm.ErrCodeInvalidAllowedPatternException:
return awsErr
case awsssm.ErrCodeParameterMaxVersionLimitExceeded:
return awsErr
case awsssm.ErrCodeUnsupportedParameterType:
return awsErr
case awsssm.ErrCodePoliciesLimitExceededException:
return awsErr
case awsssm.ErrCodeInvalidPolicyTypeException:
return awsErr
case awsssm.ErrCodeInvalidPolicyAttributeException:
return awsErr
case awsssm.ErrCodeIncompatiblePolicyException:
return awsErr
case awsssm.ErrCodeParameterAlreadyExists:
return awsErr
default:
// this means we are missing a check and we can print it out in the calling function
return awsErr
}
}
//return errors.New("aws ssm param put error")
return nil
}
// checkSSMByPathError checks for errors the GetParameterByPath API call might return
func checkSSMByPathError(err error) error {
if awsErr, ok := err.(awserr.Error); ok {
switch awsErr.Code() {
case awsssm.ErrCodeInternalServerError:
return awsErr
case awsssm.ErrCodeInvalidFilterKey:
return awsErr
case awsssm.ErrCodeInvalidFilterOption:
return awsErr
case awsssm.ErrCodeInvalidFilterValue:
return awsErr
case awsssm.ErrCodeInvalidKeyId:
return awsErr
case awsssm.ErrCodeInvalidNextToken:
return awsErr
}
}
//return errors.New("aws ssm param get by path error")
return nil
}