Skip to content

Commit f9f8ebe

Browse files
authored
INTMDB-444 Add support for terminationProtectionEnabled flag (#325)
1 parent 3be2b2e commit f9f8ebe

File tree

6 files changed

+101
-88
lines changed

6 files changed

+101
-88
lines changed

mongodbatlas/advanced_clusters.go

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,25 +43,26 @@ var _ AdvancedClustersService = &AdvancedClustersServiceOp{}
4343

4444
// AdvancedCluster represents MongoDB cluster.
4545
type AdvancedCluster struct {
46-
BackupEnabled *bool `json:"backupEnabled,omitempty"`
47-
BiConnector *BiConnector `json:"biConnector,omitempty"`
48-
ClusterType string `json:"clusterType,omitempty"`
49-
ConnectionStrings *ConnectionStrings `json:"connectionStrings,omitempty"`
50-
DiskSizeGB *float64 `json:"diskSizeGB,omitempty"`
51-
EncryptionAtRestProvider string `json:"encryptionAtRestProvider,omitempty"`
52-
GroupID string `json:"groupId,omitempty"`
53-
ID string `json:"id,omitempty"`
54-
Labels []Label `json:"labels,omitempty"`
55-
MongoDBMajorVersion string `json:"mongoDBMajorVersion,omitempty"`
56-
MongoDBVersion string `json:"mongoDBVersion,omitempty"`
57-
Name string `json:"name,omitempty"`
58-
Paused *bool `json:"paused,omitempty"`
59-
PitEnabled *bool `json:"pitEnabled,omitempty"`
60-
StateName string `json:"stateName,omitempty"`
61-
ReplicationSpecs []*AdvancedReplicationSpec `json:"replicationSpecs,omitempty"`
62-
CreateDate string `json:"createDate,omitempty"`
63-
RootCertType string `json:"rootCertType,omitempty"`
64-
VersionReleaseSystem string `json:"versionReleaseSystem,omitempty"`
46+
BackupEnabled *bool `json:"backupEnabled,omitempty"`
47+
BiConnector *BiConnector `json:"biConnector,omitempty"`
48+
ClusterType string `json:"clusterType,omitempty"`
49+
ConnectionStrings *ConnectionStrings `json:"connectionStrings,omitempty"`
50+
DiskSizeGB *float64 `json:"diskSizeGB,omitempty"`
51+
EncryptionAtRestProvider string `json:"encryptionAtRestProvider,omitempty"`
52+
GroupID string `json:"groupId,omitempty"`
53+
ID string `json:"id,omitempty"`
54+
Labels []Label `json:"labels,omitempty"`
55+
MongoDBMajorVersion string `json:"mongoDBMajorVersion,omitempty"`
56+
MongoDBVersion string `json:"mongoDBVersion,omitempty"`
57+
Name string `json:"name,omitempty"`
58+
Paused *bool `json:"paused,omitempty"`
59+
PitEnabled *bool `json:"pitEnabled,omitempty"`
60+
StateName string `json:"stateName,omitempty"`
61+
ReplicationSpecs []*AdvancedReplicationSpec `json:"replicationSpecs,omitempty"`
62+
CreateDate string `json:"createDate,omitempty"`
63+
RootCertType string `json:"rootCertType,omitempty"`
64+
VersionReleaseSystem string `json:"versionReleaseSystem,omitempty"`
65+
TerminationProtectionEnabled *bool `json:"terminationProtectionEnabled,omitempty"`
6566
}
6667

6768
type AdvancedReplicationSpec struct {

mongodbatlas/advanced_clusters_test.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ func TestAdvancedClusters_Get(t *testing.T) {
491491
],
492492
"rootCertType": "DST",
493493
"stateName": "CREATING",
494+
"terminationProtectionEnabled": false,
494495
"versionReleaseSystem": "LTS"
495496
496497
}`)
@@ -516,18 +517,19 @@ func TestAdvancedClusters_Get(t *testing.T) {
516517
Enabled: &enabled,
517518
ReadPreference: "secondary",
518519
},
519-
ClusterType: "GEOSHARDED",
520-
DiskSizeGB: &diskSizeGBGeoSharded,
521-
EncryptionAtRestProvider: "NONE",
522-
GroupID: "2",
523-
ID: "2",
524-
MongoDBMajorVersion: "4.4",
525-
MongoDBVersion: "4.4.4",
526-
Name: clusterName,
527-
Paused: &paused,
528-
PitEnabled: &pitEnabled,
529-
StateName: "CREATING",
530-
VersionReleaseSystem: "LTS",
520+
ClusterType: "GEOSHARDED",
521+
DiskSizeGB: &diskSizeGBGeoSharded,
522+
EncryptionAtRestProvider: "NONE",
523+
GroupID: "2",
524+
ID: "2",
525+
MongoDBMajorVersion: "4.4",
526+
MongoDBVersion: "4.4.4",
527+
Name: clusterName,
528+
Paused: &paused,
529+
PitEnabled: &pitEnabled,
530+
StateName: "CREATING",
531+
TerminationProtectionEnabled: pointy.Bool(false),
532+
VersionReleaseSystem: "LTS",
531533
ReplicationSpecs: []*AdvancedReplicationSpec{
532534
{
533535
ID: "2",

mongodbatlas/clusters.go

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -139,37 +139,38 @@ type ConnectionStrings struct {
139139

140140
// Cluster represents MongoDB cluster.
141141
type Cluster struct {
142-
AutoScaling *AutoScaling `json:"autoScaling,omitempty"`
143-
BackupEnabled *bool `json:"backupEnabled,omitempty"` // Deprecated: Use ProviderBackupEnabled instead
144-
BiConnector *BiConnector `json:"biConnector,omitempty"`
145-
ClusterType string `json:"clusterType,omitempty"`
146-
DiskSizeGB *float64 `json:"diskSizeGB,omitempty"`
147-
EncryptionAtRestProvider string `json:"encryptionAtRestProvider,omitempty"`
148-
Labels []Label `json:"labels,omitempty"`
149-
ID string `json:"id,omitempty"`
150-
GroupID string `json:"groupId,omitempty"`
151-
MongoDBVersion string `json:"mongoDBVersion,omitempty"`
152-
MongoDBMajorVersion string `json:"mongoDBMajorVersion,omitempty"`
153-
MongoURI string `json:"mongoURI,omitempty"`
154-
MongoURIUpdated string `json:"mongoURIUpdated,omitempty"`
155-
MongoURIWithOptions string `json:"mongoURIWithOptions,omitempty"`
156-
Name string `json:"name,omitempty"`
157-
CreateDate string `json:"createDate,omitempty"`
158-
NumShards *int64 `json:"numShards,omitempty"`
159-
Paused *bool `json:"paused,omitempty"`
160-
PitEnabled *bool `json:"pitEnabled,omitempty"`
161-
ProviderBackupEnabled *bool `json:"providerBackupEnabled,omitempty"`
162-
ProviderSettings *ProviderSettings `json:"providerSettings,omitempty"`
163-
ReplicationFactor *int64 `json:"replicationFactor,omitempty"`
164-
ReplicationSpec map[string]RegionsConfig `json:"replicationSpec,omitempty"`
165-
ReplicationSpecs []ReplicationSpec `json:"replicationSpecs,omitempty"`
166-
SrvAddress string `json:"srvAddress,omitempty"`
167-
StateName string `json:"stateName,omitempty"`
168-
ServerlessBackupOptions *ServerlessBackupOptions `json:"serverlessBackupOptions,omitempty"`
169-
ConnectionStrings *ConnectionStrings `json:"connectionStrings,omitempty"`
170-
Links []*Link `json:"links,omitempty"`
171-
VersionReleaseSystem string `json:"versionReleaseSystem,omitempty"`
172-
RootCertType string `json:"rootCertType,omitempty"`
142+
AutoScaling *AutoScaling `json:"autoScaling,omitempty"`
143+
BackupEnabled *bool `json:"backupEnabled,omitempty"` // Deprecated: Use ProviderBackupEnabled instead
144+
BiConnector *BiConnector `json:"biConnector,omitempty"`
145+
ClusterType string `json:"clusterType,omitempty"`
146+
DiskSizeGB *float64 `json:"diskSizeGB,omitempty"`
147+
EncryptionAtRestProvider string `json:"encryptionAtRestProvider,omitempty"`
148+
Labels []Label `json:"labels,omitempty"`
149+
ID string `json:"id,omitempty"`
150+
GroupID string `json:"groupId,omitempty"`
151+
MongoDBVersion string `json:"mongoDBVersion,omitempty"`
152+
MongoDBMajorVersion string `json:"mongoDBMajorVersion,omitempty"`
153+
MongoURI string `json:"mongoURI,omitempty"`
154+
MongoURIUpdated string `json:"mongoURIUpdated,omitempty"`
155+
MongoURIWithOptions string `json:"mongoURIWithOptions,omitempty"`
156+
Name string `json:"name,omitempty"`
157+
CreateDate string `json:"createDate,omitempty"`
158+
NumShards *int64 `json:"numShards,omitempty"`
159+
Paused *bool `json:"paused,omitempty"`
160+
PitEnabled *bool `json:"pitEnabled,omitempty"`
161+
ProviderBackupEnabled *bool `json:"providerBackupEnabled,omitempty"`
162+
ProviderSettings *ProviderSettings `json:"providerSettings,omitempty"`
163+
ReplicationFactor *int64 `json:"replicationFactor,omitempty"`
164+
ReplicationSpec map[string]RegionsConfig `json:"replicationSpec,omitempty"`
165+
ReplicationSpecs []ReplicationSpec `json:"replicationSpecs,omitempty"`
166+
SrvAddress string `json:"srvAddress,omitempty"`
167+
StateName string `json:"stateName,omitempty"`
168+
ServerlessBackupOptions *ServerlessBackupOptions `json:"serverlessBackupOptions,omitempty"`
169+
ConnectionStrings *ConnectionStrings `json:"connectionStrings,omitempty"`
170+
Links []*Link `json:"links,omitempty"`
171+
VersionReleaseSystem string `json:"versionReleaseSystem,omitempty"`
172+
RootCertType string `json:"rootCertType,omitempty"`
173+
TerminationProtectionEnabled *bool `json:"terminationProtectionEnabled,omitempty"`
173174
}
174175

175176
// ProcessArgs represents the advanced configuration options for the cluster.

mongodbatlas/clusters_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,7 @@ func TestClusters_Get(t *testing.T) {
932932
},
933933
"srvAddress": "mongodb+srv://mongo-shard-00-00.mongodb.net:27017,mongo-shard-00-01.mongodb.net:27017,mongo-shard-00-02.mongodb.net:27017",
934934
"stateName": "IDLE",
935+
"terminationProtectionEnabled": false,
935936
"versionReleaseSystem": "LTS"
936937
}`)
937938
})
@@ -996,9 +997,10 @@ func TestClusters_Get(t *testing.T) {
996997
ReadOnlyNodes: pointy.Int64(0),
997998
},
998999
},
999-
SrvAddress: "mongodb+srv://mongo-shard-00-00.mongodb.net:27017,mongo-shard-00-01.mongodb.net:27017,mongo-shard-00-02.mongodb.net:27017",
1000-
StateName: "IDLE",
1001-
VersionReleaseSystem: "LTS",
1000+
SrvAddress: "mongodb+srv://mongo-shard-00-00.mongodb.net:27017,mongo-shard-00-01.mongodb.net:27017,mongo-shard-00-02.mongodb.net:27017",
1001+
StateName: "IDLE",
1002+
TerminationProtectionEnabled: pointy.Bool(false),
1003+
VersionReleaseSystem: "LTS",
10021004
}
10031005

