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.
This commit is contained in:
Ashlie Martinez 2023-10-04 13:30:53 -07:00
parent 65af82f0f5
commit 7f438533f8
2 changed files with 11 additions and 20 deletions

View File

@ -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()

View File

@ -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