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:
parent
8fb55ec886
commit
3918364c40
@ -303,6 +303,8 @@ func (gc *GraphConnector) RestoreDataCollections(
|
||||
status, err = exchange.RestoreExchangeDataCollections(ctx, gc.graphService, dest, dcs, deets)
|
||||
case selectors.ServiceOneDrive:
|
||||
status, err = onedrive.RestoreCollections(ctx, gc, dest, dcs, deets)
|
||||
case selectors.ServiceSharePoint:
|
||||
status, err = sharepoint.RestoreCollections(ctx, gc, dest, dcs, deets)
|
||||
default:
|
||||
err = errors.Errorf("restore data from service %s not supported", selector.Service.String())
|
||||
}
|
||||
|
||||
@ -134,7 +134,20 @@ func (suite *GraphConnectorIntegrationSuite) TestEmptyCollections() {
|
||||
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 {
|
||||
|
||||
@ -66,7 +66,7 @@ func RestoreCollections(
|
||||
|
||||
// Iterate through the data collections and restore the contents of each
|
||||
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)
|
||||
|
||||
@ -85,10 +85,11 @@ func RestoreCollections(
|
||||
nil
|
||||
}
|
||||
|
||||
// restoreCollection handles restoration of an individual collection.
|
||||
// @returns Integer representing totalItems, restoredItems, and the
|
||||
// amount of bytes restored. The bool represents whether the context was cancelled
|
||||
func restoreCollection(
|
||||
// RestoreCollection handles restoration of an individual collection.
|
||||
// returns:
|
||||
// - the collection's item and byte count metrics
|
||||
// - the context cancellation state (true if the context is cancelled)
|
||||
func RestoreCollection(
|
||||
ctx context.Context,
|
||||
service graph.Service,
|
||||
dc data.Collection,
|
||||
|
||||
63
src/internal/connector/sharepoint/restore.go
Normal file
63
src/internal/connector/sharepoint/restore.go
Normal 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
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user