Add the backup list command to the cli (#254)

* Add the backup list command to the cli

Adds `corso backup list <service>` to the cli commands.
Currently does nothing, while we're waiting on
downstream implementation.  e2e hookup will arrive later.
This commit is contained in:
Keepers 2022-06-30 09:30:37 -06:00 committed by GitHub
parent abc8b44718
commit ce52cc5f41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 81 additions and 14 deletions

View File

@ -12,9 +12,11 @@ var backupApplications = []func(parent *cobra.Command) *cobra.Command{
func AddCommands(parent *cobra.Command) {
parent.AddCommand(backupCmd)
backupCmd.AddCommand(createCmd)
backupCmd.AddCommand(listCmd)
for _, addBackupTo := range backupApplications {
addBackupTo(createCmd)
addBackupTo(listCmd)
}
}
@ -49,3 +51,19 @@ var createCmd = &cobra.Command{
func handleCreateCmd(cmd *cobra.Command, args []string) {
cmd.Help()
}
// The backup list subcommand.
// `corso backup list <service> [<flag>...]`
var listCommand = "list"
var listCmd = &cobra.Command{
Use: listCommand,
Short: "List the history of restore points for a service",
Run: handleListCmd,
Args: cobra.NoArgs,
}
// Handler for calls to `corso backup list`.
// Produces the same output as `corso backup list --help`.
func handleListCmd(cmd *cobra.Command, args []string) {
cmd.Help()
}

View File

@ -5,6 +5,7 @@ import (
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/alcionai/corso/cli/config"
"github.com/alcionai/corso/cli/utils"
@ -19,20 +20,25 @@ var (
// called by backup.go to map parent subcommands to provider-specific handling.
func addExchangeApp(parent *cobra.Command) *cobra.Command {
var c *cobra.Command
var (
c *cobra.Command
fs *pflag.FlagSet
)
switch parent.Use {
case createCommand:
c = exchangeCreateCmd
c, fs = utils.AddCommand(parent, exchangeCreateCmd)
fs.StringVar(&user, "user", "", "ID of the user whose Exchange data is to be backed up.")
case listCommand:
c, _ = utils.AddCommand(parent, exchangeListCmd)
}
parent.AddCommand(c)
fs := c.Flags()
fs.StringVar(&user, "user", "", "ID of the user whose Exchange data is to be backed up.")
return c
}
const exchangeServiceCommand = "exchange"
// `corso backup create exchange [<flag>...]`
var exchangeCreateCmd = &cobra.Command{
Use: "exchange",
Use: exchangeServiceCommand,
Short: "Backup M365 Exchange service data",
RunE: createExchangeCmd,
Args: cobra.NoArgs,
@ -81,3 +87,34 @@ func createExchangeCmd(cmd *cobra.Command, args []string) error {
fmt.Printf("Backed up restore point %s in %s for Exchange user %s.\n", result.SnapshotID, s.Provider, user)
return nil
}
// `corso backup list exchange [<flag>...]`
var exchangeListCmd = &cobra.Command{
Use: exchangeServiceCommand,
Short: "List the history of M365 Exchange service backups",
RunE: listExchangeCmd,
Args: cobra.NoArgs,
}
// lists the history of backup operations
func listExchangeCmd(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
_, acct, err := config.GetStorageAndAccount(true, nil)
if err != nil {
return err
}
m365, err := acct.M365Config()
if err != nil {
return errors.Wrap(err, "Failed to parse m365 account config")
}
logger.Ctx(ctx).Debugw(
"Called - "+cmd.CommandPath(),
"tenantID", m365.TenantID)
// todo (keepers issue #251): e2e hookup
return nil
}

View File

@ -5,6 +5,7 @@ import (
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/alcionai/corso/cli/config"
"github.com/alcionai/corso/cli/utils"
@ -24,15 +25,16 @@ var (
// called by repo.go to map parent subcommands to provider-specific handling.
func addS3Commands(parent *cobra.Command) *cobra.Command {
var c *cobra.Command
var (
c *cobra.Command
fs *pflag.FlagSet
)
switch parent.Use {
case initCommand:
c = s3InitCmd
c, fs = utils.AddCommand(parent, s3InitCmd)
case connectCommand:
c = s3ConnectCmd
c, fs = utils.AddCommand(parent, s3ConnectCmd)
}
parent.AddCommand(c)
fs := c.Flags()
fs.StringVar(&accessKey, "access-key", "", "Access key ID (replaces the AWS_ACCESS_KEY_ID env variable).")
fs.StringVar(&bucket, "bucket", "", "Name of the S3 bucket (required).")
c.MarkFlagRequired("bucket")
@ -41,9 +43,11 @@ func addS3Commands(parent *cobra.Command) *cobra.Command {
return c
}
const s3ProviderCommand = "s3"
// `corso repo init s3 [<flag>...]`
var s3InitCmd = &cobra.Command{
Use: "s3",
Use: s3ProviderCommand,
Short: "Initialize a S3 repository",
Long: `Bootstraps a new S3 repository and connects it to your m356 account.`,
RunE: initS3Cmd,
@ -103,7 +107,7 @@ func initS3Cmd(cmd *cobra.Command, args []string) error {
// `corso repo connect s3 [<flag>...]`
var s3ConnectCmd = &cobra.Command{
Use: "s3",
Use: s3ProviderCommand,
Short: "Connect to a S3 repository",
Long: `Ensures a connection to an existing S3 repository.`,
RunE: connectS3Cmd,

View File

@ -7,6 +7,7 @@ import (
"github.com/alcionai/corso/pkg/repository"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
// RequireProps validates the existence of the properties
@ -39,3 +40,10 @@ func HasNoFlagsAndShownHelp(cmd *cobra.Command) bool {
}
return false
}
// AddCommand adds the subCommand to the parent, and returns
// both the subCommand and its pflags.
func AddCommand(parent, c *cobra.Command) (*cobra.Command, *pflag.FlagSet) {
parent.AddCommand(c)
return c, c.Flags()
}

View File

@ -16,6 +16,7 @@ require (
github.com/microsoftgraph/msgraph-sdk-go-core v0.26.1
github.com/pkg/errors v0.9.1
github.com/spf13/cobra v1.4.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.12.0
github.com/stretchr/testify v1.7.2
go.uber.org/zap v1.21.0
@ -77,7 +78,6 @@ require (
github.com/prometheus/procfs v0.7.3 // indirect
github.com/rs/xid v1.4.0 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/yosida95/uritemplate/v3 v3.0.2 // indirect
github.com/zeebo/blake3 v0.2.3 // indirect
go.opentelemetry.io/otel v1.7.0 // indirect