From 0dab40ba7a08dd78b465dcd22482bd2cec2ef3f0 Mon Sep 17 00:00:00 2001 From: Vasil Sirakov Date: Wed, 25 Sep 2024 15:11:36 +0300 Subject: [PATCH] Simplified function to determine applicable regions. Signed-off-by: Vasil Sirakov --- providers/aws/resources/aws_ec2.go | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/providers/aws/resources/aws_ec2.go b/providers/aws/resources/aws_ec2.go index 1f972c6a2..2ab4fda53 100644 --- a/providers/aws/resources/aws_ec2.go +++ b/providers/aws/resources/aws_ec2.go @@ -26,6 +26,7 @@ import ( "go.mondoo.com/cnquery/v11/providers-sdk/v1/util/jobpool" "go.mondoo.com/cnquery/v11/providers/aws/connection" "go.mondoo.com/cnquery/v11/types" + "go.mondoo.com/cnquery/v11/utils/stringx" ) func (e *mqlAwsEc2) id() (string, error) { @@ -1792,22 +1793,15 @@ func shouldExcludeInstance(instance ec2types.Instance, filters connection.Ec2Dis // given an initial set of regions, applies the allowed regions filter and the excluded regions filter on it // returning a resulting slice of only applicable region to which queries should be targeted func determineApplicableRegions(regions, regionsToInclude, regionsToExclude []string) []string { - res := regions if len(regionsToInclude) > 0 { - res = regionsToInclude + return regionsToInclude } - for _, regionToExclude := range regionsToExclude { - res = removeElement(res, regionToExclude) - } - return res -} - -func removeElement(slice []string, value string) []string { - result := []string{} - for _, v := range slice { - if v != value { - result = append(result, v) + res := []string{} + for _, r := range regions { + if !stringx.Contains(regionsToExclude, r) { + res = append(res, r) } } - return result + + return res }