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^6W4`f*Nk% zg(7Z+hpTI_@9bj_@w)bmmLzPT7|;XwDHN4B^Nc2Ge)ltR=|2(C${xl#P^EeJ?G`C6 zo>WZcu#P=DLqGXjo`N6@Ri48~V`e$By(S>kSIzSi>wcv4l8eyrRvA)|K#wNk+h$KN zU8Z!Dtrmo>53x}wg6Er7N=iiw^+ezEpXc_xT^|<)VW&nHWp4fvvES+Mfy+N91m2M4 zJawS)n{Lt9pC==-=ePSDo4mFPh5S6tG6lXoy>;+^`0MjBKl^0MgULej?d8iWF _%02Y$bhij-3R54NBTTbl3|i;v+|?X)=-E9X zl`Lcm((rsjau4?dr_pTowj&lfmOuBf 9&Z?1E=Oh-Zqx$`vsAngG!y)9&cVi9 Zsd zvAO`M+LMe!Toe00%aMjfqQIfw#6|Sy%Ok|KAs)J%Jc>A4^t*kwJ_(DLcyTB=W{o=5 z*#EnNW_Ui8j2GA=Hv*9VO8PnhWc<`_KvLiZALC8lO3>rC)%F5$wa6fH;m6(mxU%)L zJ{|I_K$!D^jZx{(;4G}qoitdx*wgtln$$`x-z68!Q?mctnLe+hcNP%CoVKb9G_0PR zMWys^fg*}%4LC>Cu99u(#nMe rtf.Created.After.Unix() + if f.Created.After != nil { + createdAfter = creationTime.Unix() > f.Created.After.Unix() } createdBefore := true - if rtf.Created.Before != nil { - createdBefore = creationTime.Unix() < rtf.Created.Before.Unix() + if f.Created.Before != nil { + createdBefore = creationTime.Unix() < f.Created.Before.Unix() } return createdAfter && createdBefore } -// matches checks whether a resource matches the filter criteria. -func (f Filter) matches(r *Resource) bool { - resTypeFilters, found := f.Cfg[r.Type] +// Match checks whether a resource matches the filter criteria. +func (f Filter) Match(r *Resource) bool { + resTypeFilters, found := f[r.Type] if !found { return false } @@ -170,10 +242,14 @@ func (f Filter) matches(r *Resource) bool { } for _, rtf := range resTypeFilters { - if rtf.matchTags(r.Tags) && rtf.matchID(r.ID) && rtf.matchCreated(r.Created) { + if rtf.MatchTagged(r.Tags) && + rtf.MatchTags(r.Tags) && + rtf.matchID(r.ID) && + rtf.matchCreated(r.Created) { return true } } + return false } diff --git a/resource/filter_test.go b/resource/filter_test.go index 659895e41..ccac01415 100644 --- a/resource/filter_test.go +++ b/resource/filter_test.go @@ -4,6 +4,8 @@ import ( "testing" "time" + "github.com/aws/aws-sdk-go/aws" + "github.com/cloudetc/awsweeper/resource" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -14,12 +16,10 @@ import ( func TestYamlFilter_Validate(t *testing.T) { // given f := &resource.Filter{ - Cfg: resource.Config{ - resource.IamRole: {}, - resource.SecurityGroup: {}, - resource.Instance: {}, - resource.Vpc: {}, - }, + resource.IamRole: {}, + resource.SecurityGroup: {}, + resource.Instance: {}, + resource.Vpc: {}, } // when @@ -31,9 +31,7 @@ func TestYamlFilter_Validate(t *testing.T) { func TestYamlFilter_Validate_EmptyConfig(t *testing.T) { // given - f := &resource.Filter{ - Cfg: resource.Config{}, - } + f := &resource.Filter{} // when err := f.Validate() @@ -45,26 +43,22 @@ func TestYamlFilter_Validate_EmptyConfig(t *testing.T) { func TestYamlFilter_Validate_UnsupportedType(t *testing.T) { // given f := &resource.Filter{ - Cfg: resource.Config{ - resource.Instance: {}, - "not_supported_type": {}, - }, + resource.Instance: {}, + "not_supported_type": {}, } // when err := f.Validate() // then - assert.EqualError(t, err, "unsupported resource type found in yaml config: not_supported_type") + assert.EqualError(t, err, "unsupported resource type: not_supported_type") } func TestYamlFilter_Types(t *testing.T) { // given f := &resource.Filter{ - Cfg: resource.Config{ - resource.Instance: {}, - resource.Vpc: {}, - }, + resource.Instance: {}, + resource.Vpc: {}, } // when @@ -79,10 +73,8 @@ func TestYamlFilter_Types(t *testing.T) { func TestYamlFilter_Types_DependencyOrder(t *testing.T) { // given f := &resource.Filter{ - Cfg: resource.Config{ - resource.Subnet: {}, - resource.Vpc: {}, - }, + resource.Subnet: {}, + resource.Vpc: {}, } // when @@ -104,7 +96,7 @@ func Test_ParseFile(t *testing.T) { created: before: 23h`) - var cfg resource.Config + var cfg resource.Filter err := yaml.UnmarshalStrict(input, &cfg) require.NoError(t, err) require.NotNil(t, cfg[resource.Instance]) @@ -125,3 +117,281 @@ func Test_ParseFile(t *testing.T) { assert.True(t, cfg[resource.Instance][1].Created.Before.After(time.Now().UTC().Add(-24*time.Hour))) require.Nil(t, cfg[resource.Instance][1].Created.After) } + +func TestTypeFilter_MatchTagged(t *testing.T) { + tests := []struct { + name string + filter resource.TypeFilter + tags map[string]string + want bool + }{ + { + name: "no tagged filter, resource has tags", + filter: resource.TypeFilter{}, + tags: map[string]string{"foo": "bar"}, + want: true, + }, + { + name: "no tagged filter, resource has no tags", + filter: resource.TypeFilter{}, + want: true, + }, + { + name: "filter tagged resources, resource has tags", + filter: resource.TypeFilter{ + Tagged: aws.Bool(true), + }, + tags: map[string]string{"foo": "bar"}, + want: true, + }, + { + name: "filter tagged resources, resource has no tags", + filter: resource.TypeFilter{ + Tagged: aws.Bool(true), + }, + want: false, + }, + { + name: "filter untagged resources, resource has tags", + filter: resource.TypeFilter{ + Tagged: aws.Bool(false), + }, + tags: map[string]string{"foo": "bar"}, + want: false, + }, + { + name: "filter untagged resources, resource has no tags", + filter: resource.TypeFilter{ + Tagged: aws.Bool(false), + }, + want: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := tt.filter.MatchTagged(tt.tags); got != tt.want { + t.Errorf("MatchTagged() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestTypeFilter_MatchTags(t *testing.T) { + tests := []struct { + name string + filter resource.TypeFilter + tags map[string]string + want bool + }{ + { + name: "no tags filter, resources has no tags", + filter: resource.TypeFilter{}, + want: true, + }, + { + name: "no tags filter, resources has tags", + filter: resource.TypeFilter{}, + tags: map[string]string{"foo": "bar"}, + want: true, + }, + { + name: "filter one tag, resource has no tags", + filter: resource.TypeFilter{ + Tags: map[string]resource.StringFilter{ + "foo": {Pattern: "^ba"}, + }, + }, + want: false, + }, + { + name: "filter one tag, resource tags have no matching key", + filter: resource.TypeFilter{ + Tags: map[string]resource.StringFilter{ + "foo": {Pattern: "^ba"}, + }, + }, + tags: map[string]string{"foz": "bar"}, + want: false, + }, + { + name: "filter one tag, one resource tag's key matches, but not value", + filter: resource.TypeFilter{ + Tags: map[string]resource.StringFilter{ + "foo": {Pattern: "^bar"}, + }, + }, + tags: map[string]string{"foo": "baz"}, + want: false, + }, + { + name: "filter one tag, resource tag's key and value match", + filter: resource.TypeFilter{ + Tags: map[string]resource.StringFilter{ + "foo": {Pattern: "^ba"}, + }, + }, + tags: map[string]string{"foo": "bar"}, + want: true, + }, + { + name: "filter one tag, one out of multiple resource tag's key and value match", + filter: resource.TypeFilter{ + Tags: map[string]resource.StringFilter{ + "foo": {Pattern: "^ba"}, + }, + }, + tags: map[string]string{"foo": "bar", "boo": "baz"}, + want: true, + }, + { + name: "filter multiple tags, all match", + filter: resource.TypeFilter{ + Tags: map[string]resource.StringFilter{ + "foo": {Pattern: "^ba"}, + "boo": {Pattern: "^ba"}, + }, + }, + tags: map[string]string{"foo": "bar", "boo": "baz"}, + want: true, + }, + { + name: "filter multiple tags, one doesn't match (key)", + filter: resource.TypeFilter{ + Tags: map[string]resource.StringFilter{ + "foo": {Pattern: "^ba"}, + "boo": {Pattern: "^ba"}, + }, + }, + tags: map[string]string{"foo": "bar", "boz": "baz"}, + want: false, + }, + { + name: "filter multiple tags, one doesn't match (value)", + filter: resource.TypeFilter{ + Tags: map[string]resource.StringFilter{ + "foo": {Pattern: "^ba"}, + "boo": {Pattern: "^ba"}, + }, + }, + tags: map[string]string{"foo": "bar", "boo": "boz"}, + want: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := tt.filter.MatchTags(tt.tags); got != tt.want { + t.Errorf("MatchTags() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestTypeFilter_MatchNoTags(t *testing.T) { + tests := []struct { + name string + filter resource.TypeFilter + tags map[string]string + want bool + }{ + { + name: "no notags filter, resource has no tags", + filter: resource.TypeFilter{}, + want: true, + }, + { + name: "no notags filter, resource has tags", + filter: resource.TypeFilter{}, + tags: map[string]string{"foo": "bar"}, + want: true, + }, + { + name: "resource has no tags", + filter: resource.TypeFilter{ + Tags: map[string]resource.StringFilter{ + "NOT(foo)": {Pattern: "^ba"}, + }, + }, + want: true, + }, + { + name: "no matching key", + filter: resource.TypeFilter{ + Tags: map[string]resource.StringFilter{ + "NOT(foo)": {Pattern: "^ba"}, + }, + }, + tags: map[string]string{"foz": "bar"}, + want: true, + }, + { + name: "matching key, but not value", + filter: resource.TypeFilter{ + Tags: map[string]resource.StringFilter{ + "NOT(foo)": {Pattern: "^bar"}, + }, + }, + tags: map[string]string{"foo": "baz"}, + want: true, + }, + { + name: "matching key and value", + filter: resource.TypeFilter{ + Tags: map[string]resource.StringFilter{ + "NOT(foo)": {Pattern: "^ba"}, + }, + }, + tags: map[string]string{"foo": "bar", "boo": "baz"}, + want: false, + }, + { + name: "matching key and value, multiple tags", + filter: resource.TypeFilter{ + Tags: map[string]resource.StringFilter{ + "NOT(foo)": {Pattern: "^ba"}, + }, + }, + tags: map[string]string{"foo": "bar", "boo": "baz"}, + want: false, + }, + { + name: "multiple filter match", + filter: resource.TypeFilter{ + Tags: map[string]resource.StringFilter{ + "NOT(foo)": {Pattern: "^ba"}, + "NOT(boo)": {Pattern: "^ba"}, + }, + }, + tags: map[string]string{"foo": "bar", "boo": "baz"}, + want: false, + }, + { + name: "one of multiple filter rules doesn't match key", + filter: resource.TypeFilter{ + Tags: map[string]resource.StringFilter{ + "NOT(foo)": {Pattern: "^ba"}, + "NOT(boo)": {Pattern: "^ba"}, + }, + }, + tags: map[string]string{"foo": "bar", "boz": "baz"}, + want: true, + }, + { + name: "one of multiple filter rules doesn't match value", + filter: resource.TypeFilter{ + Tags: map[string]resource.StringFilter{ + "NOT(foo)": {Pattern: "^ba"}, + "NOT(boo)": {Pattern: "^ba"}, + }, + }, + tags: map[string]string{"foo": "bar", "boo": "boz"}, + want: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := tt.filter.MatchTags(tt.tags); got != tt.want { + t.Errorf("MatchTags() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/resource/select.go b/resource/select.go index d534ed422..c430eaf34 100644 --- a/resource/select.go +++ b/resource/select.go @@ -37,7 +37,7 @@ func (f Filter) defaultFilter(res Resources) []Resources { result := Resources{} for _, r := range res { - if f.matches(r) { + if f.Match(r) { result = append(result, r) } } @@ -49,7 +49,7 @@ func (f Filter) efsFileSystemFilter(res Resources, raw interface{}, c *AWS) []Re resultMt := Resources{} for _, r := range res { - if f.matches(&Resource{Type: r.Type, ID: *raw.([]*efs.FileSystemDescription)[0].Name}) { + if f.Match(&Resource{Type: r.Type, ID: *raw.([]*efs.FileSystemDescription)[0].Name}) { res, err := c.DescribeMountTargets(&efs.DescribeMountTargetsInput{ FileSystemId: &r.ID, }) @@ -74,7 +74,7 @@ func (f Filter) iamUserFilter(res Resources, c *AWS) []Resources { resultUserPol := Resources{} for _, r := range res { - if f.matches(r) { + if f.Match(r) { // list inline policies, delete with "aws_iam_user_policy" delete routine ups, err := c.ListUserPolicies(&iam.ListUserPoliciesInput{ UserName: &r.ID, @@ -116,7 +116,7 @@ func (f Filter) iamPolicyFilter(res Resources, raw interface{}, c *AWS) []Resour resultAtt := Resources{} for i, r := range res { - if f.matches(r) { + if f.Match(r) { es, err := c.ListEntitiesForPolicy(&iam.ListEntitiesForPolicyInput{ PolicyArn: &r.ID, }) @@ -161,7 +161,7 @@ func (f Filter) kmsKeysFilter(res Resources, c *AWS) []Resources { result := Resources{} for _, r := range res { - if f.matches(r) { + if f.Match(r) { req, res := c.DescribeKeyRequest(&kms.DescribeKeyInput{ KeyId: aws.String(r.ID), }) @@ -184,7 +184,7 @@ func (f Filter) kmsKeyAliasFilter(res Resources) []Resources { result := Resources{} for _, r := range res { - if f.matches(r) && !strings.HasPrefix(r.ID, "alias/aws/") { + if f.Match(r) && !strings.HasPrefix(r.ID, "alias/aws/") { result = append(result, r) } } diff --git a/resource/select_test.go b/resource/select_test.go index e4332c95e..0317e20d5 100644 --- a/resource/select_test.go +++ b/resource/select_test.go @@ -14,9 +14,8 @@ import ( func TestYamlFilter_Apply_EmptyConfig(t *testing.T) { //given - f := &resource.Filter{ - Cfg: resource.Config{}, - } + f := &resource.Filter{} + res := []*resource.Resource{ { Type: resource.Instance, @@ -34,9 +33,7 @@ func TestYamlFilter_Apply_EmptyConfig(t *testing.T) { func TestYamlFilter_Apply_FilterAll(t *testing.T) { //given f := &resource.Filter{ - Cfg: resource.Config{ - resource.Instance: {}, - }, + resource.Instance: {}, } res := []*resource.Resource{ { @@ -56,11 +53,9 @@ func TestYamlFilter_Apply_FilterAll(t *testing.T) { func TestYamlFilter_Apply_FilterByID(t *testing.T) { //given f := &resource.Filter{ - Cfg: resource.Config{ - resource.Instance: { - { - ID: &resource.StringFilter{Pattern: "^select"}, - }, + resource.Instance: { + { + ID: &resource.StringFilter{Pattern: "^select"}, }, }, } @@ -87,12 +82,10 @@ func TestYamlFilter_Apply_FilterByID(t *testing.T) { func TestYamlFilter_Apply_FilterByTag(t *testing.T) { //given f := &resource.Filter{ - Cfg: resource.Config{ - resource.Instance: { - { - Tags: map[string]*resource.StringFilter{ - "foo": {Pattern: "^bar"}, - }, + resource.Instance: { + { + Tags: map[string]resource.StringFilter{ + "foo": {Pattern: "^bar"}, }, }, }, @@ -130,13 +123,11 @@ func TestYamlFilter_Apply_FilterByTag(t *testing.T) { func TestYamlFilter_Apply_FilterByMultipleTags(t *testing.T) { //given f := &resource.Filter{ - Cfg: resource.Config{ - resource.Instance: { - { - Tags: map[string]*resource.StringFilter{ - "foo": {Pattern: "^bar"}, - "bla": {Pattern: "^blub"}, - }, + resource.Instance: { + { + Tags: map[string]resource.StringFilter{ + "foo": {Pattern: "^bar"}, + "bla": {Pattern: "^blub"}, }, }, }, @@ -171,13 +162,11 @@ func TestYamlFilter_Apply_FilterByMultipleTags(t *testing.T) { func TestYamlFilter_Apply_FilterByIDandTag(t *testing.T) { //given f := &resource.Filter{ - Cfg: resource.Config{ - resource.Instance: { - { - ID: &resource.StringFilter{Pattern: "^foo"}, - Tags: map[string]*resource.StringFilter{ - "foo": {Pattern: "^bar"}, - }, + resource.Instance: { + { + ID: &resource.StringFilter{Pattern: "^foo"}, + Tags: map[string]resource.StringFilter{ + "foo": {Pattern: "^bar"}, }, }, }, @@ -215,13 +204,11 @@ func TestYamlFilter_Apply_FilterByIDandTag(t *testing.T) { func TestYamlFilter_Apply_Created(t *testing.T) { //given f := &resource.Filter{ - Cfg: resource.Config{ - resource.Instance: { - { - Created: &resource.Created{ - After: &resource.CreatedTime{Time: time.Date(2018, 11, 17, 0, 0, 0, 0, time.UTC)}, - Before: &resource.CreatedTime{Time: time.Date(2018, 11, 20, 0, 0, 0, 0, time.UTC)}, - }, + resource.Instance: { + { + Created: &resource.Created{ + After: &resource.CreatedTime{Time: time.Date(2018, 11, 17, 0, 0, 0, 0, time.UTC)}, + Before: &resource.CreatedTime{Time: time.Date(2018, 11, 20, 0, 0, 0, 0, time.UTC)}, }, }, }, @@ -265,12 +252,10 @@ func TestYamlFilter_Apply_Created(t *testing.T) { func TestYamlFilter_Apply_CreatedBefore(t *testing.T) { //given f := &resource.Filter{ - Cfg: resource.Config{ - resource.Instance: { - { - Created: &resource.Created{ - Before: &resource.CreatedTime{Time: time.Date(2018, 11, 20, 0, 0, 0, 0, time.UTC)}, - }, + resource.Instance: { + { + Created: &resource.Created{ + Before: &resource.CreatedTime{Time: time.Date(2018, 11, 20, 0, 0, 0, 0, time.UTC)}, }, }, }, @@ -304,12 +289,10 @@ func TestYamlFilter_Apply_CreatedBefore(t *testing.T) { func TestYamlFilter_Apply_CreatedAfter(t *testing.T) { //given f := &resource.Filter{ - Cfg: resource.Config{ - resource.Instance: { - { - Created: &resource.Created{ - After: &resource.CreatedTime{Time: time.Date(2018, 11, 20, 0, 0, 0, 0, time.UTC)}, - }, + resource.Instance: { + { + Created: &resource.Created{ + After: &resource.CreatedTime{Time: time.Date(2018, 11, 20, 0, 0, 0, 0, time.UTC)}, }, }, }, @@ -343,15 +326,13 @@ func TestYamlFilter_Apply_CreatedAfter(t *testing.T) { func TestYamlFilter_Apply_MultipleFiltersPerResourceType(t *testing.T) { //given f := &resource.Filter{ - Cfg: resource.Config{ - resource.Instance: { - { - ID: &resource.StringFilter{Pattern: "^select"}, - }, - { - Tags: map[string]*resource.StringFilter{ - "foo": {Pattern: "^bar"}, - }, + resource.Instance: { + { + ID: &resource.StringFilter{Pattern: "^select"}, + }, + { + Tags: map[string]resource.StringFilter{ + "foo": {Pattern: "^bar"}, }, }, }, @@ -393,15 +374,13 @@ func TestYamlFilter_Apply_MultipleFiltersPerResourceType(t *testing.T) { func TestYamlFilter_Apply_NegatedStringFilter(t *testing.T) { //given f := &resource.Filter{ - Cfg: resource.Config{ - resource.Instance: { - { - ID: &resource.StringFilter{Pattern: "^select", Negate: true}, - }, - { - Tags: map[string]*resource.StringFilter{ - "foo": {Pattern: "^bar", Negate: true}, - }, + resource.Instance: { + { + ID: &resource.StringFilter{Pattern: "^select", Negate: true}, + }, + { + Tags: map[string]resource.StringFilter{ + "foo": {Pattern: "^bar", Negate: true}, }, }, },