-
Notifications
You must be signed in to change notification settings - Fork 87
Add a command to list processes #101
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2020 MongoDB Inc | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package cli | ||
|
||
import ( | ||
"github.com/mongodb/mongocli/internal/description" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func AtlasProcessesBuilder() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "processes", | ||
Aliases: []string{"process"}, | ||
Short: description.Clusters, | ||
Hidden: true, | ||
} | ||
cmd.AddCommand(AtlasProcessListBuilder()) | ||
|
||
return cmd | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Copyright 2020 MongoDB Inc | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package cli | ||
|
||
import ( | ||
"github.com/mongodb/mongocli/internal/description" | ||
"github.com/mongodb/mongocli/internal/flags" | ||
"github.com/mongodb/mongocli/internal/json" | ||
"github.com/mongodb/mongocli/internal/store" | ||
"github.com/mongodb/mongocli/internal/usage" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type atlasProcessesListOpts struct { | ||
globalOpts | ||
listOpts | ||
store store.ProcessLister | ||
} | ||
|
||
func (opts *atlasProcessesListOpts) init() error { | ||
if opts.ProjectID() == "" { | ||
return errMissingProjectID | ||
} | ||
|
||
var err error | ||
opts.store, err = store.New() | ||
return err | ||
} | ||
|
||
func (opts *atlasProcessesListOpts) Run() error { | ||
listOpts := opts.newListOptions() | ||
result, err := opts.store.Processes(opts.ProjectID(), listOpts) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
return json.PrettyPrint(result) | ||
} | ||
|
||
// mongocli atlas process(es) list --projectId projectId [--page N] [--limit N] | ||
func AtlasProcessListBuilder() *cobra.Command { | ||
opts := &atlasProcessesListOpts{} | ||
cmd := &cobra.Command{ | ||
Use: "list", | ||
Short: description.ListProcesses, | ||
Aliases: []string{"ls"}, | ||
Hidden: true, | ||
Args: cobra.NoArgs, | ||
PreRunE: func(cmd *cobra.Command, args []string) error { | ||
return opts.init() | ||
}, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return opts.Run() | ||
}, | ||
} | ||
|
||
cmd.Flags().IntVar(&opts.pageNum, flags.Page, 0, usage.Page) | ||
cmd.Flags().IntVar(&opts.itemsPerPage, flags.Limit, 0, usage.Limit) | ||
|
||
cmd.Flags().StringVar(&opts.projectID, flags.ProjectID, "", usage.ProjectID) | ||
|
||
return cmd | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright 2020 MongoDB Inc | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package cli | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/golang/mock/gomock" | ||
"github.com/mongodb/mongocli/internal/fixtures" | ||
"github.com/mongodb/mongocli/internal/mocks" | ||
) | ||
|
||
func TestAtlasProcessesList_Run(t *testing.T) { | ||
ctrl := gomock.NewController(t) | ||
mockStore := mocks.NewMockProcessLister(ctrl) | ||
|
||
defer ctrl.Finish() | ||
|
||
expected := fixtures.Processes() | ||
|
||
listOpts := &atlasProcessesListOpts{ | ||
store: mockStore, | ||
} | ||
|
||
mockStore. | ||
EXPECT(). | ||
Processes(listOpts.projectID, listOpts.newListOptions()). | ||
Return(expected, nil). | ||
Times(1) | ||
|
||
err := listOpts.Run() | ||
if err != nil { | ||
t.Fatalf("Run() unexpected error: %v", err) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ const ( | |
StartRestore = "Start a restore job." | ||
Snapshots = "Manage continuous snapshots for your project." | ||
ListSnapshots = "List continuous snapshots for a project." | ||
Logs = "Download host logs." | ||
Clusters = "Manage clusters for your project." | ||
ClustersLong = "The clusters command provides access to your cluster configurations. You can create, edit, and delete clusters." | ||
CreateCluster = "Create a MongoDB cluster." | ||
|
@@ -43,6 +44,8 @@ const ( | |
DescribeCluster = "Describe a cluster." | ||
ListClusters = "List clusters for a project." | ||
UpdateCluster = "Update a MongoDB cluster in Atlas." | ||
Processes = "Manage processes for your project." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should the language here always refer to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This format was done as a favour from the docs team, I'll ask them to give this list of descriptions another go |
||
ListProcesses = "List processes for a project." | ||
DBUsers = "Manage database users for your project." | ||
DBUsersLong = ` | ||
The dbusers command retrieves, creates and modifies the MongoDB database users in your cluster. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright 2020 MongoDB Inc | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package fixtures | ||
|
||
import ( | ||
atlas "github.com/mongodb/go-client-mongodb-atlas/mongodbatlas" | ||
) | ||
|
||
func Processes() []*atlas.Process { | ||
return []*atlas.Process{} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright 2020 MongoDB Inc | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package store | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
atlas "github.com/mongodb/go-client-mongodb-atlas/mongodbatlas" | ||
"github.com/mongodb/mongocli/internal/config" | ||
) | ||
|
||
type ProcessLister interface { | ||
Processes(string, *atlas.ListOptions) ([]*atlas.Process, error) | ||
} | ||
|
||
// Processes encapsulate the logic to manage different cloud providers | ||
func (s *Store) Processes(groupID string, opts *atlas.ListOptions) ([]*atlas.Process, error) { | ||
switch s.service { | ||
case config.CloudService: | ||
result, _, err := s.client.(*atlas.Client).Processes.List(context.Background(), groupID, opts) | ||
return result, err | ||
default: | ||
return nil, fmt.Errorf("unsupported service: %s", s.service) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[np] Can be removed now? Not blocking
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what I was working on and could not use as I needed the new format, I'll merge away as the next PR will remove the comments