Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: disable aws task definition scraper by default #717

Merged
merged 1 commit into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
})
}
}
Loading