Skip to content

Commit d4a5157

Browse files
Bug: The atlas user create was calling the wrong endpoint (#234)
1 parent 7103b52 commit d4a5157

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

mongodbatlas/atlas_users.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import (
2121
)
2222

2323
const (
24-
usersBasePath = "api/atlas/v1.0/groups/%s/users"
24+
usersGroupBasePath = "api/atlas/v1.0/groups/%s/users"
25+
usersBasePath = "api/atlas/v1.0/users"
2526
)
2627

2728
// AtlasUsersService is an interface for interfacing with the AtlasUsers
@@ -66,7 +67,7 @@ type AtlasUser struct {
6667
//
6768
// See more: https://docs.atlas.mongodb.com/reference/api/user-get-all/
6869
func (s *AtlasUsersServiceOp) List(ctx context.Context, orgID string, listOptions *ListOptions) ([]AtlasUser, *Response, error) {
69-
path := fmt.Sprintf(usersBasePath, orgID)
70+
path := fmt.Sprintf(usersGroupBasePath, orgID)
7071

7172
// Add query params from listOptions
7273
path, err := setListOptions(path, listOptions)
@@ -100,7 +101,7 @@ func (s *AtlasUsersServiceOp) Get(ctx context.Context, userID string) (*AtlasUse
100101
return nil, nil, NewArgError("userID", "must be set")
101102
}
102103

103-
path := fmt.Sprintf("api/atlas/v1.0/users/%s", userID)
104+
path := fmt.Sprintf("%s/%s", usersBasePath, userID)
104105

105106
req, err := s.Client.NewRequest(ctx, http.MethodGet, path, nil)
106107
if err != nil {
@@ -124,7 +125,7 @@ func (s *AtlasUsersServiceOp) GetByName(ctx context.Context, username string) (*
124125
return nil, nil, NewArgError("username", "must be set")
125126
}
126127

127-
path := fmt.Sprintf("api/atlas/v1.0/users/byName/%s", username)
128+
path := fmt.Sprintf("%s/byName/%s", usersBasePath, username)
128129

129130
req, err := s.Client.NewRequest(ctx, http.MethodGet, path, nil)
130131
if err != nil {
@@ -148,7 +149,7 @@ func (s *AtlasUsersServiceOp) Create(ctx context.Context, createRequest *AtlasUs
148149
return nil, nil, NewArgError("createRequest", "cannot be nil")
149150
}
150151

151-
req, err := s.Client.NewRequest(ctx, http.MethodPost, "users", createRequest)
152+
req, err := s.Client.NewRequest(ctx, http.MethodPost, usersBasePath, createRequest)
152153
if err != nil {
153154
return nil, nil, err
154155
}

mongodbatlas/atlas_users_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ func TestAtlasUsers_Create(t *testing.T) {
312312
Country: "US",
313313
}
314314

315-
mux.HandleFunc("/users", func(w http.ResponseWriter, r *http.Request) {
315+
mux.HandleFunc("/api/atlas/v1.0/users", func(w http.ResponseWriter, r *http.Request) {
316316
expected := map[string]interface{}{
317317
"username": "john.doe@example.com",
318318
"password": "myPassword1@",

0 commit comments

Comments
 (0)