Skip to content

Commit

Permalink
Add AssignAPIKey struct to Assign request
Browse files Browse the repository at this point in the history
  • Loading branch information
thetonymaster committed Aug 14, 2019
1 parent 3fdb73c commit c4701ea
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions mongodbatlas/project_api_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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,omitempty"`
}

//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) {
Expand Down Expand Up @@ -80,7 +85,7 @@ 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")
}
Expand All @@ -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.MethodPost, path, assignAPIKeyRequest)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion mongodbatlas/project_api_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func TestProjectAPIKeys_Assign(t *testing.T) {
testMethod(t, r, http.MethodPost)
})

_, 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)
}
Expand Down

0 comments on commit c4701ea

Please sign in to comment.