Skip to content

Commit

Permalink
🐛 clean up some of the aws resource init functions
Browse files Browse the repository at this point in the history
  • Loading branch information
vjeffrey committed Oct 3, 2023
1 parent a4118a5 commit e701ebf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion providers/aws/resources/aws_cloudwatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 10 additions & 10 deletions providers/aws/resources/aws_ec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -824,7 +824,7 @@ 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) {
Expand Down
2 changes: 1 addition & 1 deletion providers/aws/resources/aws_sns.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit e701ebf

Please sign in to comment.