Skip to content

Commit

Permalink
OCM-8276 | fix: don't show empty lines when filtering version on acc …
Browse files Browse the repository at this point in the history
…roles
  • Loading branch information
gdbranco committed May 23, 2024
1 parent 4f218b4 commit f146ea8
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/aws/policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ func (c *awsClient) mapToAccountRole(version string, role iamtypes.Role) (Role,
}

func (c *awsClient) mapToAccountRoles(version string, roles []iamtypes.Role) ([]Role, error) {

emptyRole := Role{}
var accountRoles []Role
for _, role := range roles {
if !checkIfAccountRole(role.RoleName) {
Expand All @@ -849,6 +849,9 @@ func (c *awsClient) mapToAccountRoles(version string, roles []iamtypes.Role) ([]
if err != nil {
return accountRoles, err
}
if accountRole == emptyRole {
continue
}
accountRoles = append(accountRoles, accountRole)
}

Expand Down
76 changes: 76 additions & 0 deletions pkg/aws/policies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,88 @@ import (
iamtypes "github.com/aws/aws-sdk-go-v2/service/iam/types"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
common "github.com/openshift-online/ocm-common/pkg/aws/validations"
"github.com/sirupsen/logrus"

"github.com/openshift/rosa/pkg/aws/mocks"
"github.com/openshift/rosa/pkg/aws/tags"
)

var _ = Describe("mapToAccountRoles", func() {
var (
client awsClient
mockIamAPI *mocks.MockIamApiClient
mockCtrl *gomock.Controller
)

BeforeEach(func() {
mockCtrl = gomock.NewController(GinkgoT())
mockIamAPI = mocks.NewMockIamApiClient(mockCtrl)
client = awsClient{
iamClient: mockIamAPI,
}
})

It("Skips roles that don't match version", func() {
mockIamAPI.EXPECT().ListRoleTags(gomock.Any(), gomock.Any()).Return(&iam.ListRoleTagsOutput{
Tags: []iamtypes.Tag{
{
Key: aws.String(common.OpenShiftVersion),
Value: aws.String("4.13"),
},
},
}, nil)
mockIamAPI.EXPECT().ListRoleTags(gomock.Any(), gomock.Any()).Return(&iam.ListRoleTagsOutput{
Tags: []iamtypes.Tag{
{
Key: aws.String(common.OpenShiftVersion),
Value: aws.String("4.15"),
},
},
}, nil)
roles, err := client.mapToAccountRoles("4.13", []iamtypes.Role{
{
RoleName: aws.String("prefix-Installer-Role"),
},
{
RoleName: aws.String("prefix2-Installer-Role"),
},
})
Expect(err).ToNot(HaveOccurred())
Expect(roles).To(HaveLen(1))
})

It("Retrieves all roles", func() {
mockIamAPI.EXPECT().ListRoleTags(gomock.Any(), gomock.Any()).Return(&iam.ListRoleTagsOutput{
Tags: []iamtypes.Tag{
{
Key: aws.String(common.OpenShiftVersion),
Value: aws.String("4.13"),
},
},
}, nil)
mockIamAPI.EXPECT().ListRoleTags(gomock.Any(), gomock.Any()).Return(&iam.ListRoleTagsOutput{
Tags: []iamtypes.Tag{
{
Key: aws.String(common.OpenShiftVersion),
Value: aws.String("4.15"),
},
},
}, nil)
roles, err := client.mapToAccountRoles("", []iamtypes.Role{
{
RoleName: aws.String("prefix-Installer-Role"),
},
{
RoleName: aws.String("prefix2-Installer-Role"),
},
})
Expect(err).ToNot(HaveOccurred())
Expect(roles).To(HaveLen(2))
})

})

var _ = Describe("Is Policy Compatible", func() {
var (
client Client
Expand Down

0 comments on commit f146ea8

Please sign in to comment.