From c6e720c0b88e3f26f682b249e26044b5b9c9c617 Mon Sep 17 00:00:00 2001 From: Victoria Jeffrey Date: Tue, 3 Oct 2023 00:33:52 -0600 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20bugfixes=20for=20aws?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- providers/aws/resources/aws.lr.go | 2 +- providers/aws/resources/aws_cloudwatch.go | 2 +- providers/aws/resources/aws_ec2.go | 30 +++++++++++------------ providers/aws/resources/aws_iam.go | 3 +++ providers/aws/resources/aws_sns.go | 2 +- 5 files changed, 21 insertions(+), 18 deletions(-) diff --git a/providers/aws/resources/aws.lr.go b/providers/aws/resources/aws.lr.go index 9d537abca1..9a9afd9e42 100644 --- a/providers/aws/resources/aws.lr.go +++ b/providers/aws/resources/aws.lr.go @@ -467,7 +467,7 @@ func init() { Create: createAwsEc2InstanceDevice, }, "aws.ec2.securitygroup": { - // to override args, implement: initAwsEc2Securitygroup(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) + Init: initAwsEc2Securitygroup, Create: createAwsEc2Securitygroup, }, "aws.ec2.securitygroup.ippermission": { diff --git a/providers/aws/resources/aws_cloudwatch.go b/providers/aws/resources/aws_cloudwatch.go index 47f58f0769..df937b1704 100644 --- a/providers/aws/resources/aws_cloudwatch.go +++ b/providers/aws/resources/aws_cloudwatch.go @@ -176,7 +176,7 @@ func initAwsCloudwatchMetric(runtime *plugin.Runtime, args map[string]*llx.RawDa return args, nil, err } if len(metrics.Metrics) == 0 { - return nil, nil, nil + return nil, nil, errors.New("no metrics found") } if len(metrics.Metrics) > 1 { return nil, nil, errors.New("more than one metric found for " + namespace + " " + name + " in region " + region) diff --git a/providers/aws/resources/aws_ec2.go b/providers/aws/resources/aws_ec2.go index 62db92eb53..324de8edd3 100644 --- a/providers/aws/resources/aws_ec2.go +++ b/providers/aws/resources/aws_ec2.go @@ -733,11 +733,11 @@ func (a *mqlAwsEc2) gatherInstanceInfo(instances []ec2types.Reservation, imdsvVe if instance.ImageId != nil { mqlImage, err := NewResource(a.MqlRuntime, "aws.ec2.image", map[string]*llx.RawData{"arn": llx.StringData(fmt.Sprintf(imageArnPattern, regionVal, conn.AccountId(), convert.ToString(instance.ImageId)))}) - if err != nil { - return nil, err - } - if mqlImage != nil { + if err == nil { args["image"] = llx.ResourceData(mqlImage, mqlImage.MqlName()) + } else { + log.Error().Err(err).Msg("cannot find image") + args["image"] = llx.NilData } } else { args["image"] = llx.NilData @@ -749,11 +749,11 @@ func (a *mqlAwsEc2) gatherInstanceInfo(instances []ec2types.Reservation, imdsvVe map[string]*llx.RawData{ "arn": llx.StringData(fmt.Sprintf(vpcArnPattern, regionVal, conn.AccountId(), convert.ToString(instance.VpcId))), }) - if err != nil { - return nil, err - } - if mqlVpcResource != nil { + if err == nil { args["vpc"] = llx.ResourceData(mqlVpcResource, mqlVpcResource.MqlName()) + } else { + log.Error().Err(err).Msg("cannot find vpc") + args["vpc"] = llx.NilData } } else { args["vpc"] = llx.NilData @@ -766,11 +766,11 @@ func (a *mqlAwsEc2) gatherInstanceInfo(instances []ec2types.Reservation, imdsvVe "region": llx.StringData(regionVal), "name": llx.StringData(convert.ToString(instance.KeyName)), }) - if err != nil { - return nil, err - } - if mqlKeyPair != nil { + if err == nil { args["keypair"] = llx.ResourceData(mqlKeyPair, mqlKeyPair.MqlName()) + } else { + log.Error().Err(err).Msg("cannot find keypair") + args["keypair"] = llx.NilData } } else { args["keypair"] = llx.NilData @@ -802,7 +802,7 @@ func initAwsEc2Image(runtime *plugin.Runtime, args map[string]*llx.RawData) (map arnVal := args["arn"].Value.(string) arn, err := arn.Parse(arnVal) if err != nil { - return nil, nil, nil + return nil, nil, err } resource := strings.Split(arn.Resource, "/") conn := runtime.Connection.(*connection.AwsConnection) @@ -824,14 +824,14 @@ func initAwsEc2Image(runtime *plugin.Runtime, args map[string]*llx.RawData) (map return args, nil, nil } - return args, nil, nil + return nil, nil, errors.New("image not found") } func (a *mqlAwsEc2Securitygroup) id() (string, error) { return a.Arn.Data, nil } -func initAwsEc2SecurityGroup(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) { +func initAwsEc2Securitygroup(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) { if len(args) > 2 { return args, nil, nil } diff --git a/providers/aws/resources/aws_iam.go b/providers/aws/resources/aws_iam.go index e1bcb2ca0c..46084ed9db 100644 --- a/providers/aws/resources/aws_iam.go +++ b/providers/aws/resources/aws_iam.go @@ -854,6 +854,9 @@ func (a *mqlAwsIamUser) attachedPolicies() ([]interface{}, error) { } func (a *mqlAwsIamPolicy) id() (string, error) { + if a == nil { + return "", nil + } return a.Arn.Data, nil } diff --git a/providers/aws/resources/aws_sns.go b/providers/aws/resources/aws_sns.go index cec7a2120f..cb3120ea3c 100644 --- a/providers/aws/resources/aws_sns.go +++ b/providers/aws/resources/aws_sns.go @@ -60,7 +60,7 @@ func (a *mqlAwsSnsTopic) init(runtime *plugin.Runtime, args map[string]*llx.RawD arnVal := args["arn"].Value.(string) arn, err := arn.Parse(arnVal) if err != nil { - return nil, nil, nil + return nil, nil, err } args["arn"] = llx.StringData(arnVal)