From e1457c23bf2687cc6ebd74f34cf40c0ac92332b1 Mon Sep 17 00:00:00 2001 From: Keepers Date: Wed, 24 Jan 2024 13:22:08 -0700 Subject: [PATCH] show data category in backup list (#5023) Adds the backup's data category to the cli output. before: ``` ID Started At Duration Status Resource Owner 09e8d1e3-92d4-426d-9ca1-3cd063ce8bb9 2024-01-12T17:54:33Z 16.103569s Completed rfinders@10rqc2.onmicrosoft.com 893ef934-9403-4775-b667-09f77cd26e83 2024-01-12T17:55:22Z 5.66253s Completed rfinders@10rqc2.onmicrosoft.com ``` after: ``` ID Started at Duration Status Protected resource Data 09e8d1e3-92d4-426d-9ca1-3cd063ce8bb9 2024-01-12T17:54:33Z 16.103569s Completed rfinders@10rqc2.onmicrosoft.com Contacts,Emails,Events 893ef934-9403-4775-b667-09f77cd26e83 2024-01-12T17:55:22Z 5.66253s Completed rfinders@10rqc2.onmicrosoft.com Emails ``` --- #### Does this PR need a docs update or release note? - [x] :no_entry: No #### Type of change - [x] :sunflower: Feature #### Issue(s) * #3748 #### Test Plan - [x] :muscle: Manual - [x] :zap: Unit test --- CHANGELOG.md | 1 + src/pkg/backup/backup.go | 31 +++++++++++++++++++++++++------ src/pkg/backup/backup_test.go | 12 ++++++++---- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77244b734..83a8985cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - When running `backup details` on an empty backup returns a more helpful error message. +- Backup List additionally shows the data category for each backup. ### Known issues - Backing up a group mailbox item may fail if it has a very large number of attachments (500+). diff --git a/src/pkg/backup/backup.go b/src/pkg/backup/backup.go index ff1dfdd93..cc51b588a 100644 --- a/src/pkg/backup/backup.go +++ b/src/pkg/backup/backup.go @@ -3,6 +3,7 @@ package backup import ( "context" "fmt" + "sort" "strconv" "strings" "time" @@ -16,6 +17,7 @@ import ( "github.com/alcionai/corso/src/internal/version" "github.com/alcionai/corso/src/pkg/dttm" "github.com/alcionai/corso/src/pkg/fault" + "github.com/alcionai/corso/src/pkg/logger" "github.com/alcionai/corso/src/pkg/selectors" ) @@ -226,17 +228,19 @@ func (b Backup) MinimumPrintable() any { // for printing out to a terminal in a columnar display. func (b Backup) Headers(skipID bool) []string { headers := []string{ - "Started At", + "ID", + "Started at", "Duration", "Status", - "Resource Owner", + "Protected resource", + "Data", } if skipID { - return headers + headers = headers[1:] } - return append([]string{"ID"}, headers...) + return headers } // Values returns the values matching the Headers list for printing @@ -292,18 +296,33 @@ func (b Backup) Values(skipID bool) []string { bs := b.toStats() + reasons, err := b.Selector.Reasons("doesnt-matter", false) + if err != nil { + logger.CtxErr(context.Background(), err).Error("getting reasons from selector") + } + + reasonCats := []string{} + + for _, r := range reasons { + reasonCats = append(reasonCats, r.Category().HumanString()) + } + + sort.Strings(reasonCats) + values := []string{ + string(b.ID), dttm.FormatToTabularDisplay(b.StartedAt), bs.EndedAt.Sub(bs.StartedAt).String(), status, name, + strings.Join(reasonCats, ","), } if skipID { - return values + values = values[1:] } - return append([]string{string(b.ID)}, values...) + return values } // ----- print backup stats diff --git a/src/pkg/backup/backup_test.go b/src/pkg/backup/backup_test.go index b040e5d28..f2200b48a 100644 --- a/src/pkg/backup/backup_test.go +++ b/src/pkg/backup/backup_test.go @@ -155,10 +155,11 @@ func (suite *BackupUnitSuite) TestBackup_HeadersValues() { b = stubBackup(now, "id", "name") expectHs = []string{ "ID", - "Started At", + "Started at", "Duration", "Status", - "Resource Owner", + "Protected resource", + "Data", } nowFmt = dttm.FormatToTabularDisplay(now) expectVs = []string{ @@ -167,6 +168,7 @@ func (suite *BackupUnitSuite) TestBackup_HeadersValues() { "1m0s", "status (2 errors, 1 skipped: 1 malware)", "name-pr", + "Contacts,Emails,Events", } ) @@ -194,10 +196,11 @@ func (suite *BackupUnitSuite) TestBackup_HeadersValues_onlyResourceOwners() { b = stubBackup(now, "id", "name") expectHs = []string{ "ID", - "Started At", + "Started at", "Duration", "Status", - "Resource Owner", + "Protected resource", + "Data", } nowFmt = dttm.FormatToTabularDisplay(now) expectVs = []string{ @@ -206,6 +209,7 @@ func (suite *BackupUnitSuite) TestBackup_HeadersValues_onlyResourceOwners() { "1m0s", "status (2 errors, 1 skipped: 1 malware)", "name-ro", + "Contacts,Emails,Events", } )