Skip to content

Commit 333be58

Browse files
CLOUDP-60957: mongocli om logs delete (#131)
1 parent c582e1b commit 333be58

File tree

8 files changed

+176
-2
lines changed

8 files changed

+176
-2
lines changed

internal/cli/atlas_measurements_processes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func (opts *atlasMeasurementsProcessOpts) Run() error {
5252
func AtlasMeasurementsProcessBuilder() *cobra.Command {
5353
opts := &atlasMeasurementsProcessOpts{}
5454
cmd := &cobra.Command{
55-
Use: "processes",
55+
Use: "processes [host:port]",
5656
Short: description.ProcessMeasurements,
5757
Aliases: []string{"process"},
5858
Args: cobra.ExactArgs(1),

internal/cli/ops_manager_logs.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ func OpsManagerLogsBuilder() *cobra.Command {
2929
cmd.AddCommand(OpsManagerLogsCollectOptsBuilder())
3030
cmd.AddCommand(OpsManagerLogsListOptsBuilder())
3131
cmd.AddCommand(OpsManagerLogsDownloadOptsBuilder())
32+
cmd.AddCommand(OpsManagerLogsDeleteOptsBuilder())
3233

3334
return cmd
3435
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Copyright 2020 MongoDB Inc
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package cli
16+
17+
import (
18+
"github.com/mongodb/mongocli/internal/description"
19+
"github.com/mongodb/mongocli/internal/flags"
20+
"github.com/mongodb/mongocli/internal/store"
21+
"github.com/mongodb/mongocli/internal/usage"
22+
"github.com/spf13/cobra"
23+
)
24+
25+
type opsManagerLogsDeleteOpts struct {
26+
globalOpts
27+
deleteOpts
28+
store store.LogJobDeleter
29+
}
30+
31+
func (opts *opsManagerLogsDeleteOpts) initStore() error {
32+
var err error
33+
opts.store, err = store.New()
34+
return err
35+
}
36+
37+
func (opts *opsManagerLogsDeleteOpts) Run() error {
38+
return opts.store.DeleteCollectionJob(opts.ProjectID(), opts.entry)
39+
}
40+
41+
// mongocli om logs delete id [--projectId projectId] [--force]
42+
func OpsManagerLogsDeleteOptsBuilder() *cobra.Command {
43+
opts := &opsManagerLogsDeleteOpts{
44+
deleteOpts: deleteOpts{
45+
successMessage: "Log collection entry '%s' deleted\n",
46+
failMessage: "Log collection entry not deleted",
47+
},
48+
}
49+
cmd := &cobra.Command{
50+
Use: "delete [id]",
51+
Aliases: []string{"rm"},
52+
Args: cobra.ExactArgs(1),
53+
Short: description.DeleteLogCollectionJob,
54+
PreRunE: func(cmd *cobra.Command, args []string) error {
55+
if err := opts.PreRunE(opts.initStore); err != nil {
56+
return err
57+
}
58+
opts.entry = args[0]
59+
return opts.Confirm()
60+
},
61+
RunE: func(cmd *cobra.Command, args []string) error {
62+
return opts.Run()
63+
},
64+
}
65+
66+
cmd.Flags().BoolVar(&opts.confirm, flags.Force, false, usage.Force)
67+
68+
cmd.Flags().StringVar(&opts.projectID, flags.ProjectID, "", usage.ProjectID)
69+
70+
return cmd
71+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright 2020 MongoDB Inc
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package cli
16+
17+
import (
18+
"testing"
19+
20+
"github.com/golang/mock/gomock"
21+
"github.com/mongodb/mongocli/internal/mocks"
22+
)
23+
24+
func TestOpsManagerWhitelistDelete_Run(t *testing.T) {
25+
ctrl := gomock.NewController(t)
26+
mockStore := mocks.NewMockLogJobDeleter(ctrl)
27+
28+
defer ctrl.Finish()
29+
30+
deleteOpts := &opsManagerLogsDeleteOpts{
31+
deleteOpts: deleteOpts{
32+
confirm: true,
33+
entry: "test",
34+
successMessage: "Project whitelist entry '%s' deleted\n",
35+
},
36+
store: mockStore,
37+
}
38+
39+
mockStore.
40+
EXPECT().
41+
DeleteCollectionJob(deleteOpts.projectID, deleteOpts.entry).
42+
Return(nil).
43+
Times(1)
44+
45+
err := deleteOpts.Run()
46+
if err != nil {
47+
t.Fatalf("Run() unexpected error: %v", err)
48+
}
49+
}

internal/cli/ops_manager_measurements_process.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (opts *opsManagerMeasurementsProcessOpts) Run() error {
5151
func OpsManagerMeasurementsProcessBuilder() *cobra.Command {
5252
opts := &opsManagerMeasurementsProcessOpts{}
5353
cmd := &cobra.Command{
54-
Use: "process",
54+
Use: "process [hostId]",
5555
Short: description.ProcessMeasurements,
5656
Aliases: []string{"processes"},
5757
Args: cobra.ExactArgs(1),

internal/description/description.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ const (
101101
LogCollection = "Manage log collection jobs."
102102
StartLogCollectionJob = "Start a job to collect logs."
103103
ListLogCollectionJobs = "List log collection jobs."
104+
DeleteLogCollectionJob = "Delete a log collection job."
104105
DBUsersLong = `The dbusers command retrieves, creates and modifies the MongoDB database users in your cluster.
105106
Each user has a set of roles that provide access to the project’s databases.
106107
A user’s roles apply to all the clusters in the project.`

internal/mocks/mock_logs.go

Lines changed: 37 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/store/logs.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ type LogJobLister interface {
4040
LogCollectionJobs(string, *om.LogListOptions) (*om.LogCollectionJobs, error)
4141
}
4242

43+
type LogJobDeleter interface {
44+
DeleteCollectionJob(string, string) error
45+
}
46+
4347
// LogCollectionJobs encapsulate the logic to manage different cloud providers
4448
func (s *Store) LogCollectionJobs(groupID string, opts *om.LogListOptions) (*om.LogCollectionJobs, error) {
4549
switch s.service {
@@ -51,6 +55,17 @@ func (s *Store) LogCollectionJobs(groupID string, opts *om.LogListOptions) (*om.
5155
}
5256
}
5357

58+
// DeleteCollectionJob encapsulate the logic to manage different cloud providers
59+
func (s *Store) DeleteCollectionJob(groupID, logID string) error {
60+
switch s.service {
61+
case config.OpsManagerService, config.CloudManagerService:
62+
_, err := s.client.(*om.Client).LogCollections.Delete(context.Background(), groupID, logID)
63+
return err
64+
default:
65+
return fmt.Errorf("unsupported service: %s", s.service)
66+
}
67+
}
68+
5469
// Collect encapsulate the logic to manage different cloud providers
5570
func (s *Store) Collect(groupID string, newLog *om.LogCollectionJob) (*om.LogCollectionJob, error) {
5671
switch s.service {

0 commit comments

Comments
 (0)