|
| 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 | +} |
0 commit comments