add flag to output all details (#2676)

adds a hidden flag to backup details that
allows the caller to see all details retrieved
by the repository, without running the results
through the selector reduce step.

---

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

- [x]  No

#### Type of change

- [x] 🌻 Feature

#### Issue(s)

* #2675

#### Test Plan

- [x] 💪 Manual
This commit is contained in:
Keepers 2023-02-28 17:02:29 -07:00 committed by GitHub
parent 5c65638721
commit e42e3f253b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 64 additions and 23 deletions

View File

@ -136,6 +136,8 @@ func addExchangeCommands(cmd *cobra.Command) *cobra.Command {
c.Use = c.Use + " " + exchangeServiceCommandDetailsUseSuffix c.Use = c.Use + " " + exchangeServiceCommandDetailsUseSuffix
c.Example = exchangeServiceCommandDetailsExamples c.Example = exchangeServiceCommandDetailsExamples
options.AddSkipReduceFlag(c)
// Flags addition ordering should follow the order we want them to appear in help and docs: // Flags addition ordering should follow the order we want them to appear in help and docs:
// More generic (ex: --user) and more frequently used flags take precedence. // More generic (ex: --user) and more frequently used flags take precedence.
fs.StringVar(&backupID, fs.StringVar(&backupID,
@ -212,7 +214,6 @@ func addExchangeCommands(cmd *cobra.Command) *cobra.Command {
&contactFolder, &contactFolder,
utils.ContactFolderFN, nil, utils.ContactFolderFN, nil,
"Select backup details for contacts within a folder; accepts '"+utils.Wildcard+"' to select all contact folders.") "Select backup details for contacts within a folder; accepts '"+utils.Wildcard+"' to select all contact folders.")
fs.StringVar( fs.StringVar(
&contactName, &contactName,
utils.ContactNameFN, "", utils.ContactNameFN, "",
@ -434,7 +435,8 @@ func exchangeDetailsCmd() *cobra.Command {
} }
} }
// lists the history of backup operations // lists all items in the backup, running the results first through
// selector reduction as a filtering step.
func detailsExchangeCmd(cmd *cobra.Command, args []string) error { func detailsExchangeCmd(cmd *cobra.Command, args []string) error {
if utils.HasNoFlagsAndShownHelp(cmd) { if utils.HasNoFlagsAndShownHelp(cmd) {
return nil return nil
@ -468,14 +470,16 @@ func detailsExchangeCmd(cmd *cobra.Command, args []string) error {
return Only(ctx, err) return Only(ctx, err)
} }
r, err := repository.Connect(ctx, acct, s, options.Control()) ctrlOpts := options.Control()
r, err := repository.Connect(ctx, acct, s, ctrlOpts)
if err != nil { if err != nil {
return Only(ctx, errors.Wrapf(err, "Failed to connect to the %s repository", s.Provider)) return Only(ctx, errors.Wrapf(err, "Failed to connect to the %s repository", s.Provider))
} }
defer utils.CloseRepo(ctx, r) defer utils.CloseRepo(ctx, r)
ds, err := runDetailsExchangeCmd(ctx, r, backupID, opts) ds, err := runDetailsExchangeCmd(ctx, r, backupID, opts, ctrlOpts.SkipReduce)
if err != nil { if err != nil {
return Only(ctx, err) return Only(ctx, err)
} }
@ -498,6 +502,7 @@ func runDetailsExchangeCmd(
r repository.BackupGetter, r repository.BackupGetter,
backupID string, backupID string,
opts utils.ExchangeOpts, opts utils.ExchangeOpts,
skipReduce bool,
) (*details.Details, error) { ) (*details.Details, error) {
if err := utils.ValidateExchangeRestoreFlags(backupID, opts); err != nil { if err := utils.ValidateExchangeRestoreFlags(backupID, opts); err != nil {
return nil, err return nil, err
@ -513,10 +518,13 @@ func runDetailsExchangeCmd(
return nil, errors.Wrap(errs.Failure(), "Failed to get backup details in the repository") return nil, errors.Wrap(errs.Failure(), "Failed to get backup details in the repository")
} }
sel := utils.IncludeExchangeRestoreDataSelectors(opts) if !skipReduce {
utils.FilterExchangeRestoreInfoSelectors(sel, opts) sel := utils.IncludeExchangeRestoreDataSelectors(opts)
utils.FilterExchangeRestoreInfoSelectors(sel, opts)
d = sel.Reduce(ctx, d, errs)
}
return sel.Reduce(ctx, d, errs), nil return d, nil
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------

View File

@ -231,7 +231,8 @@ func (suite *ExchangeSuite) TestExchangeBackupDetailsSelectors() {
ctx, ctx,
test.BackupGetter, test.BackupGetter,
"backup-ID", "backup-ID",
test.Opts) test.Opts,
false)
assert.NoError(t, err, "failure") assert.NoError(t, err, "failure")
assert.ElementsMatch(t, test.Expected, output.Entries) assert.ElementsMatch(t, test.Expected, output.Entries)
}) })
@ -250,7 +251,8 @@ func (suite *ExchangeSuite) TestExchangeBackupDetailsSelectorsBadFormats() {
ctx, ctx,
test.BackupGetter, test.BackupGetter,
"backup-ID", "backup-ID",
test.Opts) test.Opts,
false)
assert.Error(t, err, "failure") assert.Error(t, err, "failure")
assert.Empty(t, output) assert.Empty(t, output)
}) })

