Skip to content
This repository has been archived by the owner on Aug 16, 2022. It is now read-only.

Commit

Permalink
fix: Do not fail if ec2 image is not found (#1170)
Browse files Browse the repository at this point in the history
Remove some PII.
  • Loading branch information
irmatov authored Jul 6, 2022
1 parent bcfb724 commit a0d6104
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions client/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ 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])`)
Expand Down Expand Up @@ -270,6 +271,7 @@ func removePII(aa []string, msg string) string {
msg = s3Regex.ReplaceAllString(msg, "${1}${2}=xxxx${5}")
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 = accountObfusactor(aa, msg)

return msg
Expand Down
4 changes: 4 additions & 0 deletions client/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ func TestRemovePII(t *testing.T) {
`qldb.ledgers: failed to resolve table "aws_qldb_ledgers": error at github.com/cloudquery/cq-provider-aws/resources/services/qldb.fetchQldbLedgers[ledgers.go:264] operation error QLDB: ListLedgers, exceeded maximum number of attempts, 10, https response error StatusCode: 0, RequestID: , request send failed, Get "https://qldb.ap-southeast-1.amazonaws.com/ledgers": dial tcp: lookup qldb.ap-southeast-1.amazonaws.com on 172.20.0.10:53: no such host`,
`qldb.ledgers: failed to resolve table "aws_qldb_ledgers": error at github.com/cloudquery/cq-provider-aws/resources/services/qldb.fetchQldbLedgers[ledgers.go:264] operation error QLDB: ListLedgers, exceeded maximum number of attempts, 10, https response error StatusCode: 0, RequestID: , request send failed, Get "https://xxxx": dial tcp: lookup xxxx on xxxx:xx: no such host`,
},
{
`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`,
},
}
for i, tc := range cases {
res := removePII([]string{"123456789"}, tc.Input)
Expand Down
1 change: 1 addition & 0 deletions client/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ var (
)

var notFoundErrorSubstrings = []string{
"InvalidAMIID.Unavailable",
"NoSuch",
"NotFound",
"ResourceNotFoundException",
Expand Down
3 changes: 3 additions & 0 deletions resources/services/ec2/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,9 @@ func resolveEc2ImageLastLaunchedTime(ctx context.Context, meta schema.ClientMeta
options.Region = cl.Region
})
if err != nil {
if cl.IsNotFoundError(err) {
return nil
}
return diag.WrapError(err)
}
if result.LastLaunchedTime == nil || result.LastLaunchedTime.Value == nil {
Expand Down

0 comments on commit a0d6104

Please sign in to comment.