Skip to content

Commit

Permalink
Fix bug for trusted advisor where metadata doesn't come in expected o…
Browse files Browse the repository at this point in the history
…rder (#11)
  • Loading branch information
bjfish25 authored Jul 14, 2021
1 parent 00287ab commit 65a0201
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v0.1.2

Fix bug for trusted advisor where metadata doesn't come in expected order

## v0.1.1

Fix bux for multi-role trusted advisor
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.1.1
v0.1.2
13 changes: 13 additions & 0 deletions pkg/aws/utils.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package aws

import (
"github.com/aws/aws-sdk-go/aws"
)

// Contains tells whether slice of strings 'ss' contains string 's'.
func Contains(ss []string, s string) bool {
for _, n := range ss {
Expand All @@ -10,3 +14,12 @@ func Contains(ss []string, s string) bool {
return false
}

// SdkStringContains tells whether slice of pointers of strings 'ss' contains pointer string 's'.
func SdkStringContains(ss []*string, s *string) bool {
for _, n := range ss {
if aws.StringValue(s) == aws.StringValue(n) {
return true
}
}
return false
}
37 changes: 37 additions & 0 deletions pkg/aws/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package aws

import (
"testing"

"github.com/aws/aws-sdk-go/aws"
)

func TestContains(t *testing.T) {
Expand Down Expand Up @@ -38,3 +40,38 @@ func TestContains(t *testing.T) {
})
}
}

func TestAwsStringContains(t *testing.T) {
type args struct {
a []*string
x *string
}
tests := []struct {
name string
args args
want bool
}{
{
name: "#1",
args: args{a: []*string{aws.String("a"), aws.String("b"), aws.String("c")}, x: aws.String("c")},
want: true,
},
{
name: "#2",
args: args{a: []*string{aws.String("a"), aws.String("b"), aws.String("c")}, x: aws.String("d")},
want: false,
},
{
name: "#3",
args: args{a: []*string{}, x: aws.String("d")},
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := SdkStringContains(tt.args.a, tt.args.x); got != tt.want {
t.Errorf("SdkStringContains() = %v, want %v", got, tt.want)
}
})
}
}
2 changes: 1 addition & 1 deletion pkg/cloudig/trustedadvisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func processTrustedAdvisorResults(results map[*support.TrustedAdvisorCheckDescri
finding.Comments = getComments(comments, finding.AccountID, findingTypeTrustedAdvisor, finding.Category+"-"+strings.Replace(finding.Name, " ", "_", -1))
for _, resource := range result.FlaggedResources {
if resource.Metadata != nil {
if aws.StringValue(resource.Metadata[0]) != "Green" {
if !awslocal.SdkStringContains(resource.Metadata, aws.String("Green")) && aws.BoolValue(resource.IsSuppressed) == false {
flaggedResource := aws.StringValue(resource.Metadata[1])
if aws.StringValue(resource.Metadata[2]) != "" && aws.StringValue(check.Metadata[1]) == "Region" {
flaggedResourceMeta := aws.StringValue(resource.Metadata[2])
Expand Down

0 comments on commit 65a0201

Please sign in to comment.