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) ## [Unreleased] (beta)
### Added ### 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 ### Fixed
- Fix Exchange folder cache population error when parent folder isn't found. - 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/cli/print"
"github.com/alcionai/corso/src/internal/common/dttm" "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/model"
"github.com/alcionai/corso/src/internal/stats" "github.com/alcionai/corso/src/internal/stats"
"github.com/alcionai/corso/src/pkg/fault" "github.com/alcionai/corso/src/pkg/fault"
@ -35,9 +36,10 @@ type Backup struct {
// Selector used in this operation // Selector used in this operation
Selector selectors.Selector `json:"selectors"` Selector selectors.Selector `json:"selectors"`
// ResourceOwner reference // TODO: in process of gaining support, most cases will still use
ResourceOwnerID string `json:"resourceOwnerID"` // ResourceOwner and ResourceOwnerName.
ResourceOwnerName string `json:"resourceOwnerName"` ProtectedResourceID string `json:"protectedResourceID,omitempty"`
ProtectedResourceName string `json:"protectedResourceName,omitempty"`
// Version represents the version of the backup format // Version represents the version of the backup format
Version int `json:"version"` Version int `json:"version"`
@ -59,6 +61,10 @@ type Backup struct {
// Reference to the backup details storage location. // Reference to the backup details storage location.
// Used to read backup.Details from the streamstore. // Used to read backup.Details from the streamstore.
DetailsID string `json:"detailsID"` DetailsID string `json:"detailsID"`
// prefer protectedResource
ResourceOwnerID string `json:"resourceOwnerID,omitempty"`
ResourceOwnerName string `json:"resourceOwnerName,omitempty"`
} }
// interface compliance checks // interface compliance checks
@ -167,23 +173,25 @@ func PrintAll(ctx context.Context, bs []*Backup) {
} }
type Printable struct { type Printable struct {
ID model.StableID `json:"id"` ID model.StableID `json:"id"`
Status string `json:"status"` Status string `json:"status"`
Version string `json:"version"` Version string `json:"version"`
Owner string `json:"owner"` ProtectedResourceID string `json:"protectedResourceID,omitempty"`
OwnerName string `json:"ownerName"` ProtectedResourceName string `json:"protectedResourceName,omitempty"`
Stats backupStats `json:"stats"` Owner string `json:"owner,omitempty"`
Stats backupStats `json:"stats"`
} }
// ToPrintable reduces the Backup to its minimally printable details. // ToPrintable reduces the Backup to its minimally printable details.
func (b Backup) ToPrintable() Printable { func (b Backup) ToPrintable() Printable {
return Printable{ return Printable{
ID: b.ID, ID: b.ID,
Status: b.Status, Status: b.Status,
Version: "0", Version: "0",
Owner: b.Selector.DiscreteOwner, ProtectedResourceID: b.Selector.DiscreteOwner,
OwnerName: b.Selector.DiscreteOwnerName, ProtectedResourceName: b.Selector.DiscreteOwnerName,
Stats: b.toStats(), Owner: b.Selector.DiscreteOwner,
Stats: b.toStats(),
} }
} }
@ -252,15 +260,12 @@ func (b Backup) Values() []string {
status += (")") status += (")")
} }
name := b.ResourceOwnerName name := str.First(
b.ProtectedResourceName,
if len(name) == 0 { b.ResourceOwnerName,
name = b.ResourceOwnerID b.ProtectedResourceID,
} b.ResourceOwnerID,
b.Selector.Name())
if len(name) == 0 {
name = b.Selector.DiscreteOwner
}
bs := b.toStats() bs := b.toStats()

View File

@ -37,13 +37,17 @@ func stubBackup(t time.Time, ownerID, ownerName string) backup.Backup {
model.ServiceTag: sel.PathService().String(), model.ServiceTag: sel.PathService().String(),
}, },
}, },
CreationTime: t, CreationTime: t,
SnapshotID: "snapshot", SnapshotID: "snapshot",
DetailsID: "details", DetailsID: "details",
Status: "status", ProtectedResourceID: ownerID + "-pr",
Selector: sel.Selector, ProtectedResourceName: ownerName + "-pr",
ErrorCount: 2, ResourceOwnerID: ownerID + "-ro",
Failure: "read, write", ResourceOwnerName: ownerName + "-ro",
Status: "status",
Selector: sel.Selector,
ErrorCount: 2,
Failure: "read, write",
ReadWrites: stats.ReadWrites{ ReadWrites: stats.ReadWrites{
BytesRead: 301, BytesRead: 301,
BytesUploaded: 301, BytesUploaded: 301,
@ -80,7 +84,7 @@ func (suite *BackupUnitSuite) TestBackup_HeadersValues() {
nowFmt, nowFmt,
"1m0s", "1m0s",
"status (2 errors, 1 skipped: 1 malware)", "status (2 errors, 1 skipped: 1 malware)",
"test", "name-pr",
} }
) )
@ -94,6 +98,42 @@ func (suite *BackupUnitSuite) TestBackup_HeadersValues() {
assert.Equal(t, expectVs, vs) 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() { func (suite *BackupUnitSuite) TestBackup_Values_statusVariations() {
table := []struct { table := []struct {
name string name string