Skip to content

Commit

Permalink
🐛 bugfixes for aws
Browse files Browse the repository at this point in the history
  • Loading branch information
vjeffrey committed Oct 4, 2023
1 parent bb97aec commit c6e720c
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 18 deletions.
2 changes: 1 addition & 1 deletion providers/aws/resources/aws.lr.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
30 changes: 15 additions & 15 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 All @@ -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
Expand All @@ -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,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
}
Expand Down
3 changes: 3 additions & 0 deletions providers/aws/resources/aws_iam.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

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 c6e720c

Please sign in to comment.