From 3394edfcf6e6e872f939e17490a598a595ff3618 Mon Sep 17 00:00:00 2001 From: andreaangiolillo Date: Tue, 6 Jun 2023 10:37:55 +0100 Subject: [PATCH 1/3] INTMDB-781: Query Parameter Add: retainBackups in Cluster and Advanced_Cluster --- mongodbatlas/advanced_clusters.go | 21 +++++++++++++++++++-- mongodbatlas/advanced_clusters_test.go | 5 ++++- mongodbatlas/clusters.go | 18 +++++++++++++++--- mongodbatlas/clusters_test.go | 6 +++++- 4 files changed, 43 insertions(+), 7 deletions(-) diff --git a/mongodbatlas/advanced_clusters.go b/mongodbatlas/advanced_clusters.go index 1b371352..90e9b867 100644 --- a/mongodbatlas/advanced_clusters.go +++ b/mongodbatlas/advanced_clusters.go @@ -32,7 +32,7 @@ type AdvancedClustersService interface { Get(ctx context.Context, groupID, clusterName string) (*AdvancedCluster, *Response, error) Create(ctx context.Context, groupID string, cluster *AdvancedCluster) (*AdvancedCluster, *Response, error) Update(ctx context.Context, groupID, clusterName string, cluster *AdvancedCluster) (*AdvancedCluster, *Response, error) - Delete(ctx context.Context, groupID, clusterName string) (*Response, error) + Delete(ctx context.Context, groupID, clusterName string, options *DeleteAdvanceClusterOptions) (*Response, error) TestFailover(ctx context.Context, groupID, clusterName string) (*Response, error) } @@ -109,6 +109,11 @@ type AdvancedClustersResponse struct { TotalCount int `json:"totalCount,omitempty"` } +type DeleteAdvanceClusterOptions struct { + // Flag that indicates whether to retain backup snapshots for the deleted dedicated cluster. + RetainBackups bool `url:"retainBackups,omitempty"` +} + // List all clusters in the project associated to {GROUP-ID}. // // 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 } // Delete the cluster specified to {CLUSTER-NAME} from the project associated to {GROUP-ID}. -func (s *AdvancedClustersServiceOp) Delete(ctx context.Context, groupID, clusterName string) (*Response, error) { +func (s *AdvancedClustersServiceOp) Delete(ctx context.Context, groupID, clusterName string, options *DeleteAdvanceClusterOptions) (*Response, error) { if groupID == "" { return nil, NewArgError("groupId", "must be set") } @@ -239,6 +244,18 @@ func (s *AdvancedClustersServiceOp) Delete(ctx context.Context, groupID, cluster escapedEntry := url.PathEscape(clusterName) path := fmt.Sprintf("%s/%s", basePath, escapedEntry) + if options == nil { + options = &DeleteAdvanceClusterOptions{ + RetainBackups: false, + } + } + + // Add query params from options + path, err := setListOptions(path, options) + if err != nil { + return nil, err + } + req, err := s.Client.NewRequest(ctx, http.MethodDelete, path, nil) if err != nil { return nil, err diff --git a/mongodbatlas/advanced_clusters_test.go b/mongodbatlas/advanced_clusters_test.go index 4c243f2c..f2958bce 100644 --- a/mongodbatlas/advanced_clusters_test.go +++ b/mongodbatlas/advanced_clusters_test.go @@ -1265,7 +1265,10 @@ func TestAdvancedClusters_Delete(t *testing.T) { testMethod(t, r, http.MethodDelete) }) - _, err := client.AdvancedClusters.Delete(ctx, groupID, clusterName) + options := &DeleteAdvanceClusterOptions{ + RetainBackups: true, + } + _, err := client.AdvancedClusters.Delete(ctx, groupID, clusterName, options) if err != nil { t.Fatalf("Cluster.Delete returned error: %v", err) } diff --git a/mongodbatlas/clusters.go b/mongodbatlas/clusters.go index 76d4f942..5589901a 100644 --- a/mongodbatlas/clusters.go +++ b/mongodbatlas/clusters.go @@ -42,7 +42,7 @@ type ClustersService interface { Get(ctx context.Context, groupID, clusterName string) (*Cluster, *Response, error) Create(ctx context.Context, groupID string, cluster *Cluster) (*Cluster, *Response, error) Update(ctx context.Context, groupID, clusterName string, cluster *Cluster) (*Cluster, *Response, error) - Delete(ctx context.Context, groupID, clusterName string) (*Response, error) + Delete(ctx context.Context, groupID, clusterName string, options *DeleteAdvanceClusterOptions) (*Response, error) UpdateProcessArgs(ctx context.Context, groupID, clusterName string, args *ProcessArgs) (*ProcessArgs, *Response, error) GetProcessArgs(ctx context.Context, groupID, clusterName string) (*ProcessArgs, *Response, error) Status(ctx context.Context, groupID, clusterName string) (ClusterStatus, *Response, error) @@ -421,8 +421,8 @@ func (s *ClustersServiceOp) Update(ctx context.Context, groupID, clusterName str // Delete the cluster specified to {CLUSTER-NAME} from the project associated to {GROUP-ID}. // -// See more: https://docs.atlas.mongodb.com/reference/api/clusters-delete-one/ -func (s *ClustersServiceOp) Delete(ctx context.Context, groupID, clusterName string) (*Response, error) { +// See more: https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#tag/Clusters/operation/deleteLegacyCluster +func (s *ClustersServiceOp) Delete(ctx context.Context, groupID, clusterName string, options *DeleteAdvanceClusterOptions) (*Response, error) { if groupID == "" { return nil, NewArgError("groupId", "must be set") } @@ -434,6 +434,18 @@ func (s *ClustersServiceOp) Delete(ctx context.Context, groupID, clusterName str escapedEntry := url.PathEscape(clusterName) path := fmt.Sprintf("%s/%s", basePath, escapedEntry) + if options == nil { + options = &DeleteAdvanceClusterOptions{ + RetainBackups: false, + } + } + + // Add query params from options + path, err := setListOptions(path, options) + if err != nil { + return nil, err + } + req, err := s.Client.NewRequest(ctx, http.MethodDelete, path, nil) if err != nil { return nil, err diff --git a/mongodbatlas/clusters_test.go b/mongodbatlas/clusters_test.go index 5293613d..1c395be2 100644 --- a/mongodbatlas/clusters_test.go +++ b/mongodbatlas/clusters_test.go @@ -745,7 +745,11 @@ func TestClusters_Delete(t *testing.T) { testMethod(t, r, http.MethodDelete) }) - _, err := client.Clusters.Delete(ctx, groupID, name) + options := &DeleteAdvanceClusterOptions{ + RetainBackups: true, + } + + _, err := client.Clusters.Delete(ctx, groupID, name, options) if err != nil { t.Fatalf("Cluster.Delete returned error: %v", err) } From 858bcc956ea9e1b5fbe719531344dda9d69a7539 Mon Sep 17 00:00:00 2001 From: andreaangiolillo Date: Tue, 6 Jun 2023 13:02:34 +0100 Subject: [PATCH 2/3] Addressed Gustavo's comments --- mongodbatlas/advanced_clusters.go | 8 +------- mongodbatlas/clusters.go | 6 ------ 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/mongodbatlas/advanced_clusters.go b/mongodbatlas/advanced_clusters.go index 90e9b867..c7740b04 100644 --- a/mongodbatlas/advanced_clusters.go +++ b/mongodbatlas/advanced_clusters.go @@ -111,7 +111,7 @@ type AdvancedClustersResponse struct { type DeleteAdvanceClusterOptions struct { // Flag that indicates whether to retain backup snapshots for the deleted dedicated cluster. - RetainBackups bool `url:"retainBackups,omitempty"` + RetainBackups *bool `url:"retainBackups,omitempty"` } // List all clusters in the project associated to {GROUP-ID}. @@ -244,12 +244,6 @@ func (s *AdvancedClustersServiceOp) Delete(ctx context.Context, groupID, cluster escapedEntry := url.PathEscape(clusterName) path := fmt.Sprintf("%s/%s", basePath, escapedEntry) - if options == nil { - options = &DeleteAdvanceClusterOptions{ - RetainBackups: false, - } - } - // Add query params from options path, err := setListOptions(path, options) if err != nil { diff --git a/mongodbatlas/clusters.go b/mongodbatlas/clusters.go index 5589901a..d9ad7182 100644 --- a/mongodbatlas/clusters.go +++ b/mongodbatlas/clusters.go @@ -434,12 +434,6 @@ func (s *ClustersServiceOp) Delete(ctx context.Context, groupID, clusterName str escapedEntry := url.PathEscape(clusterName) path := fmt.Sprintf("%s/%s", basePath, escapedEntry) - if options == nil { - options = &DeleteAdvanceClusterOptions{ - RetainBackups: false, - } - } - // Add query params from options path, err := setListOptions(path, options) if err != nil { From 4ac5ad9ed58a6f7a9ae3895ea8a5e219c6e8d2ec Mon Sep 17 00:00:00 2001 From: andreaangiolillo Date: Tue, 6 Jun 2023 13:07:34 +0100 Subject: [PATCH 3/3] lint error --- mongodbatlas/advanced_clusters_test.go | 2 +- mongodbatlas/clusters_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mongodbatlas/advanced_clusters_test.go b/mongodbatlas/advanced_clusters_test.go index f2958bce..a790bae5 100644 --- a/mongodbatlas/advanced_clusters_test.go +++ b/mongodbatlas/advanced_clusters_test.go @@ -1266,7 +1266,7 @@ func TestAdvancedClusters_Delete(t *testing.T) { }) options := &DeleteAdvanceClusterOptions{ - RetainBackups: true, + RetainBackups: pointer(true), } _, err := client.AdvancedClusters.Delete(ctx, groupID, clusterName, options) if err != nil { diff --git a/mongodbatlas/clusters_test.go b/mongodbatlas/clusters_test.go index 1c395be2..2a9412d0 100644 --- a/mongodbatlas/clusters_test.go +++ b/mongodbatlas/clusters_test.go @@ -746,7 +746,7 @@ func TestClusters_Delete(t *testing.T) { }) options := &DeleteAdvanceClusterOptions{ - RetainBackups: true, + RetainBackups: pointer(true), } _, err := client.Clusters.Delete(ctx, groupID, name, options)