diff --git a/src/cli/backup/exchange_integration_test.go b/src/cli/backup/exchange_integration_test.go index 31e56f53e..8a61a118d 100644 --- a/src/cli/backup/exchange_integration_test.go +++ b/src/cli/backup/exchange_integration_test.go @@ -42,7 +42,7 @@ type BackupExchangeIntegrationSuite struct { st storage.Storage vpr *viper.Viper cfgFP string - repo *repository.Repository + repo repository.Repository m365UserID string } @@ -131,7 +131,7 @@ type PreparedBackupExchangeIntegrationSuite struct { st storage.Storage vpr *viper.Viper cfgFP string - repo *repository.Repository + repo repository.Repository m365UserID string backupOps map[path.CategoryType]operations.BackupOperation } @@ -303,7 +303,7 @@ type BackupDeleteExchangeIntegrationSuite struct { st storage.Storage vpr *viper.Viper cfgFP string - repo *repository.Repository + repo repository.Repository backupOp operations.BackupOperation } diff --git a/src/cli/restore/exchange_integration_test.go b/src/cli/restore/exchange_integration_test.go index 62e5368a5..6135cdbb3 100644 --- a/src/cli/restore/exchange_integration_test.go +++ b/src/cli/restore/exchange_integration_test.go @@ -39,7 +39,7 @@ type RestoreExchangeIntegrationSuite struct { st storage.Storage vpr *viper.Viper cfgFP string - repo *repository.Repository + repo repository.Repository m365UserID string backupOps map[path.CategoryType]operations.BackupOperation } diff --git a/src/cli/utils/utils.go b/src/cli/utils/utils.go index 7d3adba24..23149b707 100644 --- a/src/cli/utils/utils.go +++ b/src/cli/utils/utils.go @@ -28,7 +28,7 @@ func RequireProps(props map[string]string) error { } // CloseRepo handles closing a repo. -func CloseRepo(ctx context.Context, r *repository.Repository) { +func CloseRepo(ctx context.Context, r repository.Repository) { if err := r.Close(ctx); err != nil { fmt.Print("Error closing repository:", err) } diff --git a/src/pkg/repository/repository.go b/src/pkg/repository/repository.go index e072a9cdb..f2bc96b2e 100644 --- a/src/pkg/repository/repository.go +++ b/src/pkg/repository/repository.go @@ -20,8 +20,34 @@ import ( "github.com/alcionai/corso/src/pkg/store" ) +// BackupGetter deals with retrieving metadata about backups from the +// repository. +type BackupGetter interface { + Backup(ctx context.Context, id model.StableID) (*backup.Backup, error) + Backups(ctx context.Context) ([]backup.Backup, error) + BackupDetails( + ctx context.Context, + backupID string, + ) (*details.Details, *backup.Backup, error) +} + +type Repository interface { + Close(context.Context) error + NewBackup( + ctx context.Context, + self selectors.Selector, + ) (operations.BackupOperation, error) + NewRestore( + ctx context.Context, + backupID string, + sel selectors.Selector, + ) (operations.RestoreOperation, error) + DeleteBackup(ctx context.Context, id model.StableID) error + BackupGetter +} + // Repository contains storage provider information. -type Repository struct { +type repository struct { ID uuid.UUID CreatedAt time.Time Version string // in case of future breaking changes @@ -48,7 +74,7 @@ func Initialize( acct account.Account, s storage.Storage, opts control.Options, -) (*Repository, error) { +) (Repository, error) { kopiaRef := kopia.NewConn(s) if err := kopiaRef.Initialize(ctx); err != nil { return nil, err @@ -67,7 +93,7 @@ func Initialize( return nil, err } - r := Repository{ + r := repository{ ID: uuid.New(), Version: "v1", Account: acct, @@ -92,7 +118,7 @@ func Connect( acct account.Account, s storage.Storage, opts control.Options, -) (*Repository, error) { +) (Repository, error) { kopiaRef := kopia.NewConn(s) if err := kopiaRef.Connect(ctx); err != nil { return nil, err @@ -112,7 +138,7 @@ func Connect( } // todo: ID and CreatedAt should get retrieved from a stored kopia config. - r := Repository{ + r := repository{ Version: "v1", Account: acct, Storage: s, @@ -124,7 +150,7 @@ func Connect( return &r, nil } -func (r *Repository) Close(ctx context.Context) error { +func (r *repository) Close(ctx context.Context) error { if err := r.Bus.Close(); err != nil { logger.Ctx(ctx).Debugw("closing the event bus", "err", err) } @@ -149,7 +175,7 @@ func (r *Repository) Close(ctx context.Context) error { } // NewBackup generates a BackupOperation runner. -func (r Repository) NewBackup( +func (r repository) NewBackup( ctx context.Context, selector selectors.Selector, ) (operations.BackupOperation, error) { @@ -164,7 +190,7 @@ func (r Repository) NewBackup( } // NewRestore generates a restoreOperation runner. -func (r Repository) NewRestore( +func (r repository) NewRestore( ctx context.Context, backupID string, sel selectors.Selector, @@ -181,25 +207,25 @@ func (r Repository) NewRestore( } // backups lists a backup by id -func (r Repository) Backup(ctx context.Context, id model.StableID) (*backup.Backup, error) { +func (r repository) Backup(ctx context.Context, id model.StableID) (*backup.Backup, error) { sw := store.NewKopiaStore(r.modelStore) return sw.GetBackup(ctx, id) } // backups lists backups in a repository -func (r Repository) Backups(ctx context.Context) ([]backup.Backup, error) { +func (r repository) Backups(ctx context.Context) ([]backup.Backup, error) { sw := store.NewKopiaStore(r.modelStore) return sw.GetBackups(ctx) } // BackupDetails returns the specified backup details object -func (r Repository) BackupDetails(ctx context.Context, backupID string) (*details.Details, *backup.Backup, error) { +func (r repository) BackupDetails(ctx context.Context, backupID string) (*details.Details, *backup.Backup, error) { sw := store.NewKopiaStore(r.modelStore) return sw.GetDetailsFromBackupID(ctx, model.StableID(backupID)) } // DeleteBackup removes the backup from both the model store and the backup storage. -func (r Repository) DeleteBackup(ctx context.Context, id model.StableID) error { +func (r repository) DeleteBackup(ctx context.Context, id model.StableID) error { bu, err := r.Backup(ctx, id) if err != nil { return err diff --git a/src/pkg/repository/repository_load_test.go b/src/pkg/repository/repository_load_test.go index 6904813f7..0e3864921 100644 --- a/src/pkg/repository/repository_load_test.go +++ b/src/pkg/repository/repository_load_test.go @@ -16,7 +16,7 @@ import ( ) func initM365Repo(t *testing.T) ( - context.Context, *repository.Repository, account.Account, storage.Storage, + context.Context, repository.Repository, account.Account, storage.Storage, ) { _, err := tester.GetRequiredEnvSls( tester.AWSStorageCredEnvs, @@ -45,7 +45,7 @@ func initM365Repo(t *testing.T) ( type RepositoryLoadTestExchangeSuite struct { suite.Suite ctx context.Context - repo *repository.Repository + repo repository.Repository acct account.Account st storage.Storage } @@ -99,7 +99,7 @@ func (suite *RepositoryLoadTestExchangeSuite) TestExchange() { type RepositoryLoadTestOneDriveSuite struct { suite.Suite ctx context.Context - repo *repository.Repository + repo repository.Repository acct account.Account st storage.Storage }