Skip to content

Commit c3435ec

Browse files
INTMDB-781: Query Parameter Add: retainBackups in Cluster and Advanced_Cluster (#493)
1 parent f3df93d commit c3435ec

File tree

4 files changed

+31
-7
lines changed

4 files changed

+31
-7
lines changed

mongodbatlas/advanced_clusters.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type AdvancedClustersService interface {
3232
Get(ctx context.Context, groupID, clusterName string) (*AdvancedCluster, *Response, error)
3333
Create(ctx context.Context, groupID string, cluster *AdvancedCluster) (*AdvancedCluster, *Response, error)
3434
Update(ctx context.Context, groupID, clusterName string, cluster *AdvancedCluster) (*AdvancedCluster, *Response, error)
35-
Delete(ctx context.Context, groupID, clusterName string) (*Response, error)
35+
Delete(ctx context.Context, groupID, clusterName string, options *DeleteAdvanceClusterOptions) (*Response, error)
3636
TestFailover(ctx context.Context, groupID, clusterName string) (*Response, error)
3737
}
3838

@@ -109,6 +109,11 @@ type AdvancedClustersResponse struct {
109109
TotalCount int `json:"totalCount,omitempty"`
110110
}
111111

112+
type DeleteAdvanceClusterOptions struct {
113+
// Flag that indicates whether to retain backup snapshots for the deleted dedicated cluster.
114+
RetainBackups *bool `url:"retainBackups,omitempty"`
115+
}
116+
112117
// List all clusters in the project associated to {GROUP-ID}.
113118
//
114119
// See more: https://docs.atlas.mongodb.com/reference/api/cluster-advanced/get-all-cluster-advanced/
@@ -227,7 +232,7 @@ func (s *AdvancedClustersServiceOp) Update(ctx context.Context, groupID, cluster
227232
}
228233

229234
// Delete the cluster specified to {CLUSTER-NAME} from the project associated to {GROUP-ID}.
230-
func (s *AdvancedClustersServiceOp) Delete(ctx context.Context, groupID, clusterName string) (*Response, error) {
235+
func (s *AdvancedClustersServiceOp) Delete(ctx context.Context, groupID, clusterName string, options *DeleteAdvanceClusterOptions) (*Response, error) {
231236
if groupID == "" {
232237
return nil, NewArgError("groupId", "must be set")
233238
}
@@ -239,6 +244,12 @@ func (s *AdvancedClustersServiceOp) Delete(ctx context.Context, groupID, cluster
239244
escapedEntry := url.PathEscape(clusterName)
240245
path := fmt.Sprintf("%s/%s", basePath, escapedEntry)
241246

247+
// Add query params from options
248+
path, err := setListOptions(path, options)
249+
if err != nil {
250+
return nil, err
251+
}
252+
242253
req, err := s.Client.NewRequest(ctx, http.MethodDelete, path, nil)
243254
if err != nil {
244255
return nil, err

mongodbatlas/advanced_clusters_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1265,7 +1265,10 @@ func TestAdvancedClusters_Delete(t *testing.T) {
12651265
testMethod(t, r, http.MethodDelete)
12661266
})
12671267

1268-
_, err := client.AdvancedClusters.Delete(ctx, groupID, clusterName)
1268+
options := &DeleteAdvanceClusterOptions{
1269+
RetainBackups: pointer(true),
1270+
}
1271+
_, err := client.AdvancedClusters.Delete(ctx, groupID, clusterName, options)
12691272
if err != nil {
12701273
t.Fatalf("Cluster.Delete returned error: %v", err)
12711274
}

mongodbatlas/clusters.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ type ClustersService interface {
4242
Get(ctx context.Context, groupID, clusterName string) (*Cluster, *Response, error)
4343
Create(ctx context.Context, groupID string, cluster *Cluster) (*Cluster, *Response, error)
4444
Update(ctx context.Context, groupID, clusterName string, cluster *Cluster) (*Cluster, *Response, error)
45-
Delete(ctx context.Context, groupID, clusterName string) (*Response, error)
45+
Delete(ctx context.Context, groupID, clusterName string, options *DeleteAdvanceClusterOptions) (*Response, error)
4646
UpdateProcessArgs(ctx context.Context, groupID, clusterName string, args *ProcessArgs) (*ProcessArgs, *Response, error)
4747
GetProcessArgs(ctx context.Context, groupID, clusterName string) (*ProcessArgs, *Response, error)
4848
Status(ctx context.Context, groupID, clusterName string) (ClusterStatus, *Response, error)
@@ -421,8 +421,8 @@ func (s *ClustersServiceOp) Update(ctx context.Context, groupID, clusterName str
421421

422422
// Delete the cluster specified to {CLUSTER-NAME} from the project associated to {GROUP-ID}.
423423
//
424-
// See more: https://docs.atlas.mongodb.com/reference/api/clusters-delete-one/
425-
func (s *ClustersServiceOp) Delete(ctx context.Context, groupID, clusterName string) (*Response, error) {
424+
// See more: https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#tag/Clusters/operation/deleteLegacyCluster
425+
func (s *ClustersServiceOp) Delete(ctx context.Context, groupID, clusterName string, options *DeleteAdvanceClusterOptions) (*Response, error) {
426426
if groupID == "" {
427427
return nil, NewArgError("groupId", "must be set")
428428
}
@@ -434,6 +434,12 @@ func (s *ClustersServiceOp) Delete(ctx context.Context, groupID, clusterName str
434434
escapedEntry := url.PathEscape(clusterName)
435435
path := fmt.Sprintf("%s/%s", basePath, escapedEntry)
436436

437+
// Add query params from options
438+
path, err := setListOptions(path, options)
439+
if err != nil {
440+
return nil, err
441+
}
442+
437443
req, err := s.Client.NewRequest(ctx, http.MethodDelete, path, nil)
438444
if err != nil {
439445
return nil, err

mongodbatlas/clusters_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,11 @@ func TestClusters_Delete(t *testing.T) {
745745
testMethod(t, r, http.MethodDelete)
746746
})
747747

748-
_, err := client.Clusters.Delete(ctx, groupID, name)
748+
options := &DeleteAdvanceClusterOptions{
749+
RetainBackups: pointer(true),
750+
}
751+
752+
_, err := client.Clusters.Delete(ctx, groupID, name, options)
749753
if err != nil {
750754
t.Fatalf("Cluster.Delete returned error: %v", err)
751755
}

0 commit comments

Comments
 (0)