hook up restore cli to repository restore runner (#219)
Introduces a NewRestore method to the Repository struct. cli/restore/exchange now generates a restoreOperation and kicks off a Run() when `corso restore exchange` is called. The restore operation still only accepts the placeholder Target string slice.
This commit is contained in:
parent
64477712c5
commit
ccb3fa46a3
@ -78,7 +78,14 @@ func createExchangeCmd(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
defer utils.CloseRepo(cmd.Context(), r)
|
||||
|
||||
// todo (keepers): actually restore things
|
||||
ro, err := r.NewRestore(cmd.Context(), []string{user, folder, mail})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Failed to initialize Exchange restore")
|
||||
}
|
||||
|
||||
if _, err := ro.Run(cmd.Context()); err != nil {
|
||||
return errors.Wrap(err, "Failed to run Exchange restore")
|
||||
}
|
||||
|
||||
fmt.Printf("Restored Exchange in %s for user %s.\n", s.Provider, user)
|
||||
return nil
|
||||
|
||||
@ -111,3 +111,18 @@ func (r Repository) NewBackup(ctx context.Context, targets []string) (operations
|
||||
creds,
|
||||
targets)
|
||||
}
|
||||
|
||||
// NewRestore generates a restoreOperation runner.
|
||||
func (r Repository) NewRestore(ctx context.Context, targets []string) (operations.RestoreOperation, error) {
|
||||
creds := credentials.M365{
|
||||
ClientID: r.Account.ClientID,
|
||||
ClientSecret: r.Account.ClientSecret,
|
||||
TenantID: r.Account.TenantID,
|
||||
}
|
||||
return operations.NewRestoreOperation(
|
||||
ctx,
|
||||
operations.OperationOpts{},
|
||||
r.dataLayer,
|
||||
creds,
|
||||
targets)
|
||||
}
|
||||
|
||||
@ -9,6 +9,7 @@ import (
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
ctesting "github.com/alcionai/corso/internal/testing"
|
||||
"github.com/alcionai/corso/pkg/credentials"
|
||||
"github.com/alcionai/corso/pkg/repository"
|
||||
"github.com/alcionai/corso/pkg/storage"
|
||||
)
|
||||
@ -114,9 +115,9 @@ func (suite *RepositoryIntegrationSuite) TestInitialize() {
|
||||
errCheck assert.ErrorAssertionFunc
|
||||
}{
|
||||
{
|
||||
prefix: "init-s3-" + timeOfTest,
|
||||
prefix: "repository-init-s3-" + timeOfTest,
|
||||
storage: func() (storage.Storage, error) {
|
||||
return ctesting.NewS3Storage("init-s3-" + timeOfTest)
|
||||
return ctesting.NewS3Storage("repository-init-s3-" + timeOfTest)
|
||||
},
|
||||
errCheck: assert.NoError,
|
||||
},
|
||||
@ -141,7 +142,7 @@ func (suite *RepositoryIntegrationSuite) TestConnect() {
|
||||
t := suite.T()
|
||||
ctx := context.Background()
|
||||
timeOfTest := ctesting.LogTimeOfTest(t)
|
||||
prefix := "conn-s3-" + timeOfTest
|
||||
prefix := "repository-conn-s3-" + timeOfTest
|
||||
|
||||
// need to initialize the repository before we can test connecting to it.
|
||||
st, err := ctesting.NewS3Storage(prefix)
|
||||
@ -154,3 +155,53 @@ func (suite *RepositoryIntegrationSuite) TestConnect() {
|
||||
_, err = repository.Connect(ctx, repository.Account{}, st)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func (suite *RepositoryIntegrationSuite) TestNewBackup() {
|
||||
t := suite.T()
|
||||
ctx := context.Background()
|
||||
timeOfTest := ctesting.LogTimeOfTest(t)
|
||||
prefix := "repository-new-backup-" + timeOfTest
|
||||
|
||||
m365 := credentials.GetM365()
|
||||
acct := repository.Account{
|
||||
ClientID: m365.ClientID,
|
||||
ClientSecret: m365.ClientSecret,
|
||||
TenantID: m365.TenantID,
|
||||
}
|
||||
|
||||
// need to initialize the repository before we can test connecting to it.
|
||||
st, err := ctesting.NewS3Storage(prefix)
|
||||
require.NoError(t, err)
|
||||
|
||||
r, err := repository.Initialize(ctx, acct, st)
|
||||
require.NoError(t, err)
|
||||
|
||||
bo, err := r.NewBackup(ctx, []string{})
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, bo)
|
||||
}
|
||||
|
||||
func (suite *RepositoryIntegrationSuite) TestNewRestore() {
|
||||
t := suite.T()
|
||||
ctx := context.Background()
|
||||
timeOfTest := ctesting.LogTimeOfTest(t)
|
||||
prefix := "repository-new-restore-" + timeOfTest
|
||||
|
||||
m365 := credentials.GetM365()
|
||||
acct := repository.Account{
|
||||
ClientID: m365.ClientID,
|
||||
ClientSecret: m365.ClientSecret,
|
||||
TenantID: m365.TenantID,
|
||||
}
|
||||
|
||||
// need to initialize the repository before we can test connecting to it.
|
||||
st, err := ctesting.NewS3Storage(prefix)
|
||||
require.NoError(t, err)
|
||||
|
||||
r, err := repository.Initialize(ctx, acct, st)
|
||||
require.NoError(t, err)
|
||||
|
||||
ro, err := r.NewRestore(ctx, []string{})
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, ro)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user