Skip to content

Commit

Permalink
🐛 fix crash on aws.iam.virtualMfaDevices & logGroup.metricsFilters al…
Browse files Browse the repository at this point in the history
…arms failure (#3190)

* 🐛 fix crash on aws.iam.virtualMfaDevices

* 🐛 fix aws cloudwatch logs metrics alarms initialization

* set the error for the virtualmfadevice
  • Loading branch information
vjeffrey authored Feb 2, 2024
1 parent f6152ae commit 0f04f4b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 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 @@ -431,7 +431,7 @@ func (a *mqlAwsCloudwatchMetric) alarms() ([]interface{}, error) {
}
res := []interface{}{}
for _, alarm := range alarmsResp.MetricAlarms {
mqlAlarm, err := CreateResource(a.MqlRuntime, "aws.cloudwatch.metricsalarm",
mqlAlarm, err := NewResource(a.MqlRuntime, "aws.cloudwatch.metricsalarm",
map[string]*llx.RawData{"arn": llx.StringData(convert.ToString(alarm.AlarmArn))})
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion providers/aws/resources/aws_ec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ func (a *mqlAwsEc2) gatherInstanceInfo(instances []ec2types.Reservation, imdsvVe
if err == nil {
args["image"] = llx.ResourceData(mqlImage, mqlImage.MqlName())
} else {
log.Error().Err(err).Msg("cannot find image")
// this is a common case, logging the error here only creates confusion
args["image"] = llx.NilData
}
} else {
Expand Down
36 changes: 20 additions & 16 deletions providers/aws/resources/aws_iam.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,9 @@ func (a *mqlAwsIam) virtualMfaDevices() ([]interface{}, error) {

devicesResp, err := svc.ListVirtualMFADevices(ctx, &iam.ListVirtualMFADevicesInput{})
if err != nil {
return nil, errors.Wrap(err, "could not gather aws iam virtual-mfa-devices")
log.Error().Err(err).Msg("cannot gather virtual mfa devices info")
a.VirtualMfaDevices = plugin.TValue[[]interface{}]{Error: err, State: plugin.StateIsSet}
return nil, nil
}

// note: adding pagination to this call results in Throttling: Rate exceeded error
Expand Down Expand Up @@ -721,23 +723,25 @@ func initAwsIamUser(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[
ctx := context.Background()

if args["name"] != nil {
username := args["name"].Value.(string)
resp, err := svc.GetUser(ctx, &iam.GetUserInput{
UserName: &username,
})
if err != nil {
return nil, nil, err
}
if usr, ok := args["name"].Value.(string); ok {
username := usr
resp, err := svc.GetUser(ctx, &iam.GetUserInput{
UserName: &username,
})
if err != nil {
return nil, nil, err
}

usr := resp.User
args["arn"] = llx.StringDataPtr(usr.Arn)
args["id"] = llx.StringDataPtr(usr.UserId)
args["name"] = llx.StringDataPtr(usr.UserName)
args["createDate"] = llx.TimeDataPtr(usr.CreateDate)
args["passwordLastUsed"] = llx.TimeDataPtr(usr.PasswordLastUsed)
args["tags"] = llx.MapData(iamTagsToMap(usr.Tags), types.String)
usr := resp.User
args["arn"] = llx.StringDataPtr(usr.Arn)
args["id"] = llx.StringDataPtr(usr.UserId)
args["name"] = llx.StringDataPtr(usr.UserName)
args["createDate"] = llx.TimeDataPtr(usr.CreateDate)
args["passwordLastUsed"] = llx.TimeDataPtr(usr.PasswordLastUsed)
args["tags"] = llx.MapData(iamTagsToMap(usr.Tags), types.String)

return args, nil, nil
return args, nil, nil
}
}

return args, nil, nil
Expand Down

0 comments on commit 0f04f4b

Please sign in to comment.