From 2d627d832abf536a1ba1fa643d4ca733b373059d Mon Sep 17 00:00:00 2001 From: Ashlie Martinez Date: Wed, 4 Oct 2023 13:30:53 -0700 Subject: [PATCH] Rename variable holding protected resource info Rename backup model variables that holds the protected resource ID and name. The variable name has changed from ResourceOwner[ID|Name] to ProtectedResource[ID|Name]. The previous version of the variable in the model of the form ProtectedResourceX wasn't getting populated and never had any data persisted for it even though other code sometimes relied on it having a value. The current update ** DOES NOT ** change the JSON tag associated with the renamed variable. This means that golang's stdlib JSON serialization with continue to use the old name. Thus there's no need for additional code to handle previously serialized backup models. --- src/pkg/backup/backup.go | 20 ++++++++------------ src/pkg/backup/backup_test.go | 11 +++-------- 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/src/pkg/backup/backup.go b/src/pkg/backup/backup.go index fe741d798..b061d2988 100644 --- a/src/pkg/backup/backup.go +++ b/src/pkg/backup/backup.go @@ -36,10 +36,12 @@ type Backup struct { // Selector used in this operation Selector selectors.Selector `json:"selectors"` - // TODO: in process of gaining support, most cases will still use - // ResourceOwner and ResourceOwnerName. - ProtectedResourceID string `json:"protectedResourceID,omitempty"` - ProtectedResourceName string `json:"protectedResourceName,omitempty"` + // ** DO NOT CHANGE JSON TAG NAMES ** + // These are in-memory only variable renames of previously persisted fields. + // ** CHANGING THE JSON TAGS WILL BREAK THINGS BECAUSE THE MODEL WON'T ** + // ** DESERIALIZE PROPERLY ** + ProtectedResourceID string `json:"resourceOwnerID,omitempty"` + ProtectedResourceName string `json:"resourceOwnerName,omitempty"` // Version represents the version of the backup format Version int `json:"version"` @@ -61,10 +63,6 @@ type Backup struct { // Reference to the backup details storage location. // Used to read backup.Details from the streamstore. DetailsID string `json:"detailsID"` - - // prefer protectedResource - ResourceOwnerID string `json:"resourceOwnerID,omitempty"` - ResourceOwnerName string `json:"resourceOwnerName,omitempty"` } // interface compliance checks @@ -115,8 +113,8 @@ func New( Tags: tags, }, - ResourceOwnerID: ownerID, - ResourceOwnerName: ownerName, + ProtectedResourceID: ownerID, + ProtectedResourceName: ownerName, Version: version, SnapshotID: snapshotID, @@ -253,9 +251,7 @@ func (b Backup) Values() []string { name := str.First( b.ProtectedResourceName, - b.ResourceOwnerName, b.ProtectedResourceID, - b.ResourceOwnerID, b.Selector.Name()) bs := b.toStats() diff --git a/src/pkg/backup/backup_test.go b/src/pkg/backup/backup_test.go index c1ce6f1cf..27324cfd8 100644 --- a/src/pkg/backup/backup_test.go +++ b/src/pkg/backup/backup_test.go @@ -40,10 +40,8 @@ func stubBackup(t time.Time, ownerID, ownerName string) backup.Backup { CreationTime: t, SnapshotID: "snapshot", DetailsID: "details", - ProtectedResourceID: ownerID + "-pr", - ProtectedResourceName: ownerName + "-pr", - ResourceOwnerID: ownerID + "-ro", - ResourceOwnerName: ownerName + "-ro", + ProtectedResourceID: ownerID + "-ro", + ProtectedResourceName: ownerName + "-ro", Status: "status", Selector: sel.Selector, ErrorCount: 2, @@ -86,7 +84,7 @@ func (suite *BackupUnitSuite) TestBackup_HeadersValues() { nowFmt, "1m0s", "status (2 errors, 1 skipped: 1 malware)", - "name-pr", + "name-ro", } ) @@ -123,9 +121,6 @@ func (suite *BackupUnitSuite) TestBackup_HeadersValues_onlyResourceOwners() { } ) - b.ProtectedResourceID = "" - b.ProtectedResourceName = "" - b.StartAndEndTime.CompletedAt = later // single skipped malware