View File

@ -103,6 +103,8 @@ func addOneDriveCommands(cmd *cobra.Command) *cobra.Command {
c.Use = c.Use + " " + oneDriveServiceCommandDetailsUseSuffix c.Use = c.Use + " " + oneDriveServiceCommandDetailsUseSuffix
c.Example = oneDriveServiceCommandDetailsExamples c.Example = oneDriveServiceCommandDetailsExamples
options.AddSkipReduceFlag(c)
fs.StringVar(&backupID, fs.StringVar(&backupID,
utils.BackupFN, "", utils.BackupFN, "",
"ID of the backup to explore. (required)") "ID of the backup to explore. (required)")
@ -348,7 +350,9 @@ func detailsOneDriveCmd(cmd *cobra.Command, args []string) error {
return Only(ctx, err) return Only(ctx, err)
} }
r, err := repository.Connect(ctx, acct, s, options.Control()) ctrlOpts := options.Control()
r, err := repository.Connect(ctx, acct, s, ctrlOpts)
if err != nil { if err != nil {
return Only(ctx, errors.Wrapf(err, "Failed to connect to the %s repository", s.Provider)) return Only(ctx, errors.Wrapf(err, "Failed to connect to the %s repository", s.Provider))
} }
@ -367,7 +371,7 @@ func detailsOneDriveCmd(cmd *cobra.Command, args []string) error {
Populated: utils.GetPopulatedFlags(cmd), Populated: utils.GetPopulatedFlags(cmd),
} }
ds, err := runDetailsOneDriveCmd(ctx, r, backupID, opts) ds, err := runDetailsOneDriveCmd(ctx, r, backupID, opts, ctrlOpts.SkipReduce)
if err != nil { if err != nil {
return Only(ctx, err) return Only(ctx, err)
} }
@ -390,6 +394,7 @@ func runDetailsOneDriveCmd(
r repository.BackupGetter, r repository.BackupGetter,
backupID string, backupID string,
opts utils.OneDriveOpts, opts utils.OneDriveOpts,
skipReduce bool,
) (*details.Details, error) { ) (*details.Details, error) {
if err := utils.ValidateOneDriveRestoreFlags(backupID, opts); err != nil { if err := utils.ValidateOneDriveRestoreFlags(backupID, opts); err != nil {
return nil, err return nil, err
@ -405,10 +410,13 @@ func runDetailsOneDriveCmd(
return nil, errors.Wrap(errs.Failure(), "Failed to get backup details in the repository") return nil, errors.Wrap(errs.Failure(), "Failed to get backup details in the repository")
} }
sel := utils.IncludeOneDriveRestoreDataSelectors(opts) if !skipReduce {
utils.FilterOneDriveRestoreInfoSelectors(sel, opts) sel := utils.IncludeOneDriveRestoreDataSelectors(opts)
utils.FilterOneDriveRestoreInfoSelectors(sel, opts)
d = sel.Reduce(ctx, d, errs)
}
return sel.Reduce(ctx, d, errs), nil return d, nil
} }
// `corso backup delete onedrive [<flag>...]` // `corso backup delete onedrive [<flag>...]`

