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:
parent
0e6ae32fc3
commit
14205d61e2
@ -242,10 +242,9 @@ func (gc *GraphConnector) ExchangeDataCollection(
|
|||||||
return collections, errs
|
return collections, errs
|
||||||
}
|
}
|
||||||
|
|
||||||
// RestoreExchangeDataCollection: Utility function to connect to M365 backstore
|
// RestoreDataCollections restores data from the specified collections
|
||||||
// and upload messages from DataCollection.
|
// into M365
|
||||||
// FullPath: tenantId, userId, <collectionCategory>, FolderId
|
func (gc *GraphConnector) RestoreDataCollections(
|
||||||
func (gc *GraphConnector) RestoreExchangeDataCollection(
|
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
dcs []data.Collection,
|
dcs []data.Collection,
|
||||||
) error {
|
) error {
|
||||||
@ -276,10 +275,23 @@ func (gc *GraphConnector) RestoreExchangeDataCollection(
|
|||||||
|
|
||||||
category := directory.Category()
|
category := directory.Category()
|
||||||
user := directory.ResourceOwner()
|
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 {
|
if _, ok := pathCounter[directory.String()]; !ok {
|
||||||
pathCounter[directory.String()] = true
|
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 {
|
if errs != nil {
|
||||||
return errs
|
return errs
|
||||||
@ -305,7 +317,10 @@ func (gc *GraphConnector) RestoreExchangeDataCollection(
|
|||||||
continue
|
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 {
|
if err != nil {
|
||||||
errs = support.WrapAndAppend(itemData.UUID(), err, errs)
|
errs = support.WrapAndAppend(itemData.UUID(), err, errs)
|
||||||
|
|||||||
@ -139,7 +139,7 @@ func (op *RestoreOperation) Run(ctx context.Context) (err error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = gc.RestoreExchangeDataCollection(ctx, dcs)
|
err = gc.RestoreDataCollections(ctx, dcs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "restoring service data")
|
err = errors.Wrap(err, "restoring service data")
|
||||||
opStats.writeErr = err
|
opStats.writeErr = err
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user