diff --git a/mongodbatlas/project_api_key.go b/mongodbatlas/project_api_key.go index a3840a942..f3322bae3 100644 --- a/mongodbatlas/project_api_key.go +++ b/mongodbatlas/project_api_key.go @@ -14,7 +14,7 @@ const projectAPIKeysPath = "groups/%s/apiKeys" type ProjectAPIKeysService interface { List(context.Context, string, *ListOptions) ([]APIKey, *Response, error) Create(context.Context, string, *APIKeyInput) (*APIKey, *Response, error) - Assign(context.Context, string, string) (*Response, error) + Assign(context.Context, string, string, *AssignAPIKey) (*Response, error) Unassign(context.Context, string, string) (*Response, error) } @@ -26,6 +26,11 @@ type ProjectAPIKeysOp struct { var _ ProjectAPIKeysService = &ProjectAPIKeysOp{} +// AssignAPIKey contains the roles to be assigned to an Organization API key into a Project +type AssignAPIKey struct { + Roles []string `json:"roles"` +} + //List all API-KEY in the organization associated to {GROUP-ID}. //See more: https://docs.atlas.mongodb.com/reference/api/projectApiKeys/get-all-apiKeys-in-one-project/ func (s *ProjectAPIKeysOp) List(ctx context.Context, groupID string, listOptions *ListOptions) ([]APIKey, *Response, error) { @@ -80,9 +85,9 @@ func (s *ProjectAPIKeysOp) Create(ctx context.Context, groupID string, createReq //Assign an API-KEY related to {GROUP-ID} to a the project with {API-KEY-ID}. //See more: https://docs.atlas.mongodb.com/reference/api/projectApiKeys/assign-one-org-apiKey-to-one-project/ -func (s *ProjectAPIKeysOp) Assign(ctx context.Context, groupID string, keyID string) (*Response, error) { +func (s *ProjectAPIKeysOp) Assign(ctx context.Context, groupID string, keyID string, assignAPIKeyRequest *AssignAPIKey) (*Response, error) { if groupID == "" { - return nil, NewArgError("apiKeyID", "must be set") + return nil, NewArgError("groupID", "must be set") } if keyID == "" { @@ -93,7 +98,7 @@ func (s *ProjectAPIKeysOp) Assign(ctx context.Context, groupID string, keyID str path := fmt.Sprintf("%s/%s", basePath, keyID) - req, err := s.client.NewRequest(ctx, http.MethodPost, path, nil) + req, err := s.client.NewRequest(ctx, http.MethodPatch, path, assignAPIKeyRequest) if err != nil { return nil, err } diff --git a/mongodbatlas/project_api_key_test.go b/mongodbatlas/project_api_key_test.go index d57e35c60..e091a1e94 100644 --- a/mongodbatlas/project_api_key_test.go +++ b/mongodbatlas/project_api_key_test.go @@ -108,10 +108,10 @@ func TestProjectAPIKeys_Assign(t *testing.T) { keyID := "5d1d12c087d9d63e6d682438" mux.HandleFunc(fmt.Sprintf("/groups/%s/apiKeys/%s", groupID, keyID), func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r, http.MethodPost) + testMethod(t, r, http.MethodPatch) }) - _, err := client.ProjectAPIKeys.Assign(ctx, groupID, keyID) + _, err := client.ProjectAPIKeys.Assign(ctx, groupID, keyID, &AssignAPIKey{}) if err != nil { t.Errorf("ProjectAPIKeys.Assign returned error: %v", err) }