10041006
if diff := deep.Equal(cluster, expected); diff != nil {

mongodbatlas/serverless_instances.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,15 @@ type ClustersResponse struct {
4747

4848
// ServerlessCreateRequestParams represents the Request Body Parameters of ServerlessInstancesService.Create.
4949
type ServerlessCreateRequestParams struct {
50-
Name string `json:"name,omitempty"`
51-
ProviderSettings *ServerlessProviderSettings `json:"providerSettings,omitempty"`
52-
ServerlessBackupOptions *ServerlessBackupOptions `json:"serverlessBackupOptions,omitempty"`
50+
Name string `json:"name,omitempty"`
51+
ProviderSettings *ServerlessProviderSettings `json:"providerSettings,omitempty"`
52+
ServerlessBackupOptions *ServerlessBackupOptions `json:"serverlessBackupOptions,omitempty"`
53+
TerminationProtectionEnabled *bool `json:"terminationProtectionEnabled,omitempty"`
5354
}
5455

5556
type ServerlessUpdateRequestParams struct {
56-
ServerlessBackupOptions *ServerlessBackupOptions `json:"serverlessBackupOptions"`
57+
ServerlessBackupOptions *ServerlessBackupOptions `json:"serverlessBackupOptions"`
58+
TerminationProtectionEnabled *bool `json:"terminationProtectionEnabled,omitempty"`
5759
}
5860

5961
// ServerlessProviderSettings represents the Provider Settings of serverless instances.

mongodbatlas/serverless_instances_test.go

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ func TestServerlessInstances_Get(t *testing.T) {
162162
"backingProviderName": "AWS",
163163
"regionName": "US_EAST_1"
164164
},
165+
"terminationProtectionEnabled": false,
165166
"stateName": "IDLE"
166167
}`)
167168
})
@@ -172,14 +173,15 @@ func TestServerlessInstances_Get(t *testing.T) {
172173
}
173174

174175
expected := &Cluster{
175-
ID: id,
176-
GroupID: projectID,
177-
MongoDBVersion: "5.0.0",
178-
Name: "test1",
179-
ProviderSettings: &ProviderSettings{RegionName: "US_EAST_1", BackingProviderName: "AWS", ProviderName: "SERVERLESS"},
180-
StateName: "IDLE",
181-
ConnectionStrings: &ConnectionStrings{StandardSrv: "mongodb+srv://instance1.example.com"},
182-
CreateDate: "2021-06-25T21:32:06Z",
176+
ID: id,
177+
GroupID: projectID,
178+
MongoDBVersion: "5.0.0",
179+
Name: "test1",
180+
ProviderSettings: &ProviderSettings{RegionName: "US_EAST_1", BackingProviderName: "AWS", ProviderName: "SERVERLESS"},
181+
StateName: "IDLE",
182+
TerminationProtectionEnabled: pointy.Bool(false),
183+
ConnectionStrings: &ConnectionStrings{StandardSrv: "mongodb+srv://instance1.example.com"},
184+
CreateDate: "2021-06-25T21:32:06Z",
183185
Links: []*Link{
184186
{
185187
Rel: "self",
@@ -286,12 +288,14 @@ func TestServerlessInstances_Update(t *testing.T) {
286288
"serverlessBackupOptions" : {
287289
"serverlessContinuousBackupEnabled" : true
288290
},
289-
"stateName" : "IDLE"
291+
"stateName" : "IDLE",
292+
"terminationProtectionEnabled": true
290293
}`)
291294
})
292295

