add restore and restore exchange cli (#210)
Adds the `corso restore` command to the cli (which only displays a help menu). And adds the `corso restore exchange` command (which also only displays a help menu) to the cli. Further functionality (like the complete flags) will come later.
This commit is contained in:
parent
bf267a5478
commit
fcdb42bc89
@ -33,7 +33,7 @@ func addExchangeApp(parent *cobra.Command) *cobra.Command {
|
|||||||
// `corso backup create exchange [<flag>...]`
|
// `corso backup create exchange [<flag>...]`
|
||||||
var exchangeCreateCmd = &cobra.Command{
|
var exchangeCreateCmd = &cobra.Command{
|
||||||
Use: "exchange",
|
Use: "exchange",
|
||||||
Short: "Backup M365 Exchange",
|
Short: "Backup M365 Exchange service data",
|
||||||
RunE: createExchangeCmd,
|
RunE: createExchangeCmd,
|
||||||
Args: cobra.NoArgs,
|
Args: cobra.NoArgs,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,6 +11,7 @@ import (
|
|||||||
"github.com/alcionai/corso/cli/backup"
|
"github.com/alcionai/corso/cli/backup"
|
||||||
"github.com/alcionai/corso/cli/config"
|
"github.com/alcionai/corso/cli/config"
|
||||||
"github.com/alcionai/corso/cli/repo"
|
"github.com/alcionai/corso/cli/repo"
|
||||||
|
"github.com/alcionai/corso/cli/restore"
|
||||||
"github.com/alcionai/corso/pkg/logger"
|
"github.com/alcionai/corso/pkg/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -57,8 +58,11 @@ func Handle() {
|
|||||||
corsoCmd.Flags().BoolP("version", "v", version, "current version info")
|
corsoCmd.Flags().BoolP("version", "v", version, "current version info")
|
||||||
corsoCmd.PersistentFlags().StringVar(&cfgFile, "config-file", "", "config file (default is $HOME/.corso)")
|
corsoCmd.PersistentFlags().StringVar(&cfgFile, "config-file", "", "config file (default is $HOME/.corso)")
|
||||||
|
|
||||||
|
corsoCmd.CompletionOptions.DisableDefaultCmd = true
|
||||||
|
|
||||||
repo.AddCommands(corsoCmd)
|
repo.AddCommands(corsoCmd)
|
||||||
backup.AddCommands(corsoCmd)
|
backup.AddCommands(corsoCmd)
|
||||||
|
restore.AddCommands(corsoCmd)
|
||||||
|
|
||||||
ctx, log := logger.Seed(context.Background())
|
ctx, log := logger.Seed(context.Background())
|
||||||
defer log.Sync() // flush all logs in the buffer
|
defer log.Sync() // flush all logs in the buffer
|
||||||
|
|||||||
@ -5,12 +5,13 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
|
||||||
"github.com/alcionai/corso/cli/utils"
|
"github.com/alcionai/corso/cli/utils"
|
||||||
"github.com/alcionai/corso/pkg/credentials"
|
"github.com/alcionai/corso/pkg/credentials"
|
||||||
"github.com/alcionai/corso/pkg/repository"
|
"github.com/alcionai/corso/pkg/repository"
|
||||||
"github.com/alcionai/corso/pkg/storage"
|
"github.com/alcionai/corso/pkg/storage"
|
||||||
"github.com/pkg/errors"
|
|
||||||
"github.com/spf13/viper"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@ -24,7 +24,7 @@ func AddCommands(parent *cobra.Command) {
|
|||||||
// `corso repo [<subcommand>] [<flag>...]`
|
// `corso repo [<subcommand>] [<flag>...]`
|
||||||
var repoCmd = &cobra.Command{
|
var repoCmd = &cobra.Command{
|
||||||
Use: "repo",
|
Use: "repo",
|
||||||
Short: "Manage your repositories.",
|
Short: "Manage your repositories",
|
||||||
Long: `Initialize, configure, and connect to your account backup repositories.`,
|
Long: `Initialize, configure, and connect to your account backup repositories.`,
|
||||||
Run: handleRepoCmd,
|
Run: handleRepoCmd,
|
||||||
Args: cobra.NoArgs,
|
Args: cobra.NoArgs,
|
||||||
|
|||||||
71
src/cli/restore/exchange.go
Normal file
71
src/cli/restore/exchange.go
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
package restore
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
"github.com/alcionai/corso/cli/config"
|
||||||
|
"github.com/alcionai/corso/cli/utils"
|
||||||
|
"github.com/alcionai/corso/pkg/credentials"
|
||||||
|
"github.com/alcionai/corso/pkg/repository"
|
||||||
|
)
|
||||||
|
|
||||||
|
// exchange bucket info from flags
|
||||||
|
var (
|
||||||
|
user string
|
||||||
|
)
|
||||||
|
|
||||||
|
// called by restore.go to map parent subcommands to provider-specific handling.
|
||||||
|
func addExchangeApp(parent *cobra.Command) *cobra.Command {
|
||||||
|
parent.AddCommand(exchangeCreateCmd)
|
||||||
|
|
||||||
|
// todo (keepers): add flags.
|
||||||
|
|
||||||
|
return exchangeCreateCmd
|
||||||
|
}
|
||||||
|
|
||||||
|
// `corso restore create exchange [<flag>...]`
|
||||||
|
var exchangeCreateCmd = &cobra.Command{
|
||||||
|
Use: "exchange",
|
||||||
|
Short: "Restore M365 Exchange service data",
|
||||||
|
RunE: createExchangeCmd,
|
||||||
|
Args: cobra.NoArgs,
|
||||||
|
}
|
||||||
|
|
||||||
|
// initializes a s3 repo.
|
||||||
|
func createExchangeCmd(cmd *cobra.Command, args []string) error {
|
||||||
|
s, cfgTenantID, err := config.MakeS3Config(true, nil)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
m365 := credentials.GetM365()
|
||||||
|
a := repository.Account{
|
||||||
|
TenantID: m365.TenantID,
|
||||||
|
ClientID: m365.ClientID,
|
||||||
|
ClientSecret: m365.ClientSecret,
|
||||||
|
}
|
||||||
|
if len(cfgTenantID) > 0 {
|
||||||
|
a.TenantID = cfgTenantID
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf(
|
||||||
|
"Called - %s\n\t365TenantID:\t%s\n\t356Client:\t%s\n\tfound 356Secret:\t%v\n",
|
||||||
|
cmd.CommandPath(),
|
||||||
|
m365.TenantID,
|
||||||
|
m365.ClientID,
|
||||||
|
len(m365.ClientSecret) > 0)
|
||||||
|
|
||||||
|
r, err := repository.Connect(cmd.Context(), a, s)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrapf(err, "Failed to connect to the %s repository", s.Provider)
|
||||||
|
}
|
||||||
|
defer utils.CloseRepo(cmd.Context(), r)
|
||||||
|
|
||||||
|
// todo (keepers): actually restore things
|
||||||
|
|
||||||
|
fmt.Printf("Restored Exchange in %s for user %s.\n", s.Provider, user)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
34
src/cli/restore/restore.go
Normal file
34
src/cli/restore/restore.go
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
package restore
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
var restoreApplications = []func(parent *cobra.Command) *cobra.Command{
|
||||||
|
addExchangeApp,
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddCommands attaches all `corso restore * *` commands to the parent.
|
||||||
|
func AddCommands(parent *cobra.Command) {
|
||||||
|
parent.AddCommand(restoreCmd)
|
||||||
|
|
||||||
|
for _, addRestoreTo := range restoreApplications {
|
||||||
|
addRestoreTo(restoreCmd)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The restore category of commands.
|
||||||
|
// `corso restore [<subcommand>] [<flag>...]`
|
||||||
|
var restoreCmd = &cobra.Command{
|
||||||
|
Use: "restore",
|
||||||
|
Short: "Restore your service data",
|
||||||
|
Long: `Restore the data stored in one of your M365 services.`,
|
||||||
|
Run: handleRestoreCmd,
|
||||||
|
Args: cobra.NoArgs,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handler for flat calls to `corso restore`.
|
||||||
|
// Produces the same output as `corso restore --help`.
|
||||||
|
func handleRestoreCmd(cmd *cobra.Command, args []string) {
|
||||||
|
cmd.Help()
|
||||||
|
}
|
||||||
@ -87,7 +87,7 @@ require (
|
|||||||
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect
|
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect
|
||||||
golang.org/x/net v0.0.0-20220607020251-c690dde0001d // indirect
|
golang.org/x/net v0.0.0-20220607020251-c690dde0001d // indirect
|
||||||
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f // indirect
|
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f // indirect
|
||||||
golang.org/x/sys v0.0.0-20220610221304-9f5ed59c137d // indirect
|
golang.org/x/sys v0.0.0-20220614162138-6c1b26c55098 // indirect
|
||||||
golang.org/x/text v0.3.7 // indirect
|
golang.org/x/text v0.3.7 // indirect
|
||||||
google.golang.org/genproto v0.0.0-20220608133413-ed9918b62aac // indirect
|
google.golang.org/genproto v0.0.0-20220608133413-ed9918b62aac // indirect
|
||||||
google.golang.org/grpc v1.47.0 // indirect
|
google.golang.org/grpc v1.47.0 // indirect
|
||||||
|
|||||||
@ -536,8 +536,8 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
|
|||||||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20220610221304-9f5ed59c137d h1:Zu/JngovGLVi6t2J3nmAf3AoTDwuzw85YZ3b9o4yU7s=
|
golang.org/x/sys v0.0.0-20220614162138-6c1b26c55098 h1:PgOr27OhUx2IRqGJ2RxAWI4dJQ7bi9cSrB82uzFzfUA=
|
||||||
golang.org/x/sys v0.0.0-20220610221304-9f5ed59c137d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220614162138-6c1b26c55098/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||||
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
|
|||||||
@ -5,9 +5,10 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/alcionai/corso/pkg/credentials"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
|
||||||
|
"github.com/alcionai/corso/pkg/credentials"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user