From 6e4f30d892114ab548cd10daedb1fe87e7509b5a Mon Sep 17 00:00:00 2001 From: Keepers Date: Thu, 25 May 2023 19:43:57 -0600 Subject: [PATCH] rename ownerName to protectedResourceName (#3513) #### Does this PR need a docs update or release note? - [x] :white_check_mark: Yes, it's included #### Type of change - [x] :broom: Tech Debt/Cleanup #### Issue(s) * #3478 #### Test Plan - [x] :zap: Unit test --- CHANGELOG.md | 2 +- src/pkg/backup/backup.go | 53 ++++++++++++++++++--------------- src/pkg/backup/backup_test.go | 56 ++++++++++++++++++++++++++++++----- 3 files changed, 78 insertions(+), 33 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index afdbc8a79..c8749a5f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] (beta) ### Added -- Added OwnerName to the backup list json output. OwnerName holds either a UPN or a WebURL, depending on the resource type. +- Added ProtectedResourceName to the backup list json output. ProtectedResourceName holds either a UPN or a WebURL, depending on the resource type. ### Fixed - Fix Exchange folder cache population error when parent folder isn't found. diff --git a/src/pkg/backup/backup.go b/src/pkg/backup/backup.go index d0796b58c..8580a041e 100644 --- a/src/pkg/backup/backup.go +++ b/src/pkg/backup/backup.go @@ -11,6 +11,7 @@ import ( "github.com/alcionai/corso/src/cli/print" "github.com/alcionai/corso/src/internal/common/dttm" + "github.com/alcionai/corso/src/internal/common/str" "github.com/alcionai/corso/src/internal/model" "github.com/alcionai/corso/src/internal/stats" "github.com/alcionai/corso/src/pkg/fault" @@ -35,9 +36,10 @@ type Backup struct { // Selector used in this operation Selector selectors.Selector `json:"selectors"` - // ResourceOwner reference - ResourceOwnerID string `json:"resourceOwnerID"` - ResourceOwnerName string `json:"resourceOwnerName"` + // TODO: in process of gaining support, most cases will still use + // ResourceOwner and ResourceOwnerName. + ProtectedResourceID string `json:"protectedResourceID,omitempty"` + ProtectedResourceName string `json:"protectedResourceName,omitempty"` // Version represents the version of the backup format Version int `json:"version"` @@ -59,6 +61,10 @@ 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 @@ -167,23 +173,25 @@ func PrintAll(ctx context.Context, bs []*Backup) { } type Printable struct { - ID model.StableID `json:"id"` - Status string `json:"status"` - Version string `json:"version"` - Owner string `json:"owner"` - OwnerName string `json:"ownerName"` - Stats backupStats `json:"stats"` + ID model.StableID `json:"id"` + Status string `json:"status"` + Version string `json:"version"` + ProtectedResourceID string `json:"protectedResourceID,omitempty"` + ProtectedResourceName string `json:"protectedResourceName,omitempty"` + Owner string `json:"owner,omitempty"` + Stats backupStats `json:"stats"` } // ToPrintable reduces the Backup to its minimally printable details. func (b Backup) ToPrintable() Printable { return Printable{ - ID: b.ID, - Status: b.Status, - Version: "0", - Owner: b.Selector.DiscreteOwner, - OwnerName: b.Selector.DiscreteOwnerName, - Stats: b.toStats(), + ID: b.ID, + Status: b.Status, + Version: "0", + ProtectedResourceID: b.Selector.DiscreteOwner, + ProtectedResourceName: b.Selector.DiscreteOwnerName, + Owner: b.Selector.DiscreteOwner, + Stats: b.toStats(), } } @@ -252,15 +260,12 @@ func (b Backup) Values() []string { status += (")") } - name := b.ResourceOwnerName - - if len(name) == 0 { - name = b.ResourceOwnerID - } - - if len(name) == 0 { - name = b.Selector.DiscreteOwner - } + 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 74ab35fe0..4f26f35c8 100644 --- a/src/pkg/backup/backup_test.go +++ b/src/pkg/backup/backup_test.go @@ -37,13 +37,17 @@ func stubBackup(t time.Time, ownerID, ownerName string) backup.Backup { model.ServiceTag: sel.PathService().String(), }, }, - CreationTime: t, - SnapshotID: "snapshot", - DetailsID: "details", - Status: "status", - Selector: sel.Selector, - ErrorCount: 2, - Failure: "read, write", + CreationTime: t, + SnapshotID: "snapshot", + DetailsID: "details", + ProtectedResourceID: ownerID + "-pr", + ProtectedResourceName: ownerName + "-pr", + ResourceOwnerID: ownerID + "-ro", + ResourceOwnerName: ownerName + "-ro", + Status: "status", + Selector: sel.Selector, + ErrorCount: 2, + Failure: "read, write", ReadWrites: stats.ReadWrites{ BytesRead: 301, BytesUploaded: 301, @@ -80,7 +84,7 @@ func (suite *BackupUnitSuite) TestBackup_HeadersValues() { nowFmt, "1m0s", "status (2 errors, 1 skipped: 1 malware)", - "test", + "name-pr", } ) @@ -94,6 +98,42 @@ func (suite *BackupUnitSuite) TestBackup_HeadersValues() { assert.Equal(t, expectVs, vs) } +func (suite *BackupUnitSuite) TestBackup_HeadersValues_onlyResourceOwners() { + var ( + t = suite.T() + now = time.Now() + later = now.Add(1 * time.Minute) + b = stubBackup(now, "id", "name") + expectHs = []string{ + "ID", + "Started At", + "Duration", + "Status", + "Resource Owner", + } + nowFmt = dttm.FormatToTabularDisplay(now) + expectVs = []string{ + "id", + nowFmt, + "1m0s", + "status (2 errors, 1 skipped: 1 malware)", + "name-ro", + } + ) + + b.ProtectedResourceID = "" + b.ProtectedResourceName = "" + + b.StartAndEndTime.CompletedAt = later + + // single skipped malware + hs := b.Headers() + assert.Equal(t, expectHs, hs) + + vs := b.Values() + assert.Equal(t, expectVs, vs) +} + func (suite *BackupUnitSuite) TestBackup_Values_statusVariations() { table := []struct { name string