Skip to content

Commit 20369e9

Browse files
authored
feat: Added missing fields 'Links', 'CopySettings' and 'DeleteCopiedBackups' in cloud backup policies (#332)
1 parent 84f6f43 commit 20369e9

File tree

2 files changed

+200
-17
lines changed

2 files changed

+200
-17
lines changed

mongodbatlas/cloud_provider_snapshot_backup_policies.go

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,20 @@ var _ CloudProviderSnapshotBackupPoliciesService = &CloudProviderSnapshotBackupP
4242

4343
// CloudProviderSnapshotBackupPolicy represents a cloud provider snapshot schedule.
4444
type CloudProviderSnapshotBackupPolicy struct {
45-
ClusterID string `json:"clusterId,omitempty"` // Unique identifier of the Atlas cluster.
46-
ClusterName string `json:"clusterName,omitempty"` // Name of the Atlas cluster.
47-
ReferenceHourOfDay *int64 `json:"referenceHourOfDay,omitempty"` // UTC Hour of day between 0 and 23, inclusive, representing which hour of the day that Atlas takes snapshots for backup policy items.
48-
ReferenceMinuteOfHour *int64 `json:"referenceMinuteOfHour,omitempty"` // UTC Minutes after referenceHourOfDay that Atlas takes snapshots for backup policy items. Must be between 0 and 59, inclusive. Number of days back in time you can restore to with point-in-time accuracy.
49-
RestoreWindowDays *int64 `json:"restoreWindowDays,omitempty"` // Number of days back in time you can restore to with point-in-time accuracy. Must be a positive, non-zero integer.
50-
UpdateSnapshots *bool `json:"updateSnapshots,omitempty"` // Specify true to apply the retention changes in the updated backup policy to snapshots that Atlas took previously.
51-
NextSnapshot string `json:"nextSnapshot,omitempty"` // UTC ISO 8601 formatted point in time when Atlas will take the next snapshot.
52-
Policies []Policy `json:"policies,omitempty"` // A list of policy definitions for the cluster.
53-
AutoExportEnabled *bool `json:"autoExportEnabled,omitempty"` // Specify true to enable automatic export of cloud backup snapshots to the AWS bucket. You must also define the export policy using export. Specify false to disable automatic export.
54-
Export *Export `json:"export,omitempty"` // Export struct that represents a policy for automatically exporting cloud backup snapshots to AWS bucket.
55-
UseOrgAndGroupNamesInExportPrefix *bool `json:"useOrgAndGroupNamesInExportPrefix,omitempty"` // Specifies whether to use organization and project names instead of organization and project UUIDs in the path to the metadata files that Atlas uploads to your S3 bucket after it finishes exporting the snapshots
45+
ClusterID string `json:"clusterId,omitempty"` // Unique identifier of the Atlas cluster.
46+
ClusterName string `json:"clusterName,omitempty"` // Name of the Atlas cluster.
47+
ReferenceHourOfDay *int64 `json:"referenceHourOfDay,omitempty"` // UTC Hour of day between 0 and 23, inclusive, representing which hour of the day that Atlas takes snapshots for backup policy items.
48+
ReferenceMinuteOfHour *int64 `json:"referenceMinuteOfHour,omitempty"` // UTC Minutes after referenceHourOfDay that Atlas takes snapshots for backup policy items. Must be between 0 and 59, inclusive. Number of days back in time you can restore to with point-in-time accuracy.
49+
RestoreWindowDays *int64 `json:"restoreWindowDays,omitempty"` // Number of days back in time you can restore to with point-in-time accuracy. Must be a positive, non-zero integer.
50+
UpdateSnapshots *bool `json:"updateSnapshots,omitempty"` // Specify true to apply the retention changes in the updated backup policy to snapshots that Atlas took previously.
51+
NextSnapshot string `json:"nextSnapshot,omitempty"` // UTC ISO 8601 formatted point in time when Atlas will take the next snapshot.
52+
Policies []Policy `json:"policies,omitempty"` // A list of policy definitions for the cluster.
53+
AutoExportEnabled *bool `json:"autoExportEnabled,omitempty"` // Specify true to enable automatic export of cloud backup snapshots to the AWS bucket. You must also define the export policy using export. Specify false to disable automatic export.
54+
Export *Export `json:"export,omitempty"` // Export struct that represents a policy for automatically exporting cloud backup snapshots to AWS bucket.
55+
UseOrgAndGroupNamesInExportPrefix *bool `json:"useOrgAndGroupNamesInExportPrefix,omitempty"` // Specifies whether to use organization and project names instead of organization and project UUIDs in the path to the metadata files that Atlas uploads to your S3 bucket after it finishes exporting the snapshots
56+
Links []*Link `json:"links,omitempty"` // One or more links to sub-resources and/or related resources.
57+
CopySettings []CopySetting `json:"copySettings,omitempty"` // List that contains a document for each copy setting item in the desired backup policy.
58+
DeleteCopiedBackups []DeleteCopiedBackup `json:"deleteCopiedBackups,omitempty"` // List that contains a document for each deleted copy setting whose backup copies you want to delete.
5659
}
5760

5861
// Policy represents for the snapshot and an array of backup policy items.
@@ -76,6 +79,22 @@ type Export struct {
7679
FrequencyType string `json:"frequencyType,omitempty"` // Frequency associated with the export policy.
7780
}
7881

82+
// CopySetting is autogenerated from the json schema.
83+
type CopySetting struct {
84+
CloudProvider *string `json:"cloudProvider,omitempty"` // Identifies the cloud provider that stores the snapshot copy.
85+
RegionName *string `json:"regionName,omitempty"` // Target region to copy snapshots belonging to replicationSpecId to.
86+
ReplicationSpecID *string `json:"replicationSpecId,omitempty"` // Unique identifier that identifies the replication object for a zone in a cluster.
87+
ShouldCopyOplogs *bool `json:"shouldCopyOplogs,omitempty"` // Flag that indicates whether to copy the oplogs to the target region.
88+
Frequencies []string `json:"frequencies,omitempty"` // List that describes which types of snapshots to copy.
89+
}
90+
91+
// DeleteCopiedBackup is autogenerated from the json schema.
92+
type DeleteCopiedBackup struct {
93+
CloudProvider *string `json:"cloudProvider,omitempty"` // Identifies the cloud provider that stores the snapshot copy.
94+
RegionName *string `json:"regionName,omitempty"` // Target region to copy snapshots belonging to replicationSpecId to.
95+
ReplicationSpecID *string `json:"replicationSpecId,omitempty"` // Unique identifier that identifies the replication object for a zone in a cluster.
96+
}
97+
7998
// Get gets the current snapshot schedule and retention settings for the cluster with {CLUSTER-NAME}.
8099
// See more: https://docs.atlas.mongodb.com/reference/api/cloud-provider-snapshot-schedule-get-all/
81100
func (s *CloudProviderSnapshotBackupPoliciesServiceOp) Get(ctx context.Context, groupID, clusterName string) (*CloudProviderSnapshotBackupPolicy, *Response, error) {
@@ -99,6 +118,10 @@ func (s *CloudProviderSnapshotBackupPoliciesServiceOp) Get(ctx context.Context,
99118
return nil, resp, err
100119
}
101120

121+
if l := root.Links; l != nil {
122+
resp.Links = l
123+
}
124+
102125
return root, resp, err
103126
}
104127

@@ -128,6 +151,10 @@ func (s *CloudProviderSnapshotBackupPoliciesServiceOp) Update(ctx context.Contex
128151
return nil, resp, err
129152
}
130153

154+
if l := root.Links; l != nil {
155+
resp.Links = l
156+
}
157+
131158
return root, resp, err
132159
}
133160

