From 7bb5a9a2b1231e1441a5fddeff62f1b0df3302d3 Mon Sep 17 00:00:00 2001 From: neha_gupta Date: Fri, 14 Apr 2023 07:04:44 +0530 Subject: [PATCH] change user flag (#3076) As part of handling share mailbox- Introduced new flag - `mailbox` and deprecated existing `user` flag This is to handle wider group of mailbox types. #### Does this PR need a docs update or release note? - [x] :white_check_mark: Yes, it's included #### Type of change - [x] :sunflower: Feature #### Issue(s) * # #### Test Plan - [x] :muscle: Manual --- .github/workflows/load_test.yml | 6 +++--- .github/workflows/sanity-test.yaml | 14 +++++++------- src/cli/backup/exchange.go | 20 ++++++++++---------- src/cli/cli.go | 17 +++++++++++++++++ src/cli/utils/flags.go | 24 +++++++++++++++++++++--- website/docs/quickstart.md | 6 +++--- 6 files changed, 61 insertions(+), 26 deletions(-) diff --git a/.github/workflows/load_test.yml b/.github/workflows/load_test.yml index ec428c42a..449fb9349 100644 --- a/.github/workflows/load_test.yml +++ b/.github/workflows/load_test.yml @@ -86,15 +86,15 @@ jobs: CORSO_M365_LOAD_TEST_USER_ID: ${{ secrets.CORSO_M365_LOAD_TEST_USER_ID }} run: | go run . exchange emails \ - --user ${{ env.CORSO_M365_LOAD_TEST_USER_ID }} \ + --mailbox ${{ env.CORSO_M365_LOAD_TEST_USER_ID }} \ --destination lt_${{ env.NOW }} \ --count 10 go run . exchange contacts \ - --user ${{ env.CORSO_M365_LOAD_TEST_USER_ID }} \ + --mailbox ${{ env.CORSO_M365_LOAD_TEST_USER_ID }} \ --destination lt_${{ env.NOW }} \ --count 10 go run . exchange events \ - --user ${{ env.CORSO_M365_LOAD_TEST_USER_ID }} \ + --mailbox ${{ env.CORSO_M365_LOAD_TEST_USER_ID }} \ --destination lt_${{ env.NOW }} \ --count 10 diff --git a/.github/workflows/sanity-test.yaml b/.github/workflows/sanity-test.yaml index b9086b21e..dd5d5b5d4 100644 --- a/.github/workflows/sanity-test.yaml +++ b/.github/workflows/sanity-test.yaml @@ -112,7 +112,7 @@ jobs: CORSO_M365_LOAD_TEST_USER_ID: ${{ secrets.CORSO_M365_LOAD_TEST_USER_ID }} run: | go run . exchange emails \ - --user ${{ env.CORSO_M365_TEST_USER_ID }} \ + --mailbox ${{ env.CORSO_M365_TEST_USER_ID }} \ --tenant ${{ env.AZURE_TENANT_ID }} \ --destination Corso_Restore_st_${{ steps.repo-init.outputs.result }} \ --count 4 @@ -123,11 +123,11 @@ jobs: run: | ./corso backup create exchange \ --no-stats \ - --user "${CORSO_M365_TEST_USER_ID}" \ - --hide-progress \ - --data 'email' \ - --json \ - 2>&1 | tee $TEST_RESULT/backup_exchange.txt + --mailbox "${CORSO_M365_TEST_USER_ID}" \ + --hide-progress \ + --data 'email' \ + --json \ + 2>&1 | tee $TEST_RESULT/backup_exchange.txt resultjson=$(sed -e '1,/Completed Backups/d' $TEST_RESULT/backup_exchange.txt ) @@ -200,7 +200,7 @@ jobs: ./corso backup create exchange \ --no-stats \ --hide-progress \ - --user "${CORSO_M365_TEST_USER_ID}" \ + --mailbox "${CORSO_M365_TEST_USER_ID}" \ --json \ 2>&1 | tee $TEST_RESULT/backup_exchange_incremental.txt diff --git a/src/cli/backup/exchange.go b/src/cli/backup/exchange.go index 4f4de9ac2..5b5e48f75 100644 --- a/src/cli/backup/exchange.go +++ b/src/cli/backup/exchange.go @@ -32,38 +32,38 @@ const ( const ( exchangeServiceCommand = "exchange" - exchangeServiceCommandCreateUseSuffix = "--user | '" + utils.Wildcard + "'" + exchangeServiceCommandCreateUseSuffix = "--mailbox | '" + utils.Wildcard + "'" exchangeServiceCommandDeleteUseSuffix = "--backup " exchangeServiceCommandDetailsUseSuffix = "--backup " ) const ( exchangeServiceCommandCreateExamples = `# Backup all Exchange data for Alice -corso backup create exchange --user alice@example.com +corso backup create exchange --mailbox alice@example.com # Backup only Exchange contacts for Alice and Bob -corso backup create exchange --user alice@example.com,bob@example.com --data contacts +corso backup create exchange --mailbox alice@example.com,bob@example.com --data contacts # Backup all Exchange data for all M365 users -corso backup create exchange --user '*'` +corso backup create exchange --mailbox '*'` exchangeServiceCommandDeleteExamples = `# Delete Exchange backup with ID 1234abcd-12ab-cd34-56de-1234abcd corso backup delete exchange --backup 1234abcd-12ab-cd34-56de-1234abcd` exchangeServiceCommandDetailsExamples = `# Explore Alice's items in backup 1234abcd-12ab-cd34-56de-1234abcd -corso backup details exchange --backup 1234abcd-12ab-cd34-56de-1234abcd --user alice@example.com +corso backup details exchange --backup 1234abcd-12ab-cd34-56de-1234abcd --mailbox alice@example.com # Explore Alice's emails with subject containing "Hello world" in folder "Inbox" from a specific backup corso backup details exchange --backup 1234abcd-12ab-cd34-56de-1234abcd \ - --user alice@example.com --email-subject "Hello world" --email-folder Inbox + --mailbox alice@example.com --email-subject "Hello world" --email-folder Inbox # Explore Bobs's events occurring after start of 2022 from a specific backup corso backup details exchange --backup 1234abcd-12ab-cd34-56de-1234abcd \ - --user bob@example.com --event-starts-after 2022-01-01T00:00:00 + --mailbox bob@example.com --event-starts-after 2022-01-01T00:00:00 # Explore Alice's contacts with name containing Andy from a specific backup corso backup details exchange --backup 1234abcd-12ab-cd34-56de-1234abcd \ - --user alice@example.com --contact-name Andy` + --mailbox alice@example.com --contact-name Andy` ) // called by backup.go to map subcommands to provider-specific handling. @@ -83,7 +83,7 @@ func addExchangeCommands(cmd *cobra.Command) *cobra.Command { // 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. - utils.AddUserFlag(c) + utils.AddMailBoxFlag(c) utils.AddDataFlag(c, []string{dataEmail, dataContacts, dataEvents}, false) options.AddFetchParallelismFlag(c) options.AddFailFastFlag(c) @@ -207,7 +207,7 @@ func exchangeBackupCreateSelectors(userIDs, cats []string) *selectors.ExchangeBa func validateExchangeBackupCreateFlags(userIDs, cats []string) error { if len(userIDs) == 0 { - return clues.New("--user requires one or more email addresses or the wildcard '*'") + return clues.New("--user/--mailbox requires one or more email addresses or the wildcard '*'") } for _, d := range cats { diff --git a/src/cli/cli.go b/src/cli/cli.go index 9202e5367..0b578c5b5 100644 --- a/src/cli/cli.go +++ b/src/cli/cli.go @@ -90,11 +90,28 @@ func preRun(cc *cobra.Command, args []string) error { options.Control()) } + // handle deprecated user flag in Backup exchange command + if cc.CommandPath() == "corso backup create exchange" { + handleMailBoxFlag(ctx, cc, flagSl) + } + log.Infow("cli command", "command", cc.CommandPath(), "flags", flagSl, "version", version.CurrentVersion()) return nil } +func handleMailBoxFlag(ctx context.Context, c *cobra.Command, flagNames []string) { + if !slices.Contains(flagNames, "user") && !slices.Contains(flagNames, "mailbox") { + print.Errf(ctx, "either --user or --mailbox flag is required") + os.Exit(1) + } + + if slices.Contains(flagNames, "user") && slices.Contains(flagNames, "mailbox") { + print.Err(ctx, "cannot use both [mailbox, user] flags in the same command") + os.Exit(1) + } +} + // Handler for flat calls to `corso`. // Produces the same output as `corso --help`. func handleCorsoCmd(cmd *cobra.Command, args []string) error { diff --git a/src/cli/utils/flags.go b/src/cli/utils/flags.go index 0b0e4a843..d884fb631 100644 --- a/src/cli/utils/flags.go +++ b/src/cli/utils/flags.go @@ -45,9 +45,10 @@ const ( BackupFN = "backup" CategoryDataFN = "data" - SiteFN = "site" // site only accepts WebURL values - SiteIDFN = "site-id" // site-id accepts actual site ids - UserFN = "user" + SiteFN = "site" // site only accepts WebURL values + SiteIDFN = "site-id" // site-id accepts actual site ids + UserFN = "user" + MailBoxFN = "mailbox" LibraryFN = "library" FileFN = "file" @@ -124,6 +125,23 @@ func AddUserFlag(cmd *cobra.Command) { cobra.CheckErr(cmd.MarkFlagRequired(UserFN)) } +// AddMailBoxFlag adds the --user and --mailbox flag. +func AddMailBoxFlag(cmd *cobra.Command) { + flags := cmd.Flags() + + flags.StringSliceVar( + &UserFV, + UserFN, nil, + "Backup a specific user's data; accepts '"+Wildcard+"' to select all users.") + + cobra.CheckErr(flags.MarkDeprecated(UserFN, fmt.Sprintf("use --%s instead", MailBoxFN))) + + flags.StringSliceVar( + &UserFV, + MailBoxFN, nil, + "Backup a specific mailbox's data; accepts '"+Wildcard+"' to select all mailbox.") +} + // AddSiteIDFlag adds the --site-id flag, which accepts site ID values. // This flag is hidden, since we expect users to prefer the --site url // and do not want to encourage confusion. diff --git a/website/docs/quickstart.md b/website/docs/quickstart.md index d51af87b0..15e25ebb6 100644 --- a/website/docs/quickstart.md +++ b/website/docs/quickstart.md @@ -125,7 +125,7 @@ you initialized the Corso repository, you might need to [connect to it again](.. ```powershell # Backup your inbox - .\corso backup create exchange --user + .\corso backup create exchange --mailbox ``` @@ -133,7 +133,7 @@ you initialized the Corso repository, you might need to [connect to it again](.. ```bash # Backup your inbox - ./corso backup create exchange --user + ./corso backup create exchange --mailbox ``` @@ -143,7 +143,7 @@ you initialized the Corso repository, you might need to [connect to it again](.. `# Backup your inbox docker run --env-file $HOME/.corso/corso.env \\ --volume $HOME/.corso:/app/corso ghcr.io/alcionai/corso:${Version()} \\ - backup create exchange --user ` + backup create exchange --mailbox ` }