Skip to content

Commit

Permalink
INTMDB-781: Query Parameter Add: retainBackups in Cluster and Advance…
Browse files Browse the repository at this point in the history
…d_Cluster (#493)
  • Loading branch information
andreaangiolillo authored Jun 7, 2023
1 parent f3df93d commit c3435ec
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
15 changes: 13 additions & 2 deletions mongodbatlas/advanced_clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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/
Expand Down Expand Up @@ -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")
}
Expand All @@ -239,6 +244,12 @@ func (s *AdvancedClustersServiceOp) Delete(ctx context.Context, groupID, cluster
escapedEntry := url.PathEscape(clusterName)
path := fmt.Sprintf("%s/%s", basePath, escapedEntry)

// 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
Expand Down
5 changes: 4 additions & 1 deletion mongodbatlas/advanced_clusters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: pointer(true),
}
_, err := client.AdvancedClusters.Delete(ctx, groupID, clusterName, options)
if err != nil {
t.Fatalf("Cluster.Delete returned error: %v", err)
}
Expand Down
12 changes: 9 additions & 3 deletions mongodbatlas/clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
}
Expand All @@ -434,6 +434,12 @@ func (s *ClustersServiceOp) Delete(ctx context.Context, groupID, clusterName str
escapedEntry := url.PathEscape(clusterName)
path := fmt.Sprintf("%s/%s", basePath, escapedEntry)

// 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
Expand Down
6 changes: 5 additions & 1 deletion mongodbatlas/clusters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: pointer(true),
}

_, err := client.Clusters.Delete(ctx, groupID, name, options)
if err != nil {
t.Fatalf("Cluster.Delete returned error: %v", err)
}
Expand Down

0 comments on commit c3435ec

Please sign in to comment.