mongodbatlas/cloud_provider_snapshot_backup_policies_test.go

Lines changed: 162 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,39 @@ func TestCloudProviderSnapshotBackupPolicies_Get(t *testing.T) {
3131
groupID := "5b6212af90dc76637950a2c6"
3232
clusterName := "myCluster"
3333

34+
var aws = "AWS"
35+
var regionName = "testRegion"
36+
var replicationSpecID = "5e2f1bcaf38990fab9227c9"
37+
var shouldCopyOplogs = true
38+
var frequencies = []string{
39+
"HOURLY",
40+
}
41+
var copySettings = CopySetting{
42+
CloudProvider: &aws,
43+
RegionName: &regionName,
44+
ReplicationSpecID: &replicationSpecID,
45+
ShouldCopyOplogs: &shouldCopyOplogs,
46+
Frequencies: frequencies,
47+
}
48+
3449
path := fmt.Sprintf("/api/atlas/v1.0/groups/%s/clusters/%s/backup/schedule", groupID, clusterName)
3550

3651
mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
3752
testMethod(t, r, http.MethodGet)
3853
fmt.Fprint(w, `{
3954
"clusterId": "5e2f1bcaf38990fab9227b8",
4055
"clusterName": "myCluster",
56+
"copySettings": [
57+
{
58+
"cloudProvider": "AWS",
59+
"frequencies": [
60+
"HOURLY"
61+
],
62+
"regionName": "testRegion",
63+
"replicationSpecId": "5e2f1bcaf38990fab9227c9",
64+
"shouldCopyOplogs": true
65+
}
66+
],
4167
"links": [
4268
{
4369
"href": "https://cloud.mongodb.com/api/atlas/v1.0/groups/5dd5a6a472efab1d71a58495/clusters/myCluster/backup/schedule",
@@ -102,8 +128,21 @@ func TestCloudProviderSnapshotBackupPolicies_Get(t *testing.T) {
102128
}
103129

104130
expected := &CloudProviderSnapshotBackupPolicy{
105-
ClusterID: "5e2f1bcaf38990fab9227b8",
106-
ClusterName: "myCluster",
131+
ClusterID: "5e2f1bcaf38990fab9227b8",
132+
ClusterName: "myCluster",
133+
CopySettings: []CopySetting{
134+
copySettings,
135+
},
136+
Links: []*Link{
137+
{
138+
Href: "https://cloud.mongodb.com/api/atlas/v1.0/groups/5dd5a6a472efab1d71a58495/clusters/myCluster/backup/schedule",
139+
Rel: "self",
140+
},
141+
{
142+
Href: "https://cloud.mongodb.com/api/public/v1.0/groups/5dd5a6a472efab1d71a58495",
143+
Rel: "http://mms.mongodb.com/group",
144+
},
145+
},
107146
NextSnapshot: "2020-01-28T05:24:25Z",
108147
Policies: []Policy{
109148
{
@@ -163,6 +202,26 @@ func TestCloudProviderSnapshotBackupPolicies_Update(t *testing.T) {
163202
groupID := "5b6212af90dc76637950a2c6"
164203
clusterName := "myCluster"
165204

205+
var aws = "AWS"
206+
var regionName = "testRegion"
207+
var replicationSpecID = "5e2f1bcaf38990fab9227c9"
208+
var shouldCopyOplogs = true
209+
var frequencies = []string{
210+
"HOURLY",
211+
}
212+
var copySettings = CopySetting{
213+
CloudProvider: &aws,
214+
RegionName: &regionName,
215+
ReplicationSpecID: &replicationSpecID,
216+
ShouldCopyOplogs: &shouldCopyOplogs,
217+
Frequencies: frequencies,
218+
}
219+
var deleteCopiedBackup = DeleteCopiedBackup{
220+
CloudProvider: &aws,
221+
RegionName: &regionName,
222+
ReplicationSpecID: &replicationSpecID,
223+
}
224+
166225
path := fmt.Sprintf("/api/atlas/v1.0/groups/%s/clusters/%s/backup/schedule", groupID, clusterName)
167226

168227
mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
@@ -196,6 +255,24 @@ func TestCloudProviderSnapshotBackupPolicies_Update(t *testing.T) {
196255
"frequencyType": "monthly",
197256
"exportBucketId": "604f6322dc786a5341d4f7fb",
198257
},
258+
"copySettings": []interface{}{
259+
map[string]interface{}{
260+
"cloudProvider": "AWS",
261+
"frequencies": []interface{}{
262+
"HOURLY",
263+
},
264+
"regionName": "testRegion",
265+
"replicationSpecId": "5e2f1bcaf38990fab9227c9",
266+
"shouldCopyOplogs": true,
267+
},
268+
},
269+
"deleteCopiedBackups": []interface{}{
270+
map[string]interface{}{
271+
"cloudProvider": "AWS",
272+
"regionName": "testRegion",
273+
"replicationSpecId": "5e2f1bcaf38990fab9227c9",
274+
},
275+
},
199276
}
200277

201278
var v map[string]interface{}
@@ -211,6 +288,24 @@ func TestCloudProviderSnapshotBackupPolicies_Update(t *testing.T) {
211288
fmt.Fprint(w, `{
212289
"clusterId": "5c94f6ea80eef5617167224d",
213290
"clusterName": "Cluster0",
291+
"copySettings": [
292+
{
293+
"cloudProvider": "AWS",
294+
"frequencies": [
295+
"HOURLY"
296+
],
297+
"regionName": "testRegion",
298+
"replicationSpecId": "5e2f1bcaf38990fab9227c9",
299+
"shouldCopyOplogs": true
300+
}
301+
],
302+
"deleteCopiedBackups": [
303+
{
304+
"cloudProvider": "AWS",
305+
"regionName": "testRegion",
306+
"replicationSpecId": "5e2f1bcaf38990fab9227c9"
307+
}
308+
],
214309
"links": [
215310
{
216311
"href": "https://cloud.mongodb.com/api/atlas/v1.0/groups/5b6212af90dc76637950a2c6/clusters/Cluster0/backup/schedule",
@@ -283,6 +378,12 @@ func TestCloudProviderSnapshotBackupPolicies_Update(t *testing.T) {
283378
ExportBucketID: "604f6322dc786a5341d4f7fb",
284379
FrequencyType: "monthly",
285380
},
381+
CopySettings: []CopySetting{
382+
copySettings,
383+
},
384+
DeleteCopiedBackups: []DeleteCopiedBackup{
385+
deleteCopiedBackup,
386+
},
286387
}
287388

288389
cloudProviderSnapshot, _, err := client.CloudProviderSnapshotBackupPolicies.Update(ctx, groupID, clusterName, updateRequest)
@@ -291,8 +392,18 @@ func TestCloudProviderSnapshotBackupPolicies_Update(t *testing.T) {
291392
}
292393

293394
expected := &CloudProviderSnapshotBackupPolicy{
294-
ClusterID: "5c94f6ea80eef5617167224d",
295-
ClusterName: "Cluster0",
395+
ClusterID: "5c94f6ea80eef5617167224d",
396+
ClusterName: "Cluster0",
397+
Links: []*Link{
398+
{
399+
Href: "https://cloud.mongodb.com/api/atlas/v1.0/groups/5b6212af90dc76637950a2c6/clusters/Cluster0/backup/schedule",
400+
Rel: "self",
401+
},
402+
{
403+
Href: "https://cloud.mongodb.com/api/atlas/v1.0/groups/5b6212af90dc76637950a2c6",
404+
Rel: "http://mms.mongodb.com/group",
405+
},
406+
},
296407
NextSnapshot: "2019-04-03T18:30:08Z",
297408
Policies: []Policy{
298409
{
@@ -322,6 +433,12 @@ func TestCloudProviderSnapshotBackupPolicies_Update(t *testing.T) {
322433
ExportBucketID: "604f6322dc786a5341d4f7fb",
323434
FrequencyType: "monthly",
324435
},
436+
CopySettings: []CopySetting{
437+
copySettings,
438+
},
439+
DeleteCopiedBackups: []DeleteCopiedBackup{
440+
deleteCopiedBackup,
441+
},
325442
}
326443

327444
if diff := deep.Equal(cloudProviderSnapshot, expected); diff != nil {
@@ -336,6 +453,21 @@ func TestCloudProviderSnapshotBackupPolicies_Delete(t *testing.T) {
336453
groupID := "5b6212af90dc76637950a2c6"
337454
clusterName := "myCluster"
338455

456+
var aws = "AWS"
457+
var regionName = "testRegion"
458+
var replicationSpecID = "5e2f1bcaf38990fab9227c9"
459+
var shouldCopyOplogs = true
460+
var frequencies = []string{
461+
"HOURLY",
462+
}
463+
var copySettings = CopySetting{
464+
CloudProvider: &aws,
465+
RegionName: &regionName,
466+
ReplicationSpecID: &replicationSpecID,
467+
ShouldCopyOplogs: &shouldCopyOplogs,
468+
Frequencies: frequencies,
469+
}
470+
339471
path := fmt.Sprintf("/api/atlas/v1.0/groups/%s/clusters/%s/backup/schedule", groupID, clusterName)
340472

341473
mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
@@ -344,6 +476,17 @@ func TestCloudProviderSnapshotBackupPolicies_Delete(t *testing.T) {
344476
fmt.Fprint(w, `{
345477
"clusterId": "5e2f1bcaf38990fab9227b8",
346478
"clusterName": "myCluster",
479+
"copySettings": [
480+
{
481+
"cloudProvider": "AWS",
482+
"frequencies": [
483+
"HOURLY"
484+
],
485+
"regionName": "testRegion",
486+
"replicationSpecID": "5e2f1bcaf38990fab9227c9",
487+
"shouldCopyOplogs": true
488+
}
489+
],
347490
"links": [
348491
{
349492
"href": "https://cloud.mongodb.com/api/atlas/v1.0/groups/5dd5a6a472efab1d71a58495/clusters/myCluster/backup/schedule",
@@ -378,8 +521,18 @@ func TestCloudProviderSnapshotBackupPolicies_Delete(t *testing.T) {
378521
}
379522

380523
expected := &CloudProviderSnapshotBackupPolicy{
381-
ClusterID: "5e2f1bcaf38990fab9227b8",
382-
ClusterName: "myCluster",
524+
ClusterID: "5e2f1bcaf38990fab9227b8",
525+
ClusterName: "myCluster",
526+
Links: []*Link{
527+
{
528+
Href: "https://cloud.mongodb.com/api/atlas/v1.0/groups/5dd5a6a472efab1d71a58495/clusters/myCluster/backup/schedule",
529+
Rel: "self",
530+
},
531+
{
532+
Href: "https://cloud.mongodb.com/api/public/v1.0/groups/5dd5a6a472efab1d71a58495",
533+
Rel: "http://mms.mongodb.com/group",
534+
},
535+
},
383536
NextSnapshot: "2020-01-28T05:24:25Z",
384537
Policies: []Policy{
385538
{
@@ -395,6 +548,9 @@ func TestCloudProviderSnapshotBackupPolicies_Delete(t *testing.T) {
395548
ExportBucketID: "604f6322dc786a5341d4f7fb",
396549
FrequencyType: "monthly",
397550
},
551+
CopySettings: []CopySetting{
552+
copySettings,
553+
},
398554
}
399555

400556
if diff := deep.Equal(cloudProviderSnapshot, expected); diff != nil {

0 commit comments

Comments
 (0)