diff --git a/Makefile b/Makefile index 989bfd9f85..e3aad1e7ac 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ SOURCE_FILES?=./... BINARY_NAME=mongocli DESTINATION=./bin/${BINARY_NAME} -GOLANGCI_VERSION=v1.23.6 +GOLANGCI_VERSION=v1.23.8 COVERAGE=coverage.out VERSION=$(shell git describe --always --tags) @@ -58,6 +58,7 @@ gen-mocks: ## Generate mocks mockgen -source=internal/store/projects.go -destination=internal/mocks/mock_projects.go -package=mocks mockgen -source=internal/store/organizations.go -destination=internal/mocks/mock_organizations.go -package=mocks mockgen -source=internal/store/owners.go -destination=internal/mocks/mock_owners.go -package=mocks + mockgen -source=internal/store/continuous_snapshots.go -destination=internal/mocks/mock_continuous_snapshots.go -package=mocks .PHONY: build build: ## Generate a binary in ./bin diff --git a/go.mod b/go.mod index 4b0c6d6ccc..dede645ae8 100644 --- a/go.mod +++ b/go.mod @@ -11,8 +11,8 @@ require ( github.com/mattn/go-colorable v0.1.4 // indirect github.com/mattn/go-isatty v0.0.12 // indirect github.com/mitchellh/go-homedir v1.1.0 - github.com/mongodb/go-client-mongodb-atlas v0.1.4-0.20200309214044-0a9bf30571f7 - github.com/mongodb/go-client-mongodb-ops-manager v0.0.2-0.20200310093302-8d5d810fb4a0 + github.com/mongodb/go-client-mongodb-atlas v0.1.4-0.20200312093748-8894c1fe3bb6 + github.com/mongodb/go-client-mongodb-ops-manager v0.0.2-0.20200312102454-e5173cc1a3b0 github.com/pelletier/go-toml v1.6.0 // indirect github.com/spf13/afero v1.2.2 github.com/spf13/cast v1.3.1 // indirect diff --git a/go.sum b/go.sum index 0a24bd21a9..a4b99a2d24 100644 --- a/go.sum +++ b/go.sum @@ -100,10 +100,10 @@ github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= -github.com/mongodb/go-client-mongodb-atlas v0.1.4-0.20200309214044-0a9bf30571f7 h1:ozMruEaA/TRIRBGAy0tfi8pneCsYvCM0Djdu/wENnQs= -github.com/mongodb/go-client-mongodb-atlas v0.1.4-0.20200309214044-0a9bf30571f7/go.mod h1:LS8O0YLkA+sbtOb3fZLF10yY3tJM+1xATXMJ3oU35LU= -github.com/mongodb/go-client-mongodb-ops-manager v0.0.2-0.20200310093302-8d5d810fb4a0 h1:3f5ftr/+/Zb7tDD6oArYoF1A1/kDvVhjEKSstXhESxI= -github.com/mongodb/go-client-mongodb-ops-manager v0.0.2-0.20200310093302-8d5d810fb4a0/go.mod h1:cR0vrJsJ1ZssXzfKNk9KCduPJKLHkmClDeTmkKXSJA0= +github.com/mongodb/go-client-mongodb-atlas v0.1.4-0.20200312093748-8894c1fe3bb6 h1:ukGCT8EiyLDm+dOJOgRqySvDjZJly5tUPUDZmQt+f0Y= +github.com/mongodb/go-client-mongodb-atlas v0.1.4-0.20200312093748-8894c1fe3bb6/go.mod h1:LS8O0YLkA+sbtOb3fZLF10yY3tJM+1xATXMJ3oU35LU= +github.com/mongodb/go-client-mongodb-ops-manager v0.0.2-0.20200312102454-e5173cc1a3b0 h1:yOYbV6B8nH8jBoSKjITRE7TkU0xeAst7mAIt+JPFUlE= +github.com/mongodb/go-client-mongodb-ops-manager v0.0.2-0.20200312102454-e5173cc1a3b0/go.mod h1:G9iLP4YeC2TRpxjZRddP6wKjz2JbpAtX+MlKriO7TOU= github.com/mwielbut/pointy v1.1.0 h1:U5/YEfoIkaGCHv0St3CgjduqXID4FNRoyZgLM1kY9vg= github.com/mwielbut/pointy v1.1.0/go.mod h1:MvvO+uMFj9T5DMda33HlvogsFBX7pWWKAkFIn4teYwY= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= diff --git a/internal/cli/atlas.go b/internal/cli/atlas.go index d49b1f5cae..7c446e531c 100644 --- a/internal/cli/atlas.go +++ b/internal/cli/atlas.go @@ -27,6 +27,7 @@ func AtlasBuilder() *cobra.Command { cmd.AddCommand(AtlasDBUsersBuilder()) cmd.AddCommand(AtlasWhitelistBuilder()) cmd.AddCommand(AtlasAlertsBuilder()) + cmd.AddCommand(AtlasBackupsBuilder()) return cmd } diff --git a/internal/cli/atlas_backups.go b/internal/cli/atlas_backups.go new file mode 100644 index 0000000000..aa36b95ed1 --- /dev/null +++ b/internal/cli/atlas_backups.go @@ -0,0 +1,31 @@ +// 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/spf13/cobra" +) + +func AtlasBackupsBuilder() *cobra.Command { + cmd := &cobra.Command{ + Use: "backups", + Aliases: []string{"backup"}, + Short: "Manage continuous backups for your project.", + } + + cmd.AddCommand(AtlasBackupsSnapshotsBuilder()) + + return cmd +} diff --git a/internal/cli/atlas_backups_snapshots.go b/internal/cli/atlas_backups_snapshots.go new file mode 100644 index 0000000000..243270ed7f --- /dev/null +++ b/internal/cli/atlas_backups_snapshots.go @@ -0,0 +1,31 @@ +// 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/spf13/cobra" +) + +func AtlasBackupsSnapshotsBuilder() *cobra.Command { + cmd := &cobra.Command{ + Use: "snapshots", + Aliases: []string{"snapshot"}, + Short: "Manage continuous snapshots for your project.", + } + + cmd.AddCommand(AtlasBackupsSnapshotsListBuilder()) + + return cmd +} diff --git a/internal/cli/atlas_backups_snapshots_list.go b/internal/cli/atlas_backups_snapshots_list.go new file mode 100644 index 0000000000..4d22ab1708 --- /dev/null +++ b/internal/cli/atlas_backups_snapshots_list.go @@ -0,0 +1,88 @@ +// 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 ( + atlas "github.com/mongodb/go-client-mongodb-atlas/mongodbatlas" + "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 atlasBackupsSnapshotsListOpts struct { + *globalOpts + clusterName string + pageNum int + itemsPerPage int + store store.SnapshotsLister +} + +func (opts *atlasBackupsSnapshotsListOpts) init() error { + if opts.ProjectID() == "" { + return errMissingProjectID + } + + var err error + opts.store, err = store.New() + return err +} + +func (opts *atlasBackupsSnapshotsListOpts) Run() error { + listOpts := opts.newListOptions() + result, err := opts.store.ContinuousSnapshots(opts.ProjectID(), opts.clusterName, listOpts) + + if err != nil { + return err + } + + return json.PrettyPrint(result) +} + +func (opts *atlasBackupsSnapshotsListOpts) newListOptions() *atlas.ListOptions { + return &atlas.ListOptions{ + PageNum: opts.pageNum, + ItemsPerPage: opts.itemsPerPage, + } +} + +// mongocli atlas cluster(s) list --projectId projectId [--page N] [--limit N] +func AtlasBackupsSnapshotsListBuilder() *cobra.Command { + opts := &atlasBackupsSnapshotsListOpts{ + globalOpts: newGlobalOpts(), + } + cmd := &cobra.Command{ + Use: "list", + Short: "List continuous snapshots for a project.", + Aliases: []string{"ls"}, + Args: cobra.ExactArgs(1), + PreRunE: func(cmd *cobra.Command, args []string) error { + return opts.init() + }, + RunE: func(cmd *cobra.Command, args []string) error { + opts.clusterName = args[0] + + 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 +} diff --git a/internal/cli/atlas_backups_snapshots_list_test.go b/internal/cli/atlas_backups_snapshots_list_test.go new file mode 100644 index 0000000000..37e70203f3 --- /dev/null +++ b/internal/cli/atlas_backups_snapshots_list_test.go @@ -0,0 +1,49 @@ +// 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 TestAtlasBackupsSnapshotsList_Run(t *testing.T) { + ctrl := gomock.NewController(t) + mockStore := mocks.NewMockSnapshotsLister(ctrl) + + defer ctrl.Finish() + + expected := fixtures.ContinuousSnapshots() + + listOpts := &atlasBackupsSnapshotsListOpts{ + globalOpts: newGlobalOpts(), + store: mockStore, + clusterName: "Cluster0", + } + + mockStore. + EXPECT(). + ContinuousSnapshots(listOpts.projectID, "Cluster0", listOpts.newListOptions()). + Return(expected, nil). + Times(1) + + err := listOpts.Run() + if err != nil { + t.Fatalf("Run() unexpected error: %v", err) + } +} diff --git a/internal/cli/cloud_manager.go b/internal/cli/cloud_manager.go index b1c9387dc7..52af0fc427 100644 --- a/internal/cli/cloud_manager.go +++ b/internal/cli/cloud_manager.go @@ -27,6 +27,7 @@ func CloudManagerBuilder() *cobra.Command { cmd.AddCommand(CloudManagerClustersBuilder()) cmd.AddCommand(AtlasAlertsBuilder()) + cmd.AddCommand(AtlasBackupsBuilder()) return cmd } diff --git a/internal/cli/ops_manager.go b/internal/cli/ops_manager.go index 7d3c697bb1..5f0f3ca393 100644 --- a/internal/cli/ops_manager.go +++ b/internal/cli/ops_manager.go @@ -28,6 +28,7 @@ func OpsManagerBuilder() *cobra.Command { cmd.AddCommand(CloudManagerClustersBuilder()) cmd.AddCommand(AtlasAlertsBuilder()) cmd.AddCommand(OpsManagerOwnerBuilder()) + cmd.AddCommand(AtlasBackupsBuilder()) return cmd } diff --git a/internal/fixtures/continuous_snapshots.go b/internal/fixtures/continuous_snapshots.go new file mode 100644 index 0000000000..eb42710c1f --- /dev/null +++ b/internal/fixtures/continuous_snapshots.go @@ -0,0 +1,54 @@ +package fixtures + +import atlas "github.com/mongodb/go-client-mongodb-atlas/mongodbatlas" + +func ContinuousSnapshots() *atlas.ContinuousSnapshots { + doNotDelete := false + + return &atlas.ContinuousSnapshots{ + Links: []*atlas.Link{ + { + Href: "https://cloud.mongodb.com/api/atlas/v1.0/groups/6c7498dg87d9e6526801572b/clusters/Cluster0/snapshots?pageNum=1&itemsPerPage=100", + Rel: "self", + }, + }, + Results: []*atlas.ContinuousSnapshot{ + { + ClusterID: "7c2487d833e9e75286093696", + Complete: true, + Created: &atlas.SnapshotTimestamp{ + Date: "2017-12-26T16:32:16Z", + Increment: 1, + }, + DoNotDelete: &doNotDelete, + Expires: "2018-12-25T16:32:16Z", + GroupID: "6c7498dg87d9e6526801572b", + ID: "5a4279d4fcc178500596745a", + LastOplogAppliedTimestamp: &atlas.SnapshotTimestamp{ + Date: "2017-12-26T16:32:15Z", + Increment: 1, + }, + Links: []*atlas.Link{ + { + Href: "https://cloud.mongodb.com/api/atlas/v1.0/groups/6c7498dg87d9e6526801572b/clusters/Cluster0/snapshots/5a4279d4fcc178500596745a", + Rel: "self", + }, + }, + Parts: []*atlas.Part{ + { + ClusterID: "7c2487d833e9e75286093696", + CompressionSetting: "GZIP", + DataSizeBytes: 4502, + EncryptionEnabled: false, + FileSizeBytes: 324760, + MongodVersion: "3.6.10", + ReplicaSetName: "Cluster0-shard-0", + StorageSizeBytes: 53248, + TypeName: "REPLICA_SET", + }, + }, + }, + }, + TotalCount: 1, + } +} diff --git a/internal/mocks/mock_continuous_snapshots.go b/internal/mocks/mock_continuous_snapshots.go new file mode 100644 index 0000000000..7e8889c38d --- /dev/null +++ b/internal/mocks/mock_continuous_snapshots.go @@ -0,0 +1,140 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: internal/store/continuous_snapshots.go + +// Package mocks is a generated GoMock package. +package mocks + +import ( + gomock "github.com/golang/mock/gomock" + mongodbatlas "github.com/mongodb/go-client-mongodb-atlas/mongodbatlas" + reflect "reflect" +) + +// MockSnapshotsLister is a mock of SnapshotsLister interface +type MockSnapshotsLister struct { + ctrl *gomock.Controller + recorder *MockSnapshotsListerMockRecorder +} + +// MockSnapshotsListerMockRecorder is the mock recorder for MockSnapshotsLister +type MockSnapshotsListerMockRecorder struct { + mock *MockSnapshotsLister +} + +// NewMockSnapshotsLister creates a new mock instance +func NewMockSnapshotsLister(ctrl *gomock.Controller) *MockSnapshotsLister { + mock := &MockSnapshotsLister{ctrl: ctrl} + mock.recorder = &MockSnapshotsListerMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use +func (m *MockSnapshotsLister) EXPECT() *MockSnapshotsListerMockRecorder { + return m.recorder +} + +// ContinuousSnapshots mocks base method +func (m *MockSnapshotsLister) ContinuousSnapshots(arg0, arg1 string, arg2 *mongodbatlas.ListOptions) (*mongodbatlas.ContinuousSnapshots, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ContinuousSnapshots", arg0, arg1, arg2) + ret0, _ := ret[0].(*mongodbatlas.ContinuousSnapshots) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ContinuousSnapshots indicates an expected call of ContinuousSnapshots +func (mr *MockSnapshotsListerMockRecorder) ContinuousSnapshots(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ContinuousSnapshots", reflect.TypeOf((*MockSnapshotsLister)(nil).ContinuousSnapshots), arg0, arg1, arg2) +} + +// MockSnapshotDescriber is a mock of SnapshotDescriber interface +type MockSnapshotDescriber struct { + ctrl *gomock.Controller + recorder *MockSnapshotDescriberMockRecorder +} + +// MockSnapshotDescriberMockRecorder is the mock recorder for MockSnapshotDescriber +type MockSnapshotDescriberMockRecorder struct { + mock *MockSnapshotDescriber +} + +// NewMockSnapshotDescriber creates a new mock instance +func NewMockSnapshotDescriber(ctrl *gomock.Controller) *MockSnapshotDescriber { + mock := &MockSnapshotDescriber{ctrl: ctrl} + mock.recorder = &MockSnapshotDescriberMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use +func (m *MockSnapshotDescriber) EXPECT() *MockSnapshotDescriberMockRecorder { + return m.recorder +} + +// ContinuousSnapshot mocks base method +func (m *MockSnapshotDescriber) ContinuousSnapshot(arg0, arg1, arg2 string) (*mongodbatlas.ContinuousSnapshot, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ContinuousSnapshot", arg0, arg1, arg2) + ret0, _ := ret[0].(*mongodbatlas.ContinuousSnapshot) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ContinuousSnapshot indicates an expected call of ContinuousSnapshot +func (mr *MockSnapshotDescriberMockRecorder) ContinuousSnapshot(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ContinuousSnapshot", reflect.TypeOf((*MockSnapshotDescriber)(nil).ContinuousSnapshot), arg0, arg1, arg2) +} + +// MockSnapshotsStore is a mock of SnapshotsStore interface +type MockSnapshotsStore struct { + ctrl *gomock.Controller + recorder *MockSnapshotsStoreMockRecorder +} + +// MockSnapshotsStoreMockRecorder is the mock recorder for MockSnapshotsStore +type MockSnapshotsStoreMockRecorder struct { + mock *MockSnapshotsStore +} + +// NewMockSnapshotsStore creates a new mock instance +func NewMockSnapshotsStore(ctrl *gomock.Controller) *MockSnapshotsStore { + mock := &MockSnapshotsStore{ctrl: ctrl} + mock.recorder = &MockSnapshotsStoreMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use +func (m *MockSnapshotsStore) EXPECT() *MockSnapshotsStoreMockRecorder { + return m.recorder +} + +// ContinuousSnapshots mocks base method +func (m *MockSnapshotsStore) ContinuousSnapshots(arg0, arg1 string, arg2 *mongodbatlas.ListOptions) (*mongodbatlas.ContinuousSnapshots, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ContinuousSnapshots", arg0, arg1, arg2) + ret0, _ := ret[0].(*mongodbatlas.ContinuousSnapshots) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ContinuousSnapshots indicates an expected call of ContinuousSnapshots +func (mr *MockSnapshotsStoreMockRecorder) ContinuousSnapshots(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ContinuousSnapshots", reflect.TypeOf((*MockSnapshotsStore)(nil).ContinuousSnapshots), arg0, arg1, arg2) +} + +// ContinuousSnapshot mocks base method +func (m *MockSnapshotsStore) ContinuousSnapshot(arg0, arg1, arg2 string) (*mongodbatlas.ContinuousSnapshot, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ContinuousSnapshot", arg0, arg1, arg2) + ret0, _ := ret[0].(*mongodbatlas.ContinuousSnapshot) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ContinuousSnapshot indicates an expected call of ContinuousSnapshot +func (mr *MockSnapshotsStoreMockRecorder) ContinuousSnapshot(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ContinuousSnapshot", reflect.TypeOf((*MockSnapshotsStore)(nil).ContinuousSnapshot), arg0, arg1, arg2) +} diff --git a/internal/store/continuous_snapshots.go b/internal/store/continuous_snapshots.go new file mode 100644 index 0000000000..c4bd93c6a3 --- /dev/null +++ b/internal/store/continuous_snapshots.go @@ -0,0 +1,65 @@ +// 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" + om "github.com/mongodb/go-client-mongodb-ops-manager/opsmngr" + "github.com/mongodb/mongocli/internal/config" +) + +type SnapshotsLister interface { + ContinuousSnapshots(string, string, *atlas.ListOptions) (*atlas.ContinuousSnapshots, error) +} + +type SnapshotDescriber interface { + ContinuousSnapshot(string, string, string) (*atlas.ContinuousSnapshot, error) +} + +type SnapshotsStore interface { + SnapshotsLister + SnapshotDescriber +} + +// ProjectClusters encapsulate the logic to manage different cloud providers +func (s *Store) ContinuousSnapshots(projectID, clusterID string, opts *atlas.ListOptions) (*atlas.ContinuousSnapshots, error) { + switch s.service { + case config.CloudService: + result, _, err := s.client.(*atlas.Client).ContinuousSnapshots.List(context.Background(), projectID, clusterID, opts) + return result, err + case config.OpsManagerService, config.CloudManagerService: + result, _, err := s.client.(*om.Client).ContinuousSnapshots.List(context.Background(), projectID, clusterID, opts) + return result, err + default: + return nil, fmt.Errorf("unsupported service: %s", s.service) + } +} + +// Cluster encapsulate the logic to manage different cloud providers +func (s *Store) ContinuousSnapshot(projectID, clusterID, snapshotID string) (*atlas.ContinuousSnapshot, error) { + switch s.service { + case config.CloudService: + result, _, err := s.client.(*atlas.Client).ContinuousSnapshots.Get(context.Background(), projectID, clusterID, snapshotID) + return result, err + case config.OpsManagerService, config.CloudManagerService: + result, _, err := s.client.(*om.Client).ContinuousSnapshots.Get(context.Background(), projectID, clusterID, snapshotID) + return result, err + default: + return nil, fmt.Errorf("unsupported service: %s", s.service) + } +}