Skip to content

Commit

Permalink
Use MQL functions to retrieve aws resources, making use of the cache. (
Browse files Browse the repository at this point in the history
…#2194)

* Use MQL functions to retrieve aws resources, making use of the cache.

* fix logging.
  • Loading branch information
preslavgerchev authored Oct 12, 2023
1 parent 60c4214 commit 0782671
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
17 changes: 9 additions & 8 deletions providers/aws/resources/aws_ec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -854,8 +854,8 @@ func initAwsEc2Securitygroup(runtime *plugin.Runtime, args map[string]*llx.RawDa
}
awsEc2 := obj.(*mqlAwsEc2)

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

Expand All @@ -875,8 +875,8 @@ func initAwsEc2Securitygroup(runtime *plugin.Runtime, args map[string]*llx.RawDa
}
}

for i := range rawResources {
securityGroup := rawResources[i].(*mqlAwsEc2Securitygroup)
for i := range rawResources.Data {
securityGroup := rawResources.Data[i].(*mqlAwsEc2Securitygroup)
if match(securityGroup) {
return args, securityGroup, nil
}
Expand Down Expand Up @@ -1111,6 +1111,7 @@ func initAwsEc2Instance(runtime *plugin.Runtime, args map[string]*llx.RawData) (
return args, nil, nil
}

log.Debug().Msg("init an ec2 instance")
if len(args) == 0 {
if ids := getAssetIdentifier(runtime); ids != nil {
args["arn"] = llx.StringData(ids.arn)
Expand All @@ -1127,14 +1128,14 @@ func initAwsEc2Instance(runtime *plugin.Runtime, args map[string]*llx.RawData) (
}
ec2 := obj.(*mqlAwsEc2)

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

arnVal := args["arn"].Value.(string)
for i := range rawResources {
instance := rawResources[i].(*mqlAwsEc2Instance)
for i := range rawResources.Data {
instance := rawResources.Data[i].(*mqlAwsEc2Instance)
if instance.Arn.Data == arnVal {
return args, instance, nil
}
Expand Down
8 changes: 4 additions & 4 deletions providers/aws/resources/aws_vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,8 @@ func initAwsVpc(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[stri
}
a := obj.(*mqlAws)

rawResources, err := a.vpcs()
if err != nil {
rawResources := a.GetVpcs()
if rawResources.Error != nil {
return nil, nil, err
}

Expand All @@ -313,8 +313,8 @@ func initAwsVpc(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[stri
}
}

for i := range rawResources {
volume := rawResources[i].(*mqlAwsVpc)
for i := range rawResources.Data {
volume := rawResources.Data[i].(*mqlAwsVpc)
if match(volume) {
return args, volume, nil
}
Expand Down

0 comments on commit 0782671

Please sign in to comment.