add sharepoint library restore (#1636)

## Description

adds restore boilerplate for sharepoint libraries.

## Type of change

- [x] 🌻 Feature

## Issue(s)

* #1615

## Test Plan

- [x] 💪 Manual
- [x] 💚 E2E
This commit is contained in:
Keepers 2022-12-05 11:56:33 -07:00 committed by GitHub
parent 8fb55ec886
commit 3918364c40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 85 additions and 6 deletions

View File

@ -303,6 +303,8 @@ func (gc *GraphConnector) RestoreDataCollections(
status, err = exchange.RestoreExchangeDataCollections(ctx, gc.graphService, dest, dcs, deets) status, err = exchange.RestoreExchangeDataCollections(ctx, gc.graphService, dest, dcs, deets)
case selectors.ServiceOneDrive: case selectors.ServiceOneDrive:
status, err = onedrive.RestoreCollections(ctx, gc, dest, dcs, deets) status, err = onedrive.RestoreCollections(ctx, gc, dest, dcs, deets)
case selectors.ServiceSharePoint:
status, err = sharepoint.RestoreCollections(ctx, gc, dest, dcs, deets)
default: default:
err = errors.Errorf("restore data from service %s not supported", selector.Service.String()) err = errors.Errorf("restore data from service %s not supported", selector.Service.String())
} }

View File

@ -134,7 +134,20 @@ func (suite *GraphConnectorIntegrationSuite) TestEmptyCollections() {
Service: selectors.ServiceOneDrive, Service: selectors.ServiceOneDrive,
}, },
}, },
// TODO: SharePoint {
name: "SharePointNil",
col: nil,
sel: selectors.Selector{
Service: selectors.ServiceSharePoint,
},
},
{
name: "SharePointEmpty",
col: []data.Collection{},
sel: selectors.Selector{
Service: selectors.ServiceSharePoint,
},
},
} }
for _, test := range table { for _, test := range table {

View File

@ -66,7 +66,7 @@ func RestoreCollections(
// Iterate through the data collections and restore the contents of each // Iterate through the data collections and restore the contents of each
for _, dc := range dcs { for _, dc := range dcs {
temp, canceled := restoreCollection(ctx, service, dc, dest.ContainerName, deets, errUpdater) temp, canceled := RestoreCollection(ctx, service, dc, dest.ContainerName, deets, errUpdater)
restoreMetrics.Combine(temp) restoreMetrics.Combine(temp)
@ -85,10 +85,11 @@ func RestoreCollections(
nil nil
} }
// restoreCollection handles restoration of an individual collection. // RestoreCollection handles restoration of an individual collection.
// @returns Integer representing totalItems, restoredItems, and the // returns:
// amount of bytes restored. The bool represents whether the context was cancelled // - the collection's item and byte count metrics
func restoreCollection( // - the context cancellation state (true if the context is cancelled)
func RestoreCollection(
ctx context.Context, ctx context.Context,
service graph.Service, service graph.Service,
dc data.Collection, dc data.Collection,

View File

@ -0,0 +1,63 @@
package sharepoint
import (
"context"
"github.com/pkg/errors"
"github.com/alcionai/corso/src/internal/connector/graph"
"github.com/alcionai/corso/src/internal/connector/onedrive"
"github.com/alcionai/corso/src/internal/connector/support"
"github.com/alcionai/corso/src/internal/data"
"github.com/alcionai/corso/src/pkg/backup/details"
"github.com/alcionai/corso/src/pkg/control"
"github.com/alcionai/corso/src/pkg/path"
)
// RestoreCollections will restore the specified data collections into OneDrive
func RestoreCollections(
ctx context.Context,
service graph.Service,
dest control.RestoreDestination,
dcs []data.Collection,
deets *details.Details,
) (*support.ConnectorOperationStatus, error) {
var (
restoreMetrics support.CollectionMetrics
restoreErrors error
)
errUpdater := func(id string, err error) {
restoreErrors = support.WrapAndAppend(id, err, restoreErrors)
}
// Iterate through the data collections and restore the contents of each
for _, dc := range dcs {
var (
metrics support.CollectionMetrics
canceled bool
)
switch dc.FullPath().Category() {
case path.LibrariesCategory:
metrics, canceled = onedrive.RestoreCollection(ctx, service, dc, dest.ContainerName, deets, errUpdater)
default:
return nil, errors.Errorf("category %s not supported", dc.FullPath().Category())
}
restoreMetrics.Combine(metrics)
if canceled {
break
}
}
return support.CreateStatus(
ctx,
support.Restore,
len(dcs),
restoreMetrics,
restoreErrors,
dest.ContainerName),
nil
}