rename ownerName to protectedResourceName (#3513)

#### Does this PR need a docs update or release note?

- [x]  Yes, it's included

#### Type of change

- [x] 🧹 Tech Debt/Cleanup

#### Issue(s)

* #3478

#### Test Plan

- [x]  Unit test
This commit is contained in:
Keepers 2023-05-25 19:43:57 -06:00 committed by GitHub
parent cd7c63ba6f
commit 6e4f30d892
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 78 additions and 33 deletions

View File

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

View File

@ -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
@ -170,8 +176,9 @@ type Printable struct {
ID model.StableID `json:"id"`
Status string `json:"status"`
Version string `json:"version"`
Owner string `json:"owner"`
OwnerName string `json:"ownerName"`
ProtectedResourceID string `json:"protectedResourceID,omitempty"`
ProtectedResourceName string `json:"protectedResourceName,omitempty"`
Owner string `json:"owner,omitempty"`
Stats backupStats `json:"stats"`
}
@ -181,8 +188,9 @@ func (b Backup) ToPrintable() Printable {
ID: b.ID,
Status: b.Status,
Version: "0",
ProtectedResourceID: b.Selector.DiscreteOwner,
ProtectedResourceName: b.Selector.DiscreteOwnerName,
Owner: b.Selector.DiscreteOwner,
OwnerName: b.Selector.DiscreteOwnerName,
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()

View File

@ -40,6 +40,10 @@ 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",
Status: "status",
Selector: sel.Selector,
ErrorCount: 2,
@ -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