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

INTMDB-137: Fix output of CloudProviderAccessService.GetRole #500

Merged
merged 4 commits into from
Jun 19, 2023
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
6 changes: 3 additions & 3 deletions mongodbatlas/cloud_provider_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const cloudProviderAccessPath = "api/atlas/v1.0/groups/%s/cloudProviderAccess"
// See more: https://www.mongodb.com/docs/atlas/reference/api-resources-spec/v2/#tag/Cloud-Provider-Access
type CloudProviderAccessService interface {
ListRoles(context.Context, string) (*CloudProviderAccessRoles, *Response, error)
GetRole(context.Context, string, string) (*CloudProviderAccessRoles, *Response, error)
GetRole(context.Context, string, string) (*AWSIAMRole, *Response, error)
CreateRole(context.Context, string, *CloudProviderAccessRoleRequest) (*AWSIAMRole, *Response, error)
AuthorizeRole(context.Context, string, string, *CloudProviderAuthorizationRequest) (*AWSIAMRole, *Response, error)
DeauthorizeRole(context.Context, *CloudProviderDeauthorizationRequest) (*Response, error)
Expand Down Expand Up @@ -83,7 +83,7 @@ type CloudProviderDeauthorizationRequest struct {
// with the specified id and with access to the specified project.
//
// See more: https://www.mongodb.com/docs/atlas/reference/api-resources-spec/v2/#tag/Cloud-Provider-Access/operation/getCloudProviderAccessRole
func (s *CloudProviderAccessServiceOp) GetRole(ctx context.Context, groupID, roleID string) (*CloudProviderAccessRoles, *Response, error) {
func (s *CloudProviderAccessServiceOp) GetRole(ctx context.Context, groupID, roleID string) (*AWSIAMRole, *Response, error) {
if groupID == "" {
return nil, nil, NewArgError("groupId", "must be set")
}
Expand All @@ -98,7 +98,7 @@ func (s *CloudProviderAccessServiceOp) GetRole(ctx context.Context, groupID, rol
return nil, nil, err
}

root := new(CloudProviderAccessRoles)
root := new(AWSIAMRole)
resp, err := s.Client.Do(ctx, req, root)
if err != nil {
return nil, resp, err
Expand Down
24 changes: 9 additions & 15 deletions mongodbatlas/cloud_provider_access_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ func TestCloudProviderAccessServiceOp_GetRole(t *testing.T) {
mux.HandleFunc(fmt.Sprintf("/api/atlas/v1.0/groups/1/cloudProviderAccess/%s", roleID), func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{
"awsIamRoles": [{
"atlasAWSAccountArn": "arn:aws:iam::123456789012:root",
"atlasAssumedRoleExternalId": "3192be49-6e76-4b7d-a7b8-b486a8fc4483",
"authorizedDate": "2020-08-03T20:42:49Z",
Expand All @@ -83,7 +82,6 @@ func TestCloudProviderAccessServiceOp_GetRole(t *testing.T) {
"iamAssumedRoleArn": "arn:aws:iam::772401394250:role/my-test-aws-role",
"providerName": "AWS",
"roleId": "5f232b94af0a6b41747bcc2d"
}]
}`)
})

Expand All @@ -92,19 +90,15 @@ func TestCloudProviderAccessServiceOp_GetRole(t *testing.T) {
t.Fatalf("CloudProviderAccess.GetRole returned error: %v", err)
}

expected := &CloudProviderAccessRoles{
AWSIAMRoles: []AWSIAMRole{
{
AtlasAWSAccountARN: "arn:aws:iam::123456789012:root",
AtlasAssumedRoleExternalID: "3192be49-6e76-4b7d-a7b8-b486a8fc4483",
AuthorizedDate: "2020-08-03T20:42:49Z",
CreatedDate: "2020-07-30T20:20:36Z",
FeatureUsages: []*FeatureUsage{},
IAMAssumedRoleARN: "arn:aws:iam::772401394250:role/my-test-aws-role",
ProviderName: "AWS",
RoleID: "5f232b94af0a6b41747bcc2d",
},
},
expected := &AWSIAMRole{
AtlasAWSAccountARN: "arn:aws:iam::123456789012:root",
AtlasAssumedRoleExternalID: "3192be49-6e76-4b7d-a7b8-b486a8fc4483",
AuthorizedDate: "2020-08-03T20:42:49Z",
CreatedDate: "2020-07-30T20:20:36Z",
FeatureUsages: []*FeatureUsage{},
IAMAssumedRoleARN: "arn:aws:iam::772401394250:role/my-test-aws-role",
ProviderName: "AWS",
RoleID: "5f232b94af0a6b41747bcc2d",
}
if diff := deep.Equal(roles, expected); diff != nil {
t.Error(diff)
Expand Down