Skip to content

Commit

Permalink
feat: disable aws task definition scraper by default
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Jul 9, 2024
1 parent e13b4a9 commit 0b8e857
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 2 deletions.
15 changes: 13 additions & 2 deletions api/v1/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"time"

"github.com/flanksource/commons/logger"
"github.com/samber/lo"
)

// AWS ...
Expand Down Expand Up @@ -75,26 +76,36 @@ const (
AWSEC2DHCPOptions = "AWS::EC2::DHCPOptions"
)

var defaultAWSExclusions = []string{"ECSTaskDefinition"}

func (aws AWS) Includes(resource string) bool {
if len(aws.Include) == 0 {
return true
return !lo.ContainsBy(defaultAWSExclusions, func(item string) bool {
return strings.EqualFold(item, resource)
})
}

for _, include := range aws.Include {
if strings.EqualFold(include, resource) {
return true
}
}

return false
}

func (aws AWS) Excludes(resource string) bool {
if len(aws.Exclude) == 0 {
return false
return !lo.ContainsBy(defaultAWSExclusions, func(item string) bool {
return strings.EqualFold(item, resource)
})
}

for _, exclude := range aws.Exclude {
if strings.EqualFold(exclude, resource) {
return true
}
}

return false
}
66 changes: 66 additions & 0 deletions api/v1/aws_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package v1

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestAWS_Includes(t *testing.T) {
tests := []struct {
name string
config AWS
resource string
want bool
}{
{
name: "empty include list, not in default exclusions",
config: AWS{},
resource: "ec2",
want: true,
},
{
name: "empty include list, in default exclusions",
config: AWS{},
resource: "ECSTASKDEFINITION",
want: false,
},
{
name: "explicit inclusion of default exclusion",
config: AWS{Include: []string{"EcsTaskDefinition"}},
resource: "ECSTASKDEFINITION",
want: true,
},
{
name: "non-empty include list, resource included",
config: AWS{
Include: []string{"s3", "ec2", "rds"},
},
resource: "ec2",
want: true,
},
{
name: "non-empty include list, resource not included",
config: AWS{
Include: []string{"s3", "ec2", "rds"},
},
resource: "lambda",
want: false,
},
{
name: "case-insensitive include",
config: AWS{
Include: []string{"S3", "EC2", "RDS"},
},
resource: "ec2",
want: true,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := tt.config.Includes(tt.resource)
assert.Equal(t, tt.want, got)
})
}
}

0 comments on commit 0b8e857

Please sign in to comment.