Skip to content

Commit

Permalink
🐛 Fix aws dynamodb table init function, make all AWS init funcs use t…
Browse files Browse the repository at this point in the history
…he mql cache (#2198)

* 🐛 Fix aws dynamodb table init function, make all AWS init funcs use MQL's GetX() retrieval funcs.

* Remove redundant err checks.
  • Loading branch information
preslavgerchev authored Oct 13, 2023
1 parent ce28531 commit 9d865c9
Show file tree
Hide file tree
Showing 16 changed files with 91 additions and 84 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.

8 changes: 4 additions & 4 deletions providers/aws/resources/aws_apigateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,14 @@ func initAwsApigatewayRestapi(runtime *plugin.Runtime, args map[string]*llx.RawD
}
gw := obj.(*mqlAwsApigateway)

rawResources, err := gw.restApis()
if err != nil {
rawResources := gw.GetRestApis()
if rawResources.Error != nil {
return nil, nil, err
}

arnVal := args["arn"].Value.(string)
for i := range rawResources {
restApi := rawResources[i].(*mqlAwsApigatewayRestapi)
for i := range rawResources.Data {
restApi := rawResources.Data[i].(*mqlAwsApigatewayRestapi)
if restApi.Arn.Data == arnVal {
return args, restApi, nil
}
Expand Down
9 changes: 6 additions & 3 deletions providers/aws/resources/aws_cloudtrail.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,13 @@ func initAwsCloudtrailTrail(runtime *plugin.Runtime, args map[string]*llx.RawDat
}
awsCloudtrail := obj.(*mqlAwsCloudtrail)

rawResources := awsCloudtrail.GetTrails().Data
rawResources := awsCloudtrail.GetTrails()
if rawResources.Error != nil {
return nil, nil, rawResources.Error
}

for i := range rawResources {
trail := rawResources[i].(*mqlAwsCloudtrailTrail)
for i := range rawResources.Data {
trail := rawResources.Data[i].(*mqlAwsCloudtrailTrail)
if trail.Arn.Data == arn {
return args, trail, nil
}
Expand Down
18 changes: 12 additions & 6 deletions providers/aws/resources/aws_cloudwatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -659,11 +659,14 @@ func initAwsCloudwatchLoggroup(runtime *plugin.Runtime, args map[string]*llx.Raw
return nil, nil, err
}
cloudwatch := obj.(*mqlAwsCloudwatch)
rawResources := cloudwatch.GetLogGroups().Data
rawResources := cloudwatch.GetLogGroups()
if rawResources.Error != nil {
return nil, nil, rawResources.Error
}

arnVal := args["arn"].Value.(string)
for i := range rawResources {
loggroup := rawResources[i].(*mqlAwsCloudwatchLoggroup)
for i := range rawResources.Data {
loggroup := rawResources.Data[i].(*mqlAwsCloudwatchLoggroup)
mqlLgArn := loggroup.Arn.Data

if mqlLgArn == arnVal {
Expand Down Expand Up @@ -766,11 +769,14 @@ func initAwsCloudwatchMetricsalarm(runtime *plugin.Runtime, args map[string]*llx
}
aws := obj.(*mqlAwsCloudwatch)

rawResources := aws.GetAlarms().Data
rawResources := aws.GetAlarms()
if rawResources.Error != nil {
return nil, nil, rawResources.Error
}

arnVal := args["arn"].Value.(string)
for i := range rawResources {
alarm := rawResources[i].(*mqlAwsCloudwatchMetricsalarm)
for i := range rawResources.Data {
alarm := rawResources.Data[i].(*mqlAwsCloudwatchMetricsalarm)
if alarm.Arn.Data == arnVal {
return args, alarm, nil
}
Expand Down
22 changes: 11 additions & 11 deletions providers/aws/resources/aws_dynamodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (a *mqlAwsDynamodb) getBackups(conn *connection.AwsConnection) []*jobpool.J
return tasks
}

func initDynamoDbTable(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) {
func initAwsDynamodbTable(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) {
if len(args) > 2 {
return args, nil, nil
}
Expand All @@ -102,14 +102,14 @@ func initDynamoDbTable(runtime *plugin.Runtime, args map[string]*llx.RawData) (m
}
dynamodb := obj.(*mqlAwsDynamodb)

rawResources, err := dynamodb.tables()
if err != nil {
return nil, nil, err
rawResources := dynamodb.GetTables()
if rawResources.Error != nil {
return nil, nil, rawResources.Error
}

arnVal := args["arn"].Value.(string)
for i := range rawResources {
dbInstance := rawResources[i].(*mqlAwsDynamodbTable)
for i := range rawResources.Data {
dbInstance := rawResources.Data[i].(*mqlAwsDynamodbTable)
if dbInstance.Arn.Data == arnVal {
return args, dbInstance, nil
}
Expand Down Expand Up @@ -360,14 +360,14 @@ func initAwsDynamodbGlobaltable(runtime *plugin.Runtime, args map[string]*llx.Ra
}
dynamodb := obj.(*mqlAwsDynamodb)

rawResources, err := dynamodb.globalTables()
if err != nil {
return nil, nil, err
rawResources := dynamodb.GetGlobalTables()
if rawResources.Error != nil {
return nil, nil, rawResources.Error
}

arnVal := args["arn"].Value.(string)
for i := range rawResources {
dbInstance := rawResources[i].(*mqlAwsDynamodbGlobaltable)
for i := range rawResources.Data {
dbInstance := rawResources.Data[i].(*mqlAwsDynamodbGlobaltable)
if dbInstance.Arn.Data == arnVal {
return args, dbInstance, nil
}
Expand Down
17 changes: 8 additions & 9 deletions providers/aws/resources/aws_ec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -1085,8 +1085,8 @@ func initAwsEc2Volume(runtime *plugin.Runtime, args map[string]*llx.RawData) (ma
}
awsEc2 := obj.(*mqlAwsEc2)

rawResources, err := awsEc2.volumes()
if err != nil {
rawResources := awsEc2.GetVolumes()
if rawResources.Error != nil {
return nil, nil, err
}

Expand All @@ -1099,8 +1099,8 @@ func initAwsEc2Volume(runtime *plugin.Runtime, args map[string]*llx.RawData) (ma
}
}

for i := range rawResources {
volume := rawResources[i].(*mqlAwsEc2Volume)
for i := range rawResources.Data {
volume := rawResources.Data[i].(*mqlAwsEc2Volume)
if match(volume) {
return args, volume, nil
}
Expand Down Expand Up @@ -1168,11 +1168,10 @@ func initAwsEc2Snapshot(runtime *plugin.Runtime, args map[string]*llx.RawData) (
}
awsEc2 := obj.(*mqlAwsEc2)

rawResources, err := awsEc2.snapshots()
if err != nil {
rawResources := awsEc2.GetSnapshots()
if rawResources.Error != nil {
return nil, nil, err
}

var match func(snapshot *mqlAwsEc2Snapshot) bool

if args["arn"] != nil {
Expand All @@ -1189,8 +1188,8 @@ func initAwsEc2Snapshot(runtime *plugin.Runtime, args map[string]*llx.RawData) (
}
}

for i := range rawResources {
snapshot := rawResources[i].(*mqlAwsEc2Snapshot)
for i := range rawResources.Data {
snapshot := rawResources.Data[i].(*mqlAwsEc2Snapshot)
if match(snapshot) {
return args, snapshot, nil
}
Expand Down
11 changes: 5 additions & 6 deletions providers/aws/resources/aws_ecr.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,13 @@ func initAwsEcrImage(runtime *plugin.Runtime, args map[string]*llx.RawData) (map
}
ecr := obj.(*mqlAwsEcr)

rawResources, err := ecr.images()
if err != nil {
return nil, nil, err
rawResources := ecr.GetImages()
if rawResources.Error != nil {
return nil, nil, rawResources.Error
}

arnVal := args["arn"].Value.(string)
for i := range rawResources {
image := rawResources[i].(*mqlAwsEcrImage)
for i := range rawResources.Data {
image := rawResources.Data[i].(*mqlAwsEcrImage)
if image.Arn.Data == arnVal {
return args, image, nil
}
Expand Down
11 changes: 6 additions & 5 deletions providers/aws/resources/aws_ecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,14 +441,15 @@ func initAwsEcsContainer(runtime *plugin.Runtime, args map[string]*llx.RawData)
}
ecs := obj.(*mqlAwsEcs)

rawResources, err := ecs.containers()
if err != nil {
return nil, nil, err
rawResources := ecs.GetContainers()

if rawResources.Error != nil {
return nil, nil, rawResources.Error
}

arnVal := args["arn"].Value.(string)
for i := range rawResources {
container := rawResources[i].(*mqlAwsEcsContainer)
for i := range rawResources.Data {
container := rawResources.Data[i].(*mqlAwsEcsContainer)
if container.Arn.Data == arnVal {
return args, container, nil
}
Expand Down
10 changes: 5 additions & 5 deletions providers/aws/resources/aws_elb.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,14 @@ func initAwsElbLoadBalancer(runtime *plugin.Runtime, args map[string]*llx.RawDat
}
elb := obj.(*mqlAwsElb)

rawResources, err := elb.loadBalancers()
if err != nil {
return nil, nil, err
rawResources := elb.GetLoadBalancers()
if rawResources.Error != nil {
return nil, nil, rawResources.Error
}

arnVal := args["arn"].Value.(string)
for i := range rawResources {
lb := rawResources[i].(*mqlAwsElbLoadbalancer)
for i := range rawResources.Data {
lb := rawResources.Data[i].(*mqlAwsElbLoadbalancer)
if lb.Arn.Data == arnVal {
return args, lb, nil
}
Expand Down
11 changes: 5 additions & 6 deletions providers/aws/resources/aws_kms.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,12 @@ func initAwsKmsKey(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[s
}
kms := obj.(*mqlAwsKms)

rawResources, err := kms.keys()
if err != nil {
return nil, nil, err
rawResources := kms.GetKeys()
if rawResources.Error != nil {
return nil, nil, rawResources.Error
}

for i := range rawResources {
key := rawResources[i].(*mqlAwsKmsKey)
for i := range rawResources.Data {
key := rawResources.Data[i].(*mqlAwsKmsKey)
if key.Arn.Data == a {
return args, key, nil
}
Expand Down
10 changes: 5 additions & 5 deletions providers/aws/resources/aws_lambda.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,14 @@ func initAwsLambdaFunction(runtime *plugin.Runtime, args map[string]*llx.RawData
}
l := obj.(*mqlAwsLambda)

rawResources, err := l.functions()
if err != nil {
return nil, nil, err
rawResources := l.GetFunctions()
if rawResources.Error != nil {
return nil, nil, rawResources.Error
}

arnVal := args["arn"].Value.(string)
for i := range rawResources {
dbInstance := rawResources[i].(*mqlAwsLambdaFunction)
for i := range rawResources.Data {
dbInstance := rawResources.Data[i].(*mqlAwsLambdaFunction)
if dbInstance.Arn.Data == arnVal {
return args, dbInstance, nil
}
Expand Down
6 changes: 3 additions & 3 deletions providers/aws/resources/aws_rds.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,14 @@ func initAwsRdsDbinstance(runtime *plugin.Runtime, args map[string]*llx.RawData)
}
rds := obj.(*mqlAwsRds)

rawResources, err := rds.dbInstances()
rawResources := rds.GetDbInstances()
if err != nil {
return nil, nil, err
}

arnVal := args["arn"].Value.(string)
for i := range rawResources {
dbInstance := rawResources[i].(*mqlAwsRdsDbinstance)
for i := range rawResources.Data {
dbInstance := rawResources.Data[i].(*mqlAwsRdsDbinstance)
if dbInstance.Arn.Data == arnVal {
return args, dbInstance, nil
}
Expand Down
10 changes: 5 additions & 5 deletions providers/aws/resources/aws_redshift.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,14 @@ func initAwsRedshiftCluster(runtime *plugin.Runtime, args map[string]*llx.RawDat
}
redshift := obj.(*mqlAwsRedshift)

rawResources, err := redshift.clusters()
if err != nil {
return nil, nil, err
rawResources := redshift.GetClusters()
if rawResources.Error != nil {
return nil, nil, rawResources.Error
}

arnVal := args["arn"].Value.(string)
for i := range rawResources {
cluster := rawResources[i].(*mqlAwsRedshiftCluster)
for i := range rawResources.Data {
cluster := rawResources.Data[i].(*mqlAwsRedshiftCluster)

if cluster.Arn.Data == arnVal {
return args, cluster, nil
Expand Down
10 changes: 5 additions & 5 deletions providers/aws/resources/aws_s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,14 @@ func initAwsS3Bucket(runtime *plugin.Runtime, args map[string]*llx.RawData) (map
}
awsS3 := obj.(*mqlAwsS3)

rawResources, err := awsS3.buckets()
if err != nil {
return nil, nil, err
rawResources := awsS3.GetBuckets()
if rawResources.Error != nil {
return nil, nil, rawResources.Error
}

// iterate over security groups and find the one with the arn
for i := range rawResources {
bucket := rawResources[i].(*mqlAwsS3Bucket)
for i := range rawResources.Data {
bucket := rawResources.Data[i].(*mqlAwsS3Bucket)
if bucket.Arn.Data == arn {
return args, bucket, nil
}
Expand Down
10 changes: 5 additions & 5 deletions providers/aws/resources/aws_sagemaker.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,14 @@ func initAwsSagemakerNotebookinstance(runtime *plugin.Runtime, args map[string]*
}
sm := obj.(*mqlAwsSagemaker)

rawResources, err := sm.notebookInstances()
if err != nil {
return nil, nil, err
rawResources := sm.GetNotebookInstances()
if rawResources.Error != nil {
return nil, nil, rawResources.Error
}

arnVal := args["arn"].Value.(string)
for i := range rawResources {
ni := rawResources[i].(*mqlAwsSagemakerNotebookinstance)
for i := range rawResources.Data {
ni := rawResources.Data[i].(*mqlAwsSagemakerNotebookinstance)
if ni.Arn.Data == arnVal {
return args, ni, nil
}
Expand Down
10 changes: 5 additions & 5 deletions providers/aws/resources/aws_ssm.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,14 @@ func initAwsSsmInstance(runtime *plugin.Runtime, args map[string]*llx.RawData) (
}
ssm := obj.(*mqlAwsSsm)

rawResources, err := ssm.instances()
if err != nil {
return nil, nil, err
rawResources := ssm.GetInstances()
if rawResources.Error != nil {
return nil, nil, rawResources.Error
}

arnVal := args["arn"].Value.(string)
for i := range rawResources {
instance := rawResources[i].(*mqlAwsSsmInstance)
for i := range rawResources.Data {
instance := rawResources.Data[i].(*mqlAwsSsmInstance)

if instance.Arn.Data == arnVal {
return args, instance, nil
Expand Down

0 comments on commit 9d865c9

Please sign in to comment.