Refactor restore helper (#838)

## Description

Small refactor of the data collection restore helper so that we can plug-in the OneDrive helpers in a 
follow-up PR

## Type of change

<!--- Please check the type of change your PR introduces: --->
- [ ] 🌻 Feature
- [ ] 🐛 Bugfix
- [ ] 🗺️ Documentation
- [ ] 🤖 Test
- [ ] 💻 CI/Deployment
- [x] 🐹 Trivial/Minor

## Test Plan

<!-- How will this be tested prior to merging.-->
- [ ] 💪 Manual
- [ ]  Unit test
- [x] 💚 E2E
This commit is contained in:
Vaibhav Kamra 2022-09-13 17:14:27 -07:00 committed by GitHub
parent 0e6ae32fc3
commit 14205d61e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 7 deletions

View File

@ -242,10 +242,9 @@ func (gc *GraphConnector) ExchangeDataCollection(
return collections, errs
}
// RestoreExchangeDataCollection: Utility function to connect to M365 backstore
// and upload messages from DataCollection.
// FullPath: tenantId, userId, <collectionCategory>, FolderId
func (gc *GraphConnector) RestoreExchangeDataCollection(
// RestoreDataCollections restores data from the specified collections
// into M365
func (gc *GraphConnector) RestoreDataCollections(
ctx context.Context,
dcs []data.Collection,
) error {
@ -276,10 +275,23 @@ func (gc *GraphConnector) RestoreExchangeDataCollection(
category := directory.Category()
user := directory.ResourceOwner()
service := directory.Service()
// Check whether restoring data into the specified service is supported
switch service {
case path.ExchangeService:
// Supported
default:
return errors.Errorf("restore data from service %s not supported", service.String())
}
if _, ok := pathCounter[directory.String()]; !ok {
pathCounter[directory.String()] = true
folderID, errs = exchange.GetRestoreContainer(&gc.graphService, user, category)
switch service {
case path.ExchangeService:
folderID, errs = exchange.GetRestoreContainer(&gc.graphService, user, category)
}
if errs != nil {
return errs
@ -305,7 +317,10 @@ func (gc *GraphConnector) RestoreExchangeDataCollection(
continue
}
err = exchange.RestoreExchangeObject(ctx, buf.Bytes(), category, policy, &gc.graphService, folderID, user)
switch service {
case path.ExchangeService:
err = exchange.RestoreExchangeObject(ctx, buf.Bytes(), category, policy, &gc.graphService, folderID, user)
}
if err != nil {
errs = support.WrapAndAppend(itemData.UUID(), err, errs)

View File

@ -139,7 +139,7 @@ func (op *RestoreOperation) Run(ctx context.Context) (err error) {
return err
}
err = gc.RestoreExchangeDataCollection(ctx, dcs)
err = gc.RestoreDataCollections(ctx, dcs)
if err != nil {
err = errors.Wrap(err, "restoring service data")
opStats.writeErr = err