diff --git a/client/errors.go b/client/errors.go index ebdea3aaa..0fb0ee16d 100644 --- a/client/errors.go +++ b/client/errors.go @@ -35,12 +35,13 @@ var ( `\bdial\s(tcp|udp)\s` + // "dial tcp " fmt.Sprintf(`(?:%s|%s):\d+`, ipv4Regex, bracketedIpv6Regex), // "192.168.1.2:123" or "[::1]:123" ) - ec2ImageIdRegex = regexp.MustCompile(`The image ID '[^']+'`) - encAuthRegex = regexp.MustCompile(`(\s)(Encoded authorization failure message:)\s[A-Za-z0-9_-]+`) - userRegex = regexp.MustCompile(`(\s)(is not authorized to perform: .+ on resource:\s)(user)\s.+`) - s3Regex = regexp.MustCompile(`(\s)(S3(Key|Bucket))=(.+?)([,;\s])`) - resourceNotExistsRegex = regexp.MustCompile(`(\sThe )([A-Za-z0-9 -]+ )'([A-Za-z0-9-]+?)'( does not exist)`) - resourceNotFoundRegex = regexp.MustCompile(`([A-Za-z0-9 -]+)( name not found - Could not find )([A-Za-z0-9 -]+)( named )'([A-Za-z0-9-]+?)'`) + ec2ImageIdRegex = regexp.MustCompile(`The image ID '[^']+'`) + encAuthRegex = regexp.MustCompile(`(\s)(Encoded authorization failure message:)\s[A-Za-z0-9_-]+`) + userRegex = regexp.MustCompile(`(\s)(is not authorized to perform: .+ on resource:\s)(user)\s.+`) + s3Regex = regexp.MustCompile(`(\s)(S3(Key|Bucket))=(.+?)([,;\s])`) + resourceNotExistsRegex = regexp.MustCompile(`(\sThe )([A-Za-z0-9 -]+ )'([A-Za-z0-9-]+?)'( does not exist)`) + resourceNotFoundRegex = regexp.MustCompile(`([A-Za-z0-9 -]+)( name not found - Could not find )([A-Za-z0-9 -]+)( named )'([A-Za-z0-9-]+?)'`) + autoscalingGroupNotFound = regexp.MustCompile(`(ValidationError: Group ).+( not found)`) ) var errorCodeDescriptions = map[string]string{ @@ -272,6 +273,7 @@ func removePII(aa []string, msg string) string { msg = resourceNotExistsRegex.ReplaceAllString(msg, "${1}${2}'xxxx'${4}") msg = resourceNotFoundRegex.ReplaceAllString(msg, "${1}${2}${3}${4}'xxxx'") msg = ec2ImageIdRegex.ReplaceAllString(msg, "The image ID 'xxxx'") + msg = autoscalingGroupNotFound.ReplaceAllString(msg, "${1}xxxx${2}") msg = accountObfusactor(aa, msg) return msg diff --git a/client/errors_test.go b/client/errors_test.go index 7dfd16e58..d694acbac 100644 --- a/client/errors_test.go +++ b/client/errors_test.go @@ -67,6 +67,10 @@ func TestRemovePII(t *testing.T) { `operation error EC2: DescribeImageAttribute, https response error StatusCode: 400, RequestID: 3PQRRTJ1BAB82DWH, api error InvalidAMIID.Unavailable: The image ID 'ami-01964cde3b8020132' is no longer available`, `operation error EC2: DescribeImageAttribute, https response error StatusCode: 400, RequestID: xxxx, api error InvalidAMIID.Unavailable: The image ID 'xxxx' is no longer available`, }, + { + `operation error Auto Scaling: DescribePolicies, https response error StatusCode: 400, RequestID: 3PQRRTJ1BAB82DWH, api error ValidationError: Group group-name not found`, + `operation error Auto Scaling: DescribePolicies, https response error StatusCode: 400, RequestID: xxxx, api error ValidationError: Group xxxx not found`, + }, } for i, tc := range cases { res := removePII([]string{"123456789"}, tc.Input) diff --git a/resources/services/autoscaling/groups.go b/resources/services/autoscaling/groups.go index 0135444de..3052278de 100644 --- a/resources/services/autoscaling/groups.go +++ b/resources/services/autoscaling/groups.go @@ -4,7 +4,7 @@ import ( "context" "encoding/json" "errors" - "strings" + "regexp" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/autoscaling" @@ -15,6 +15,8 @@ import ( "github.com/cloudquery/cq-provider-sdk/provider/schema" ) +var groupNotFoundRegex = regexp.MustCompile(`AutoScalingGroup name not found|Group .* not found`) + type autoscalingGroupWrapper struct { types.AutoScalingGroup NotificationConfigurations []types.NotificationConfiguration @@ -703,6 +705,9 @@ func fetchAutoscalingGroupScalingPolicies(ctx context.Context, meta schema.Clien o.Region = cl.Region }) if err != nil { + if isAutoScalingGroupNotExistsError(err) { + return nil + } return diag.WrapError(err) } res <- output.ScalingPolicies @@ -751,6 +756,9 @@ func fetchAutoscalingGroupLifecycleHooks(ctx context.Context, meta schema.Client o.Region = cl.Region }) if err != nil { + if isAutoScalingGroupNotExistsError(err) { + return nil + } return diag.WrapError(err) } res <- output.LifecycleHooks @@ -774,7 +782,7 @@ func getNotificationConfigurationByGroupName(name string, set []types.Notificati func isAutoScalingGroupNotExistsError(err error) bool { var ae smithy.APIError if errors.As(err, &ae) { - if ae.ErrorCode() == "ValidationError" && strings.Contains(ae.ErrorMessage(), "AutoScalingGroup name not found") { + if ae.ErrorCode() == "ValidationError" && groupNotFoundRegex.MatchString(ae.ErrorMessage()) { return true } }