View File

@ -102,7 +102,8 @@ func (suite *OneDriveSuite) TestOneDriveBackupDetailsSelectors() {
ctx, ctx,
test.BackupGetter, test.BackupGetter,
"backup-ID", "backup-ID",
test.Opts) test.Opts,
false)
assert.NoError(t, err) assert.NoError(t, err)
assert.ElementsMatch(t, test.Expected, output.Entries) assert.ElementsMatch(t, test.Expected, output.Entries)
}) })
@ -121,7 +122,8 @@ func (suite *OneDriveSuite) TestOneDriveBackupDetailsSelectorsBadFormats() {
ctx, ctx,
test.BackupGetter, test.BackupGetter,
"backup-ID", "backup-ID",
test.Opts) test.Opts,
false)
assert.Error(t, err) assert.Error(t, err)
assert.Empty(t, output) assert.Empty(t, output)
}) })

View File

@ -114,6 +114,8 @@ func addSharePointCommands(cmd *cobra.Command) *cobra.Command {
c.Use = c.Use + " " + sharePointServiceCommandDetailsUseSuffix c.Use = c.Use + " " + sharePointServiceCommandDetailsUseSuffix
c.Example = sharePointServiceCommandDetailsExamples c.Example = sharePointServiceCommandDetailsExamples
options.AddSkipReduceFlag(c)
fs.StringVar(&backupID, fs.StringVar(&backupID,
utils.BackupFN, "", utils.BackupFN, "",
"ID of the backup to retrieve.") "ID of the backup to retrieve.")
@ -479,7 +481,9 @@ func detailsSharePointCmd(cmd *cobra.Command, args []string) error {
return Only(ctx, err) return Only(ctx, err)
} }
r, err := repository.Connect(ctx, acct, s, options.Control()) ctrlOpts := options.Control()
r, err := repository.Connect(ctx, acct, s, ctrlOpts)
if err != nil { if err != nil {
return Only(ctx, errors.Wrapf(err, "Failed to connect to the %s repository", s.Provider)) return Only(ctx, errors.Wrapf(err, "Failed to connect to the %s repository", s.Provider))
} }
@ -495,7 +499,7 @@ func detailsSharePointCmd(cmd *cobra.Command, args []string) error {
Populated: utils.GetPopulatedFlags(cmd), Populated: utils.GetPopulatedFlags(cmd),
} }
ds, err := runDetailsSharePointCmd(ctx, r, backupID, opts) ds, err := runDetailsSharePointCmd(ctx, r, backupID, opts, ctrlOpts.SkipReduce)
if err != nil { if err != nil {
return Only(ctx, err) return Only(ctx, err)
} }
@ -518,6 +522,7 @@ func runDetailsSharePointCmd(
r repository.BackupGetter, r repository.BackupGetter,
backupID string, backupID string,
opts utils.SharePointOpts, opts utils.SharePointOpts,
skipReduce bool,
) (*details.Details, error) { ) (*details.Details, error) {
if err := utils.ValidateSharePointRestoreFlags(backupID, opts); err != nil { if err := utils.ValidateSharePointRestoreFlags(backupID, opts); err != nil {
return nil, err return nil, err
@ -533,8 +538,11 @@ func runDetailsSharePointCmd(
return nil, errors.Wrap(errs.Failure(), "Failed to get backup details in the repository") return nil, errors.Wrap(errs.Failure(), "Failed to get backup details in the repository")
} }
sel := utils.IncludeSharePointRestoreDataSelectors(opts) if !skipReduce {
utils.FilterSharePointRestoreInfoSelectors(sel, opts) sel := utils.IncludeSharePointRestoreDataSelectors(opts)
utils.FilterSharePointRestoreInfoSelectors(sel, opts)
d = sel.Reduce(ctx, d, errs)
}
return sel.Reduce(ctx, d, errs), nil return d, nil
} }

