From 73311742640e8e9e6a7d25a1dd8a5e35ec5d424c Mon Sep 17 00:00:00 2001 From: Dominik Richter Date: Mon, 18 Sep 2023 22:25:22 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20networkAcl=20portRange=20a?= =?UTF-8?q?nd=20egress?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ported https://github.com/mondoohq/cnquery/pull/1508 Fixes https://github.com/mondoohq/cnquery/issues/1510 Signed-off-by: Dominik Richter --- providers/aws/resources/aws_ec2.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/providers/aws/resources/aws_ec2.go b/providers/aws/resources/aws_ec2.go index 0cfee10585..dc3cfa21d4 100644 --- a/providers/aws/resources/aws_ec2.go +++ b/providers/aws/resources/aws_ec2.go @@ -11,9 +11,8 @@ import ( "github.com/aws/aws-sdk-go-v2/service/ec2" ec2types "github.com/aws/aws-sdk-go-v2/service/ec2/types" - ssmtypes "github.com/aws/aws-sdk-go-v2/service/ssm/types" - "github.com/aws/aws-sdk-go-v2/service/ssm" + ssmtypes "github.com/aws/aws-sdk-go-v2/service/ssm/types" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/arn" "github.com/aws/smithy-go" @@ -24,7 +23,6 @@ import ( "go.mondoo.com/cnquery/providers-sdk/v1/util/convert" "go.mondoo.com/cnquery/providers-sdk/v1/util/jobpool" "go.mondoo.com/cnquery/providers/aws/connection" - "go.mondoo.com/cnquery/types" ) @@ -146,22 +144,29 @@ func (a *mqlAwsEc2Networkacl) entries() ([]interface{}, error) { res := []interface{}{} for _, entry := range networkacls.NetworkAcls[0].Entries { + egress := convert.ToBool(entry.Egress) + entryId := id + "-" + strconv.Itoa(convert.ToIntFrom32(entry.RuleNumber)) + if egress { + entryId += "-egress" + } else { + entryId += "-ingress" + } args := map[string]*llx.RawData{ - "egress": llx.BoolData(convert.ToBool(entry.Egress)), + "egress": llx.BoolData(egress), "ruleAction": llx.StringData(string(entry.RuleAction)), - "id": llx.StringData(id + "-" + strconv.Itoa(convert.ToIntFrom32(entry.RuleNumber))), + "id": llx.StringData(entryId), } if entry.PortRange != nil { - mqlPortEntry, err := CreateResource(a.MqlRuntime, "aws.ec2.networkacl.entry.portrange", + mqlPortRange, err := CreateResource(a.MqlRuntime, "aws.ec2.networkacl.entry.portrange", map[string]*llx.RawData{ "from": llx.IntData(convert.ToInt64From32(entry.PortRange.From)), "to": llx.IntData(convert.ToInt64From32(entry.PortRange.To)), - "id": llx.StringData(id + "-" + strconv.Itoa(convert.ToIntFrom32(entry.RuleNumber)) + "-" + strconv.Itoa(convert.ToIntFrom32(entry.PortRange.From))), + "id": llx.StringData(entryId + "-" + strconv.Itoa(convert.ToIntFrom32(entry.PortRange.From))), }) if err != nil { return nil, err } - args["mqlPortEntry"] = llx.ResourceData(mqlPortEntry, mqlPortEntry.MqlName()) + args["portRange"] = llx.ResourceData(mqlPortRange, mqlPortRange.MqlName()) } mqlAclEntry, err := CreateResource(a.MqlRuntime, "aws.ec2.networkacl.entry", args)