Skip to content

Commit

Permalink
🧹 aws resource fixes (#3083)
Browse files Browse the repository at this point in the history
* 🐛 fix aws elb loadbalancer attributes

* 🧹 add dynamodb global table discovery

* 🧹 add log message for required namespace for aws applicationautoscaling

* 🧹 fixups
  • Loading branch information
vjeffrey authored Jan 23, 2024
1 parent 4a66f67 commit c4d1d8a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
3 changes: 3 additions & 0 deletions providers/aws/resources/aws_applicationautoscaling.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ func (a *mqlAwsApplicationautoscalingTarget) id() (string, error) {
func (a *mqlAwsApplicationAutoscaling) scalableTargets() ([]interface{}, error) {
conn := a.MqlRuntime.Connection.(*connection.AwsConnection)
namespace := a.Namespace.Data
if namespace == "" {
return nil, errors.New("namespace required for application autoscaling query. please specify one of [comprehend, rds, sagemaker, appstream, elasticmapreduce, dynamodb, lambda, ecs, cassandra, ec2, neptune, kafka, custom-resource, elasticache]")
}

res := []interface{}{}
poolOfJobs := jobpool.CreatePool(a.getTargets(conn, aatypes.ServiceNamespace(namespace)), 5)
Expand Down
35 changes: 33 additions & 2 deletions providers/aws/resources/aws_elb.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import (
"context"
"errors"
"fmt"
"strings"

"github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing"
"github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2"
"github.com/aws/aws-sdk-go/aws/arn"
"github.com/rs/zerolog/log"
"go.mondoo.com/cnquery/v10/llx"
"go.mondoo.com/cnquery/v10/providers-sdk/v1/plugin"
Expand Down Expand Up @@ -215,8 +217,12 @@ func (a *mqlAwsElbLoadbalancer) listenerDescriptions() ([]interface{}, error) {
if err != nil {
return nil, err
}
svc := conn.Elbv2(region)
ctx := context.Background()

if isV1LoadBalancerArn(arn) {
return a.ListenerDescriptions.Data, nil
}
svc := conn.Elbv2(region)
listeners, err := svc.DescribeListeners(ctx, &elasticloadbalancingv2.DescribeListenersInput{LoadBalancerArn: &arn})
if err != nil {
return nil, err
Expand All @@ -227,16 +233,41 @@ func (a *mqlAwsElbLoadbalancer) listenerDescriptions() ([]interface{}, error) {
func (a *mqlAwsElbLoadbalancer) attributes() ([]interface{}, error) {
conn := a.MqlRuntime.Connection.(*connection.AwsConnection)
arn := a.Arn.Data
name := a.Name.Data

region, err := GetRegionFromArn(arn)
if err != nil {
return nil, err
}
svc := conn.Elbv2(region)
ctx := context.Background()

if isV1LoadBalancerArn(arn) {
svc := conn.Elb(region)
attributes, err := svc.DescribeLoadBalancerAttributes(ctx, &elasticloadbalancing.DescribeLoadBalancerAttributesInput{LoadBalancerName: &name})
if err != nil {
return nil, err
}
j, err := convert.JsonToDict(attributes.LoadBalancerAttributes)
if err != nil {
return nil, err
}
return []interface{}{j}, nil
}
svc := conn.Elbv2(region)
attributes, err := svc.DescribeLoadBalancerAttributes(ctx, &elasticloadbalancingv2.DescribeLoadBalancerAttributesInput{LoadBalancerArn: &arn})
if err != nil {
return nil, err
}
return convert.JsonToDictSlice(attributes.Attributes)
}

func isV1LoadBalancerArn(a string) bool {
arnVal, err := arn.Parse(a)
if err != nil {
return false
}
if strings.Contains(arnVal.Resource, "classic") {
return true
}
return false
}
12 changes: 11 additions & 1 deletion providers/aws/resources/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const (
DiscoveryCloudwatchLoggroups = "cloudwatch-loggroups"
DiscoveryLambdaFunctions = "lambda-functions"
DiscoveryDynamoDBTables = "dynamodb-tables"
DiscoveryDynamoDBGlobalTables = "dynamodb-global-tables"
DiscoveryRedshiftClusters = "redshift-clusters"
DiscoveryVolumes = "ec2-volumes"
DiscoverySnapshots = "ec2-snapshots"
Expand Down Expand Up @@ -80,6 +81,7 @@ var AllAPIResources = []string{
DiscoveryCloudwatchLoggroups,
DiscoveryLambdaFunctions,
DiscoveryDynamoDBTables,
DiscoveryDynamoDBGlobalTables,
DiscoveryRedshiftClusters,
DiscoveryVolumes,
DiscoverySnapshots,
Expand Down Expand Up @@ -709,7 +711,15 @@ func discover(runtime *plugin.Runtime, awsAccount *mqlAwsAccount, target string,
}
assetList = append(assetList, MqlObjectToAsset(accountId, m, conn))
}
ts = d.GetGlobalTables()
case DiscoveryDynamoDBGlobalTables:
res, err := NewResource(runtime, "aws.dynamodb", map[string]*llx.RawData{})
if err != nil {
return nil, err
}

d := res.(*mqlAwsDynamodb)

ts := d.GetGlobalTables()
if ts == nil {
return assetList, nil
}
Expand Down

0 comments on commit c4d1d8a

Please sign in to comment.