Skip to content

Commit

Permalink
INTMDB-137: Fix output of CloudProviderAccessService.GetRole (#500)
Browse files Browse the repository at this point in the history
  • Loading branch information
andreaangiolillo authored Jun 19, 2023
1 parent 33190b5 commit d69ad1a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
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

0 comments on commit d69ad1a

Please sign in to comment.