Skip to content

Commit ab86577

Browse files
committed
task: Deprecate continous backup for atlas
1 parent 14ea7ea commit ab86577

File tree

6 files changed

+134
-14
lines changed

6 files changed

+134
-14
lines changed

internal/cli/atlas/atlas.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,15 @@ func Builder() *cobra.Command {
3131
return validate.Credentials()
3232
},
3333
}
34+
// hide old backup until we have a better name for it
35+
b := backup.Builder()
36+
b.Hidden = true
37+
3438
cmd.AddCommand(ClustersBuilder())
3539
cmd.AddCommand(DBUsersBuilder())
3640
cmd.AddCommand(WhitelistBuilder())
3741
cmd.AddCommand(alerts.Builder())
38-
cmd.AddCommand(backup.Builder())
42+
cmd.AddCommand(b)
3943
cmd.AddCommand(events.Builder())
4044
cmd.AddCommand(MetricsBuilder())
4145
cmd.AddCommand(LogsBuilder())

internal/cli/backup/checkpoints_list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (opts *CheckpointsListOpts) initStore() error {
4141
func (opts *CheckpointsListOpts) Run() error {
4242
listOpts := opts.NewListOptions()
4343

44-
result, err := opts.store.List(opts.ConfigProjectID(), opts.clusterName, listOpts)
44+
result, err := opts.store.Checkpoints(opts.ConfigProjectID(), opts.clusterName, listOpts)
4545

4646
if err != nil {
4747
return err

internal/cli/backup/checkpoints_list_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func TestCheckpointsList_Run(t *testing.T) {
3737

3838
mockStore.
3939
EXPECT().
40-
List(listOpts.ProjectID, "Cluster0", listOpts.NewListOptions()).
40+
Checkpoints(listOpts.ProjectID, "Cluster0", listOpts.NewListOptions()).
4141
Return(expected, nil).
4242
Times(1)
4343

internal/mocks/mock_continuous_backup.go

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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 store
16+
17+
import (
18+
"context"
19+
"fmt"
20+
21+
atlas "github.com/mongodb/go-client-mongodb-atlas/mongodbatlas"
22+
"github.com/mongodb/mongocli/internal/config"
23+
)
24+
25+
// SnapshotRestoreJobs encapsulate the logic to manage different cloud providers
26+
func (s *Store) SnapshotRestoreJobs(projectID, clusterName string, opts *atlas.ListOptions) (*atlas.CloudProviderSnapshotRestoreJobs, error) {
27+
o := &atlas.SnapshotReqPathParameters{
28+
GroupID: projectID,
29+
ClusterName: clusterName,
30+
}
31+
switch s.service {
32+
case config.CloudService:
33+
result, _, err := s.client.(*atlas.Client).CloudProviderSnapshotRestoreJobs.List(context.Background(), o, opts)
34+
return result, err
35+
default:
36+
return nil, fmt.Errorf("unsupported service: %s", s.service)
37+
}
38+
}
39+
40+
// CreateSnapshotRestoreJobs encapsulate the logic to manage different cloud providers
41+
func (s *Store) CreateSnapshotRestoreJobs(projectID, clusterName string, request *atlas.CloudProviderSnapshotRestoreJob) (*atlas.CloudProviderSnapshotRestoreJob, error) {
42+
o := &atlas.SnapshotReqPathParameters{
43+
GroupID: projectID,
44+
ClusterName: clusterName,
45+
}
46+
switch s.service {
47+
case config.CloudService:
48+
result, _, err := s.client.(*atlas.Client).CloudProviderSnapshotRestoreJobs.Create(context.Background(), o, request)
49+
return result, err
50+
default:
51+
return nil, fmt.Errorf("unsupported service: %s", s.service)
52+
}
53+
}
54+
55+
// ContinuousSnapshots encapsulate the logic to manage different cloud providers
56+
func (s *Store) CloudProviderSnapshots(projectID, clusterName string, opts *atlas.ListOptions) (*atlas.CloudProviderSnapshots, error) {
57+
o := &atlas.SnapshotReqPathParameters{
58+
GroupID: projectID,
59+
ClusterName: clusterName,
60+
}
61+
switch s.service {
62+
case config.CloudService:
63+
result, _, err := s.client.(*atlas.Client).CloudProviderSnapshots.GetAllCloudProviderSnapshots(context.Background(), o, opts)
64+
return result, err
65+
default:
66+
return nil, fmt.Errorf("unsupported service: %s", s.service)
67+
}
68+
}
69+
70+
// CloudProviderSnapshot encapsulate the logic to manage different cloud providers
71+
func (s *Store) CloudProviderSnapshot(projectID, clusterName, snapshotID string) (*atlas.CloudProviderSnapshot, error) {
72+
o := &atlas.SnapshotReqPathParameters{
73+
GroupID: projectID,
74+
ClusterName: clusterName,
75+
SnapshotID: snapshotID,
76+
}
77+
switch s.service {
78+
case config.CloudService:
79+
result, _, err := s.client.(*atlas.Client).CloudProviderSnapshots.GetOneCloudProviderSnapshot(context.Background(), o)
80+
return result, err
81+
default:
82+
return nil, fmt.Errorf("unsupported service: %s", s.service)
83+
}
84+
}
85+
86+
// CreateCloudProviderSnapshot encapsulate the logic to manage different cloud providers
87+
func (s *Store) CreateCloudProviderSnapshot(projectID, clusterName string, req *atlas.CloudProviderSnapshot) (*atlas.CloudProviderSnapshot, error) {
88+
o := &atlas.SnapshotReqPathParameters{
89+
GroupID: projectID,
90+
ClusterName: clusterName,
91+
}
92+
switch s.service {
93+
case config.CloudService:
94+
result, _, err := s.client.(*atlas.Client).CloudProviderSnapshots.Create(context.Background(), o, req)
95+
return result, err
96+
default:
97+
return nil, fmt.Errorf("unsupported service: %s", s.service)
98+
}
99+
}
100+
101+
// DeleteCloudProviderSnapshot encapsulate the logic to manage different cloud providers
102+
func (s *Store) DeleteCloudProviderSnapshot(projectID, clusterName, snapshotID string) error {
103+
o := &atlas.SnapshotReqPathParameters{
104+
GroupID: projectID,
105+
ClusterName: clusterName,
106+
SnapshotID: snapshotID,
107+
}
108+
switch s.service {
109+
case config.CloudService:
110+
_, err := s.client.(*atlas.Client).CloudProviderSnapshots.Delete(context.Background(), o)
111+
return err
112+
default:
113+
return fmt.Errorf("unsupported service: %s", s.service)
114+
}
115+
}

internal/store/continuous_backup.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
//go:generate mockgen -destination=../mocks/mock_continuous_backup.go -package=mocks github.com/mongodb/mongocli/internal/store CheckpointsLister,ContinuousJobLister,ContinuousJobCreator,SnapshotsLister,SnapshotDescriber
2727

2828
type CheckpointsLister interface {
29-
List(string, string, *atlas.ListOptions) (*atlas.Checkpoints, error)
29+
Checkpoints(string, string, *atlas.ListOptions) (*atlas.Checkpoints, error)
3030
}
3131

3232
type ContinuousJobLister interface {
@@ -45,8 +45,8 @@ type SnapshotDescriber interface {
4545
ContinuousSnapshot(string, string, string) (*atlas.ContinuousSnapshot, error)
4646
}
4747

48-
// List encapsulate the logic to manage different cloud providers
49-
func (s *Store) List(projectID, clusterID string, opts *atlas.ListOptions) (*atlas.Checkpoints, error) {
48+
// Checkpoints encapsulate the logic to manage different cloud providers
49+
func (s *Store) Checkpoints(projectID, clusterID string, opts *atlas.ListOptions) (*atlas.Checkpoints, error) {
5050
switch s.service {
5151
case config.CloudService:
5252
result, _, err := s.client.(*atlas.Client).Checkpoints.List(context.Background(), projectID, clusterID, opts)
@@ -59,6 +59,7 @@ func (s *Store) List(projectID, clusterID string, opts *atlas.ListOptions) (*atl
5959
}
6060
}
6161

62+
// ContinuousRestoreJobs encapsulate the logic to manage different cloud providers
6263
func (s *Store) ContinuousRestoreJobs(projectID, clusterID string, opts *atlas.ListOptions) (*atlas.ContinuousJobs, error) {
6364
switch s.service {
6465
case config.CloudService:
@@ -86,7 +87,7 @@ func (s *Store) CreateContinuousRestoreJob(projectID, clusterID string, request
8687
}
8788
}
8889

89-
// ProjectClusters encapsulate the logic to manage different cloud providers
90+
// ContinuousSnapshots encapsulate the logic to manage different cloud providers
9091
func (s *Store) ContinuousSnapshots(projectID, clusterID string, opts *atlas.ListOptions) (*atlas.ContinuousSnapshots, error) {
9192
switch s.service {
9293
case config.CloudService:
@@ -100,7 +101,7 @@ func (s *Store) ContinuousSnapshots(projectID, clusterID string, opts *atlas.Lis
100101
}
101102
}
102103

103-
// Cluster encapsulate the logic to manage different cloud providers
104+
// ContinuousSnapshot encapsulate the logic to manage different cloud providers
104105
func (s *Store) ContinuousSnapshot(projectID, clusterID, snapshotID string) (*atlas.ContinuousSnapshot, error) {
105106
switch s.service {
106107
case config.CloudService:

0 commit comments

Comments
 (0)