View File

@ -219,7 +219,8 @@ func (suite *SharePointSuite) TestSharePointBackupDetailsSelectors() {
ctx, ctx,
test.BackupGetter, test.BackupGetter,
"backup-ID", "backup-ID",
test.Opts) test.Opts,
false)
assert.NoError(t, err) assert.NoError(t, err)
assert.ElementsMatch(t, test.Expected, output.Entries) assert.ElementsMatch(t, test.Expected, output.Entries)
}) })
@ -238,7 +239,8 @@ func (suite *SharePointSuite) TestSharePointBackupDetailsSelectorsBadFormats() {
ctx, ctx,
test.BackupGetter, test.BackupGetter,
"backup-ID", "backup-ID",
test.Opts) test.Opts,
false)
assert.Error(t, err) assert.Error(t, err)
assert.Empty(t, output) assert.Empty(t, output)
}) })

View File

@ -14,6 +14,7 @@ func Control() control.Options {
opt.FailFast = fastFail opt.FailFast = fastFail
opt.DisableMetrics = noStats opt.DisableMetrics = noStats
opt.RestorePermissions = restorePermissions opt.RestorePermissions = restorePermissions
opt.SkipReduce = skipReduce
opt.ToggleFeatures.DisableIncrementals = disableIncrementals opt.ToggleFeatures.DisableIncrementals = disableIncrementals
opt.ToggleFeatures.EnablePermissionsBackup = enablePermissionsBackup opt.ToggleFeatures.EnablePermissionsBackup = enablePermissionsBackup
@ -28,6 +29,7 @@ var (
fastFail bool fastFail bool
noStats bool noStats bool
restorePermissions bool restorePermissions bool
skipReduce bool
) )
// AddOperationFlags adds command-local operation flags // AddOperationFlags adds command-local operation flags
@ -52,6 +54,14 @@ func AddRestorePermissionsFlag(cmd *cobra.Command) {
cobra.CheckErr(fs.MarkHidden("restore-permissions")) cobra.CheckErr(fs.MarkHidden("restore-permissions"))
} }
// AddSkipReduceFlag adds a hidden flag that allows callers to skip the selector
// reduction step. Currently only intended for details commands, not restore.
func AddSkipReduceFlag(cmd *cobra.Command) {
fs := cmd.Flags()
fs.BoolVar(&skipReduce, "skip-reduce", false, "Skip the selector reduce filtering")
cobra.CheckErr(fs.MarkHidden("skip-reduce"))
}
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// Feature Flags // Feature Flags
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------

View File

@ -10,6 +10,7 @@ type Options struct {
DisableMetrics bool `json:"disableMetrics"` DisableMetrics bool `json:"disableMetrics"`
FailFast bool `json:"failFast"` FailFast bool `json:"failFast"`
RestorePermissions bool `json:"restorePermissions"` RestorePermissions bool `json:"restorePermissions"`
SkipReduce bool `json:"skipReduce"`
ToggleFeatures Toggles `json:"ToggleFeatures"` ToggleFeatures Toggles `json:"ToggleFeatures"`
} }