<!-- PR description--> Flags for all configs- Azure cred flags- (azure-tenant-id, azure-client-id, azure-client-secret) present in - - Backup (create, delete, details and list) and restore of Exchange, Onedrive and Sharepoint command - S3 repo init and connect command AWS cred flags - (aws-access-key, aws-secret-access-key, aws-session-token) present in- - Backup (create, delete, details and list) and restore of Exchange, Onedrive and Sharepoint command - S3 repo init and connect command Passphrase flag- (--passphrase) present in- - Backup (create, delete, details and list) and restore of Exchange, Onedrive and Sharepoint command - S3 repo init and connect command S3 flags- --endpoint, --prefix, --bucket, --disable-tls, --disable-tls-verification - flags is for repo init and connect commands all the S3 env var will also work only in case of repo init and connect command. For all other commands user first connects to repo. Which will store the config values in config file. And then user can use that config file for other commands. No cred configs are save in the config file by Corso. Config file values added- Azure cred - - azure_client_id - azure_secret - azure_tenantid AWS cred - - aws_access_key_id - aws_secret_access_key - aws_session_token Passphrase - - passphrase **NOTE:** - in case of AWS creds all the three values should be provided from same method. Either put all values in env, config file and so on. - all the S3 env var will also work only in case of repo init and connect command. For all other commands user first connects to repo. Which will store the config values in config file. And then user can use that config file for other commands. --- #### Does this PR need a docs update or release note? - [ ] ✅ Yes, it's included - [x] 🕐 Yes, but in a later PR - [ ] ⛔ No #### Type of change <!--- Please check the type of change your PR introduces: ---> - [x] 🌻 Feature #### Issue(s) <!-- Can reference multiple issues. Use one of the following "magic words" - "closes, fixes" to auto-close the Github issue. --> * https://github.com/alcionai/corso/issues/3522 #### Test Plan <!-- How will this be tested prior to merging.--> - [x] 💪 Manual - [x] ⚡ Unit test - [ ] 💚 E2E
133 lines
4.0 KiB
Go
133 lines
4.0 KiB
Go
package restore
|
|
|
|
import (
|
|
"github.com/alcionai/clues"
|
|
"github.com/pkg/errors"
|
|
"github.com/spf13/cobra"
|
|
"github.com/spf13/pflag"
|
|
|
|
"github.com/alcionai/corso/src/cli/flags"
|
|
. "github.com/alcionai/corso/src/cli/print"
|
|
"github.com/alcionai/corso/src/cli/repo"
|
|
"github.com/alcionai/corso/src/cli/utils"
|
|
"github.com/alcionai/corso/src/internal/common/dttm"
|
|
"github.com/alcionai/corso/src/internal/data"
|
|
"github.com/alcionai/corso/src/pkg/control"
|
|
)
|
|
|
|
// called by restore.go to map subcommands to provider-specific handling.
|
|
func addSharePointCommands(cmd *cobra.Command) *cobra.Command {
|
|
var (
|
|
c *cobra.Command
|
|
fs *pflag.FlagSet
|
|
)
|
|
|
|
switch cmd.Use {
|
|
case restoreCommand:
|
|
c, fs = utils.AddCommand(cmd, sharePointRestoreCmd())
|
|
|
|
c.Use = c.Use + " " + sharePointServiceCommandUseSuffix
|
|
|
|
// Flags addition ordering should follow the order we want them to appear in help and docs:
|
|
// More generic (ex: --site) and more frequently used flags take precedence.
|
|
fs.SortFlags = false
|
|
|
|
flags.AddBackupIDFlag(c, true)
|
|
flags.AddSharePointDetailsAndRestoreFlags(c)
|
|
flags.AddRestorePermissionsFlag(c)
|
|
flags.AddFailFastFlag(c)
|
|
|
|
flags.AddCorsoPassphaseFlags(c)
|
|
flags.AddAWSCredsFlags(c)
|
|
flags.AddAzureCredsFlags(c)
|
|
}
|
|
|
|
return c
|
|
}
|
|
|
|
const (
|
|
sharePointServiceCommand = "sharepoint"
|
|
sharePointServiceCommandUseSuffix = "--backup <backupId>"
|
|
|
|
//nolint:lll
|
|
sharePointServiceCommandRestoreExamples = `# Restore file with ID 98765abcdef in Bob's latest backup (1234abcd...)
|
|
corso restore sharepoint --backup 1234abcd-12ab-cd34-56de-1234abcd --file 98765abcdef
|
|
|
|
# Restore the file with ID 98765abcdef along with its associated permissions
|
|
corso restore sharepoint --backup 1234abcd-12ab-cd34-56de-1234abcd \
|
|
--file 98765abcdef --restore-permissions
|
|
|
|
# Restore files named "ServerRenderTemplate.xsl" in the folder "Display Templates/Style Sheets".
|
|
corso restore sharepoint --backup 1234abcd-12ab-cd34-56de-1234abcd \
|
|
--file "ServerRenderTemplate.xsl" --folder "Display Templates/Style Sheets"
|
|
|
|
# Restore all files in the folder "Display Templates/Style Sheets" that were created before 2020.
|
|
corso restore sharepoint --backup 1234abcd-12ab-cd34-56de-1234abcd
|
|
--file-created-before 2020-01-01T00:00:00 --folder "Display Templates/Style Sheets"
|
|
|
|
# Restore all files in the "Documents" library.
|
|
corso restore sharepoint --backup 1234abcd-12ab-cd34-56de-1234abcd
|
|
--library Documents --folder "Display Templates/Style Sheets" `
|
|
)
|
|
|
|
// `corso restore sharepoint [<flag>...]`
|
|
func sharePointRestoreCmd() *cobra.Command {
|
|
return &cobra.Command{
|
|
Use: sharePointServiceCommand,
|
|
Short: "Restore M365 SharePoint service data",
|
|
RunE: restoreSharePointCmd,
|
|
Args: cobra.NoArgs,
|
|
Example: sharePointServiceCommandRestoreExamples,
|
|
}
|
|
}
|
|
|
|
// processes an sharepoint service restore.
|
|
func restoreSharePointCmd(cmd *cobra.Command, args []string) error {
|
|
ctx := cmd.Context()
|
|
|
|
if utils.HasNoFlagsAndShownHelp(cmd) {
|
|
return nil
|
|
}
|
|
|
|
opts := utils.MakeSharePointOpts(cmd)
|
|
|
|
if flags.RunModeFV == flags.RunModeFlagTest {
|
|
return nil
|
|
}
|
|
|
|
if err := utils.ValidateSharePointRestoreFlags(flags.BackupIDFV, opts); err != nil {
|
|
return err
|
|
}
|
|
|
|
r, _, _, err := utils.GetAccountAndConnect(ctx, repo.S3Overrides())
|
|
if err != nil {
|
|
return Only(ctx, err)
|
|
}
|
|
|
|
defer utils.CloseRepo(ctx, r)
|
|
|
|
restoreCfg := control.DefaultRestoreConfig(dttm.HumanReadableDriveItem)
|
|
Infof(ctx, "Restoring to folder %s", restoreCfg.Location)
|
|
|
|
sel := utils.IncludeSharePointRestoreDataSelectors(ctx, opts)
|
|
utils.FilterSharePointRestoreInfoSelectors(sel, opts)
|
|
|
|
ro, err := r.NewRestore(ctx, flags.BackupIDFV, sel.Selector, restoreCfg)
|
|
if err != nil {
|
|
return Only(ctx, clues.Wrap(err, "Failed to initialize SharePoint restore"))
|
|
}
|
|
|
|
ds, err := ro.Run(ctx)
|
|
if err != nil {
|
|
if errors.Is(err, data.ErrNotFound) {
|
|
return Only(ctx, clues.New("Backup or backup details missing for id "+flags.BackupIDFV))
|
|
}
|
|
|
|
return Only(ctx, clues.Wrap(err, "Failed to run SharePoint restore"))
|
|
}
|
|
|
|
ds.Items().MaybePrintEntries(ctx)
|
|
|
|
return nil
|
|
}
|