293296
bodyParam := &ServerlessUpdateRequestParams{
294-
ServerlessBackupOptions: &ServerlessBackupOptions{ServerlessContinuousBackupEnabled: pointy.Bool(true)},
297+
ServerlessBackupOptions: &ServerlessBackupOptions{ServerlessContinuousBackupEnabled: pointy.Bool(true)},
298+
TerminationProtectionEnabled: pointy.Bool(true),
295299
}
296300

297301
serverlessInstance, _, err := client.ServerlessInstances.Update(ctx, projectID, "sample", bodyParam)
@@ -300,15 +304,16 @@ func TestServerlessInstances_Update(t *testing.T) {
300304
}
301305

302306
expected := &Cluster{
303-
ID: id,
304-
GroupID: projectID,
305-
MongoDBVersion: "5.0.0",
306-
Name: "sample",
307-
ProviderSettings: &ProviderSettings{RegionName: "US_EAST_1", BackingProviderName: "AWS", ProviderName: "SERVERLESS"},
308-
StateName: "IDLE",
309-
ConnectionStrings: &ConnectionStrings{StandardSrv: "mongodb+srv://instanceName1.example.com"},
310-
CreateDate: "2021-06-25T21:31:10Z",
311-
ServerlessBackupOptions: &ServerlessBackupOptions{ServerlessContinuousBackupEnabled: pointy.Bool(true)},
307+
ID: id,
308+
GroupID: projectID,
309+
MongoDBVersion: "5.0.0",
310+
Name: "sample",
311+
ProviderSettings: &ProviderSettings{RegionName: "US_EAST_1", BackingProviderName: "AWS", ProviderName: "SERVERLESS"},
312+
StateName: "IDLE",
313+
ConnectionStrings: &ConnectionStrings{StandardSrv: "mongodb+srv://instanceName1.example.com"},
314+
CreateDate: "2021-06-25T21:31:10Z",
315+
ServerlessBackupOptions: &ServerlessBackupOptions{ServerlessContinuousBackupEnabled: pointy.Bool(true)},
316+
TerminationProtectionEnabled: pointy.Bool(true),
312317
Links: []*Link{
313318
{
314319
Rel: "self",

0 commit comments

Comments
 (0)