Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Adds acceptDataRisksAndForceReplicaSetReconfig parameter in cluster and advanced cluster #518

Merged
merged 2 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 22 additions & 21 deletions mongodbatlas/advanced_clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,28 @@ var _ AdvancedClustersService = &AdvancedClustersServiceOp{}

// AdvancedCluster represents MongoDB cluster.
type AdvancedCluster struct {
BackupEnabled *bool `json:"backupEnabled,omitempty"`
BiConnector *BiConnector `json:"biConnector,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we avoid formatter changes?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that can be done, it's go fmt because the new field name length is larger, I don't think we should override go fmt

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should override go fmt

Apologies for lack of clarity. That wasn't my intention.

I think a good pattern in this case is to add this field as the last element. Since this field is much longer than everything else we can add comment or enter and then rest of the content is not affected:

Screenshot 2023-10-30 at 15 43 05

Hope that makes sense

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I have done:

  1. git reset --soft head~2
  2. Moved field to the bottom
  3. make fmt

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this client we like to keep fields alphabetically ordered for easy comparison in case of missing fields

Copy link
Member Author

@lantoli lantoli Oct 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry I just saw this comment. Exactly, I wanted to keep the same order as in the new SDK

ClusterType string `json:"clusterType,omitempty"`
ConnectionStrings *ConnectionStrings `json:"connectionStrings,omitempty"`
DiskSizeGB *float64 `json:"diskSizeGB,omitempty"`
EncryptionAtRestProvider string `json:"encryptionAtRestProvider,omitempty"`
GroupID string `json:"groupId,omitempty"`
ID string `json:"id,omitempty"`
Labels []Label `json:"labels,omitempty"`
MongoDBMajorVersion string `json:"mongoDBMajorVersion,omitempty"`
MongoDBVersion string `json:"mongoDBVersion,omitempty"`
Name string `json:"name,omitempty"`
Paused *bool `json:"paused,omitempty"`
PitEnabled *bool `json:"pitEnabled,omitempty"`
StateName string `json:"stateName,omitempty"`
ReplicationSpecs []*AdvancedReplicationSpec `json:"replicationSpecs,omitempty"`
CreateDate string `json:"createDate,omitempty"`
RootCertType string `json:"rootCertType,omitempty"`
VersionReleaseSystem string `json:"versionReleaseSystem,omitempty"`
TerminationProtectionEnabled *bool `json:"terminationProtectionEnabled,omitempty"`
Tags []*Tag `json:"tags,omitempty"`
AcceptDataRisksAndForceReplicaSetReconfig string `json:"acceptDataRisksAndForceReplicaSetReconfig,omitempty"`
BackupEnabled *bool `json:"backupEnabled,omitempty"`
BiConnector *BiConnector `json:"biConnector,omitempty"`
ClusterType string `json:"clusterType,omitempty"`
ConnectionStrings *ConnectionStrings `json:"connectionStrings,omitempty"`
DiskSizeGB *float64 `json:"diskSizeGB,omitempty"`
EncryptionAtRestProvider string `json:"encryptionAtRestProvider,omitempty"`
GroupID string `json:"groupId,omitempty"`
ID string `json:"id,omitempty"`
Labels []Label `json:"labels,omitempty"`
MongoDBMajorVersion string `json:"mongoDBMajorVersion,omitempty"`
MongoDBVersion string `json:"mongoDBVersion,omitempty"`
Name string `json:"name,omitempty"`
Paused *bool `json:"paused,omitempty"`
PitEnabled *bool `json:"pitEnabled,omitempty"`
StateName string `json:"stateName,omitempty"`
ReplicationSpecs []*AdvancedReplicationSpec `json:"replicationSpecs,omitempty"`
CreateDate string `json:"createDate,omitempty"`
RootCertType string `json:"rootCertType,omitempty"`
VersionReleaseSystem string `json:"versionReleaseSystem,omitempty"`
TerminationProtectionEnabled *bool `json:"terminationProtectionEnabled,omitempty"`
Tags []*Tag `json:"tags,omitempty"`
}

type AdvancedReplicationSpec struct {
Expand Down
12 changes: 11 additions & 1 deletion mongodbatlas/advanced_clusters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func TestAdvancedClusters_List(t *testing.T) {
"readPreference": "secondary"
},
"clusterType": "REPLICASET",
"acceptDataRisksAndForceReplicaSetReconfig": "2021-03-02T22:25:18Z",
"createDate": "2021-03-02T22:25:18Z",
"diskSizeGB": 10.0,
"encryptionAtRestProvider": "NONE",
Expand Down Expand Up @@ -112,6 +113,7 @@ func TestAdvancedClusters_List(t *testing.T) {
"readPreference": "secondary"
},
"clusterType": "GEOSHARDED",
"acceptDataRisksAndForceReplicaSetReconfig": "2021-03-02T22:27:46Z",
"createDate": "2021-03-02T22:27:46Z",
"diskSizeGB": 40.0,
"encryptionAtRestProvider": "NONE",
Expand Down Expand Up @@ -294,7 +296,8 @@ func TestAdvancedClusters_List(t *testing.T) {
},
},
},
CreateDate: "2021-03-02T22:25:18Z",
CreateDate: "2021-03-02T22:25:18Z",
AcceptDataRisksAndForceReplicaSetReconfig: "2021-03-02T22:25:18Z",
RootCertType: "DST",
},
{
Expand Down Expand Up @@ -393,6 +396,7 @@ func TestAdvancedClusters_List(t *testing.T) {
},
},
}},
AcceptDataRisksAndForceReplicaSetReconfig: "2021-03-02T22:27:46Z",
CreateDate: "2021-03-02T22:27:46Z",
RootCertType: "DST",
VersionReleaseSystem: "LTS",
Expand Down Expand Up @@ -636,6 +640,7 @@ func TestAdvancedClusters_Create(t *testing.T) {
"readPreference": "secondary"
},
"clusterType": "GEOSHARDED",
"acceptDataRisksAndForceReplicaSetReconfig": "2021-03-02T22:27:46Z",
"createDate": "2021-03-02T22:27:46Z",
"diskSizeGB": 40.0,
"encryptionAtRestProvider": "NONE",
Expand Down Expand Up @@ -832,6 +837,7 @@ func TestAdvancedClusters_Create(t *testing.T) {
},
},
}},
AcceptDataRisksAndForceReplicaSetReconfig: "2021-03-02T22:27:46Z",
CreateDate: "2021-03-02T22:27:46Z",
RootCertType: "DST",
VersionReleaseSystem: "LTS",
Expand Down Expand Up @@ -938,6 +944,7 @@ func TestAdvancedClusters_Create(t *testing.T) {
},
},
}},
AcceptDataRisksAndForceReplicaSetReconfig: "2021-03-02T22:27:46Z",
CreateDate: "2021-03-02T22:27:46Z",
RootCertType: "DST",
VersionReleaseSystem: "LTS",
Expand All @@ -960,6 +967,7 @@ func TestAdvancedClusters_Update(t *testing.T) {
"readPreference": "secondary"
},
"clusterType": "GEOSHARDED",
"acceptDataRisksAndForceReplicaSetReconfig": "2021-03-02T22:27:46Z",
"createDate": "2021-03-02T22:27:46Z",
"diskSizeGB": 40.0,
"encryptionAtRestProvider": "NONE",
Expand Down Expand Up @@ -1149,6 +1157,7 @@ func TestAdvancedClusters_Update(t *testing.T) {
},
},
}},
AcceptDataRisksAndForceReplicaSetReconfig: "2021-03-02T22:27:46Z",
CreateDate: "2021-03-02T22:27:46Z",
RootCertType: "DST",
}
Expand Down Expand Up @@ -1248,6 +1257,7 @@ func TestAdvancedClusters_Update(t *testing.T) {
},
},
}},
AcceptDataRisksAndForceReplicaSetReconfig: "2021-03-02T22:27:46Z",
CreateDate: "2021-03-02T22:27:46Z",
RootCertType: "DST",
}
Expand Down
67 changes: 34 additions & 33 deletions mongodbatlas/clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,39 +140,40 @@ type ConnectionStrings struct {

// Cluster represents MongoDB cluster.
type Cluster struct {
AutoScaling *AutoScaling `json:"autoScaling,omitempty"`
BackupEnabled *bool `json:"backupEnabled,omitempty"` // Deprecated: Use ProviderBackupEnabled instead
BiConnector *BiConnector `json:"biConnector,omitempty"`
ClusterType string `json:"clusterType,omitempty"`
DiskSizeGB *float64 `json:"diskSizeGB,omitempty"`
EncryptionAtRestProvider string `json:"encryptionAtRestProvider,omitempty"`
Labels []Label `json:"labels,omitempty"`
ID string `json:"id,omitempty"`
GroupID string `json:"groupId,omitempty"`
MongoDBVersion string `json:"mongoDBVersion,omitempty"`
MongoDBMajorVersion string `json:"mongoDBMajorVersion,omitempty"`
MongoURI string `json:"mongoURI,omitempty"`
MongoURIUpdated string `json:"mongoURIUpdated,omitempty"`
MongoURIWithOptions string `json:"mongoURIWithOptions,omitempty"`
Name string `json:"name,omitempty"`
CreateDate string `json:"createDate,omitempty"`
NumShards *int64 `json:"numShards,omitempty"`
Paused *bool `json:"paused,omitempty"`
PitEnabled *bool `json:"pitEnabled,omitempty"`
ProviderBackupEnabled *bool `json:"providerBackupEnabled,omitempty"`
ProviderSettings *ProviderSettings `json:"providerSettings,omitempty"`
ReplicationFactor *int64 `json:"replicationFactor,omitempty"`
ReplicationSpec map[string]RegionsConfig `json:"replicationSpec,omitempty"`
ReplicationSpecs []ReplicationSpec `json:"replicationSpecs,omitempty"`
SrvAddress string `json:"srvAddress,omitempty"`
StateName string `json:"stateName,omitempty"`
ServerlessBackupOptions *ServerlessBackupOptions `json:"serverlessBackupOptions,omitempty"`
ConnectionStrings *ConnectionStrings `json:"connectionStrings,omitempty"`
Links []*Link `json:"links,omitempty"`
VersionReleaseSystem string `json:"versionReleaseSystem,omitempty"`
RootCertType string `json:"rootCertType,omitempty"`
TerminationProtectionEnabled *bool `json:"terminationProtectionEnabled,omitempty"`
Tags *[]*Tag `json:"tags,omitempty"`
AcceptDataRisksAndForceReplicaSetReconfig string `json:"acceptDataRisksAndForceReplicaSetReconfig,omitempty"`
AutoScaling *AutoScaling `json:"autoScaling,omitempty"`
BackupEnabled *bool `json:"backupEnabled,omitempty"` // Deprecated: Use ProviderBackupEnabled instead
BiConnector *BiConnector `json:"biConnector,omitempty"`
ClusterType string `json:"clusterType,omitempty"`
DiskSizeGB *float64 `json:"diskSizeGB,omitempty"`
EncryptionAtRestProvider string `json:"encryptionAtRestProvider,omitempty"`
Labels []Label `json:"labels,omitempty"`
ID string `json:"id,omitempty"`
GroupID string `json:"groupId,omitempty"`
MongoDBVersion string `json:"mongoDBVersion,omitempty"`
MongoDBMajorVersion string `json:"mongoDBMajorVersion,omitempty"`
MongoURI string `json:"mongoURI,omitempty"`
MongoURIUpdated string `json:"mongoURIUpdated,omitempty"`
MongoURIWithOptions string `json:"mongoURIWithOptions,omitempty"`
Name string `json:"name,omitempty"`
CreateDate string `json:"createDate,omitempty"`
NumShards *int64 `json:"numShards,omitempty"`
Paused *bool `json:"paused,omitempty"`
PitEnabled *bool `json:"pitEnabled,omitempty"`
ProviderBackupEnabled *bool `json:"providerBackupEnabled,omitempty"`
ProviderSettings *ProviderSettings `json:"providerSettings,omitempty"`
ReplicationFactor *int64 `json:"replicationFactor,omitempty"`
ReplicationSpec map[string]RegionsConfig `json:"replicationSpec,omitempty"`
ReplicationSpecs []ReplicationSpec `json:"replicationSpecs,omitempty"`
SrvAddress string `json:"srvAddress,omitempty"`
StateName string `json:"stateName,omitempty"`
ServerlessBackupOptions *ServerlessBackupOptions `json:"serverlessBackupOptions,omitempty"`
ConnectionStrings *ConnectionStrings `json:"connectionStrings,omitempty"`
Links []*Link `json:"links,omitempty"`
VersionReleaseSystem string `json:"versionReleaseSystem,omitempty"`
RootCertType string `json:"rootCertType,omitempty"`
TerminationProtectionEnabled *bool `json:"terminationProtectionEnabled,omitempty"`
Tags *[]*Tag `json:"tags,omitempty"`
}

// ProcessArgs represents the advanced configuration options for the cluster.
Expand Down
19 changes: 17 additions & 2 deletions mongodbatlas/clusters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func TestClusters_ListClusters(t *testing.T) {
fmt.Fprint(w, `{
"results": [
{
"acceptDataRisksAndForceReplicaSetReconfig": "2017-10-23T21:26:17Z",
"autoScaling": {
"diskGBEnabled": true,
"compute": {
Expand Down Expand Up @@ -109,6 +110,7 @@ func TestClusters_ListClusters(t *testing.T) {
"tags": [ { "key": "key1", "value": "value1" } ]
},
{
"acceptDataRisksAndForceReplicaSetReconfig": "2017-10-23T21:26:17Z",
"autoScaling": {
"diskGBEnabled": true,
"compute": {
Expand Down Expand Up @@ -196,6 +198,7 @@ func TestClusters_ListClusters(t *testing.T) {
}

cluster1 := Cluster{
AcceptDataRisksAndForceReplicaSetReconfig: "2017-10-23T21:26:17Z",
AutoScaling: &AutoScaling{
DiskGBEnabled: pointer(true),
Compute: &Compute{
Expand Down Expand Up @@ -363,6 +366,7 @@ func TestClusters_Create(t *testing.T) {

createRequest := &Cluster{
ID: "1",
AcceptDataRisksAndForceReplicaSetReconfig: "2017-10-23T21:26:17Z",
AutoScaling: &AutoScaling{DiskGBEnabled: pointer(true),
Compute: &Compute{Enabled: pointer(true), ScaleDownEnabled: pointer(true)}},
BackupEnabled: pointer(true),
Expand Down Expand Up @@ -410,6 +414,7 @@ func TestClusters_Create(t *testing.T) {
mux.HandleFunc(fmt.Sprintf("/api/atlas/v1.0/groups/%s/clusters", groupID), func(w http.ResponseWriter, r *http.Request) {
expected := map[string]interface{}{
"id": "1",
"acceptDataRisksAndForceReplicaSetReconfig": "2017-10-23T21:26:17Z",
"autoScaling": map[string]interface{}{
"diskGBEnabled": true,
"compute": map[string]interface{}{
Expand Down Expand Up @@ -469,6 +474,7 @@ func TestClusters_Create(t *testing.T) {
jsonBlob := `
{
"id":"1",
"acceptDataRisksAndForceReplicaSetReconfig": "2017-10-23T21:26:17Z",
"autoScaling": {
"diskGBEnabled": true,
"compute": {
Expand Down Expand Up @@ -565,6 +571,7 @@ func TestClusters_Update(t *testing.T) {

updateRequest := &Cluster{
ID: "1",
AcceptDataRisksAndForceReplicaSetReconfig: "2017-10-23T21:26:17Z",
AutoScaling: &AutoScaling{DiskGBEnabled: pointer(true),
Compute: &Compute{Enabled: pointer(true), ScaleDownEnabled: pointer(true)}},
BackupEnabled: pointer(true),
Expand Down Expand Up @@ -605,6 +612,7 @@ func TestClusters_Update(t *testing.T) {
mux.HandleFunc(fmt.Sprintf("/api/atlas/v1.0/groups/%s/clusters/%s", groupID, clusterName), func(w http.ResponseWriter, r *http.Request) {
expected := map[string]interface{}{
"id": "1",
"acceptDataRisksAndForceReplicaSetReconfig": "2017-10-23T21:26:17Z",
"autoScaling": map[string]interface{}{
"diskGBEnabled": true,
"compute": map[string]interface{}{
Expand Down Expand Up @@ -656,6 +664,7 @@ func TestClusters_Update(t *testing.T) {

jsonBlob := `
{
"acceptDataRisksAndForceReplicaSetReconfig": "2017-10-23T21:26:17Z",
"autoScaling": {
"diskGBEnabled": true,
"compute": {
Expand Down Expand Up @@ -894,6 +903,7 @@ func TestClusters_Get(t *testing.T) {
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{
"id":"1",
"acceptDataRisksAndForceReplicaSetReconfig": "2017-10-23T21:26:17Z",
"autoScaling": {
"diskGBEnabled": true
},
Expand Down Expand Up @@ -969,7 +979,8 @@ func TestClusters_Get(t *testing.T) {
}

expected := &Cluster{
ID: "1",
ID: "1",
AcceptDataRisksAndForceReplicaSetReconfig: "2017-10-23T21:26:17Z",
AutoScaling: &AutoScaling{DiskGBEnabled: pointer(true)},
BackupEnabled: pointer(true),
BiConnector: &BiConnector{Enabled: pointer(false), ReadPreference: "secondary"},
Expand Down Expand Up @@ -1066,7 +1077,8 @@ func TestClusters_LoadSampleDataset(t *testing.T) {
"_id": "1",
"clusterName": "globalCluster",
"completeDate": null,
"createDate": "2021-03-26T16:30:47Z",
"acceptDataRisksAndForceReplicaSetReconfig": "2021-03-26T16:30:47Z",
"createDate": "2021-03-26T16:30:47Z",
"errorMessage": null,
"state": "WORKING"}`)
})
Expand Down Expand Up @@ -1333,6 +1345,7 @@ func TestClusters_Upgrade(t *testing.T) {

upgradeRequest := &Cluster{
ID: "1",
AcceptDataRisksAndForceReplicaSetReconfig: "2017-10-23T21:26:17Z",
AutoScaling: &AutoScaling{DiskGBEnabled: pointer(true),
Compute: &Compute{Enabled: pointer(true), ScaleDownEnabled: pointer(true)}},
BackupEnabled: pointer(true),
Expand Down Expand Up @@ -1373,6 +1386,7 @@ func TestClusters_Upgrade(t *testing.T) {
mux.HandleFunc(fmt.Sprintf("/api/atlas/v1.0/groups/%s/clusters/tenantUpgrade", groupID), func(w http.ResponseWriter, r *http.Request) {
expected := map[string]interface{}{
"id": "1",
"acceptDataRisksAndForceReplicaSetReconfig": "2017-10-23T21:26:17Z",
"autoScaling": map[string]interface{}{
"diskGBEnabled": true,
"compute": map[string]interface{}{
Expand Down Expand Up @@ -1424,6 +1438,7 @@ func TestClusters_Upgrade(t *testing.T) {

jsonBlob := `
{
"acceptDataRisksAndForceReplicaSetReconfig": "2017-10-23T21:26:17Z",
"autoScaling": {
"diskGBEnabled": true,
"compute": {
Expand Down
Loading