GC: Backup: Sharepoint libraries to omit site drive. (#2098)
## Description Branch treats Drive `Site Pages` as a restricted directory. All `pages` within the directory, will be backed up via the Site Pages API. This adds an additional call to per collection to obtain the parent `driveName`. <!-- Insert PR description--> TODO: Create a Pipeline that distinguishes between SitePages, Libraries, and List for SharePoint ## Does this PR need a docs update or release note? - [x] 🕐 Yes, but in a later PR The documentation should state the assumption is that only `.aspx` files are to be found in the s ## Type of change <!--- Please check the type of change your PR introduces: ---> - [x] 🌻 Feature ## Issue(s) <!-- Can reference multiple issues. Use one of the following "magic words" - "closes, fixes" to auto-close the Github issue. --> * closes #2072<issue> ## Test Plan - [x] ⚡ Unit test
This commit is contained in:
parent
9f185a9b41
commit
936789b6b4
@ -24,6 +24,7 @@ const (
|
|||||||
OneDriveSource
|
OneDriveSource
|
||||||
SharePointSource
|
SharePointSource
|
||||||
)
|
)
|
||||||
|
const restrictedDirectory = "Site Pages"
|
||||||
|
|
||||||
func (ds driveSource) toPathServiceCat() (path.ServiceType, path.CategoryType) {
|
func (ds driveSource) toPathServiceCat() (path.ServiceType, path.CategoryType) {
|
||||||
switch ds {
|
switch ds {
|
||||||
@ -102,8 +103,9 @@ func (c *Collections) Get(ctx context.Context) ([]data.Collection, error) {
|
|||||||
// Update the collection map with items from each drive
|
// Update the collection map with items from each drive
|
||||||
for _, d := range drives {
|
for _, d := range drives {
|
||||||
driveID := *d.GetId()
|
driveID := *d.GetId()
|
||||||
|
driveName := *d.GetName()
|
||||||
|
|
||||||
delta, paths, err := collectItems(ctx, c.service, driveID, c.UpdateCollections)
|
delta, paths, err := collectItems(ctx, c.service, driveID, driveName, c.UpdateCollections)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -162,7 +164,7 @@ func (c *Collections) Get(ctx context.Context) ([]data.Collection, error) {
|
|||||||
// A new collection is created for every drive folder (or package)
|
// A new collection is created for every drive folder (or package)
|
||||||
func (c *Collections) UpdateCollections(
|
func (c *Collections) UpdateCollections(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
driveID string,
|
driveID, driveName string,
|
||||||
items []models.DriveItemable,
|
items []models.DriveItemable,
|
||||||
paths map[string]string,
|
paths map[string]string,
|
||||||
) error {
|
) error {
|
||||||
@ -188,7 +190,7 @@ func (c *Collections) UpdateCollections(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Skip items that don't match the folder selectors we were given.
|
// Skip items that don't match the folder selectors we were given.
|
||||||
if !includePath(ctx, c.matcher, collectionPath) {
|
if shouldSkipDrive(ctx, collectionPath, c.matcher, driveName) {
|
||||||
logger.Ctx(ctx).Infof("Skipping path %s", collectionPath.String())
|
logger.Ctx(ctx).Infof("Skipping path %s", collectionPath.String())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -239,6 +241,11 @@ func (c *Collections) UpdateCollections(
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func shouldSkipDrive(ctx context.Context, drivePath path.Path, m folderMatcher, driveName string) bool {
|
||||||
|
return !includePath(ctx, m, drivePath) ||
|
||||||
|
(drivePath.Category() == path.LibrariesCategory && restrictedDirectory == driveName)
|
||||||
|
}
|
||||||
|
|
||||||
// GetCanonicalPath constructs the standard path for the given source.
|
// GetCanonicalPath constructs the standard path for the given source.
|
||||||
func GetCanonicalPath(p, tenant, resourceOwner string, source driveSource) (path.Path, error) {
|
func GetCanonicalPath(p, tenant, resourceOwner string, source driveSource) (path.Path, error) {
|
||||||
var (
|
var (
|
||||||
|
|||||||
@ -326,7 +326,7 @@ func (suite *OneDriveCollectionsSuite) TestUpdateCollections() {
|
|||||||
nil,
|
nil,
|
||||||
control.Options{})
|
control.Options{})
|
||||||
|
|
||||||
err := c.UpdateCollections(ctx, "driveID", tt.items, paths)
|
err := c.UpdateCollections(ctx, "driveID", "General", tt.items, paths)
|
||||||
tt.expect(t, err)
|
tt.expect(t, err)
|
||||||
assert.Equal(t, len(tt.expectedCollectionPaths), len(c.CollectionMap), "collection paths")
|
assert.Equal(t, len(tt.expectedCollectionPaths), len(c.CollectionMap), "collection paths")
|
||||||
assert.Equal(t, tt.expectedItemCount, c.NumItems, "item count")
|
assert.Equal(t, tt.expectedItemCount, c.NumItems, "item count")
|
||||||
|
|||||||
@ -163,7 +163,7 @@ func userDrives(ctx context.Context, service graph.Servicer, user string) ([]mod
|
|||||||
// itemCollector functions collect the items found in a drive
|
// itemCollector functions collect the items found in a drive
|
||||||
type itemCollector func(
|
type itemCollector func(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
driveID string,
|
driveID, driveName string,
|
||||||
driveItems []models.DriveItemable,
|
driveItems []models.DriveItemable,
|
||||||
paths map[string]string,
|
paths map[string]string,
|
||||||
) error
|
) error
|
||||||
@ -173,7 +173,7 @@ type itemCollector func(
|
|||||||
func collectItems(
|
func collectItems(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
service graph.Servicer,
|
service graph.Servicer,
|
||||||
driveID string,
|
driveID, driveName string,
|
||||||
collector itemCollector,
|
collector itemCollector,
|
||||||
) (string, map[string]string, error) {
|
) (string, map[string]string, error) {
|
||||||
var (
|
var (
|
||||||
@ -219,7 +219,7 @@ func collectItems(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = collector(ctx, driveID, r.GetValue(), paths)
|
err = collector(ctx, driveID, driveName, r.GetValue(), paths)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", nil, err
|
return "", nil, err
|
||||||
}
|
}
|
||||||
@ -349,9 +349,10 @@ func GetAllFolders(
|
|||||||
ctx,
|
ctx,
|
||||||
gs,
|
gs,
|
||||||
*d.GetId(),
|
*d.GetId(),
|
||||||
|
*d.GetName(),
|
||||||
func(
|
func(
|
||||||
innerCtx context.Context,
|
innerCtx context.Context,
|
||||||
driveID string,
|
driveID, driveName string,
|
||||||
items []models.DriveItemable,
|
items []models.DriveItemable,
|
||||||
paths map[string]string,
|
paths map[string]string,
|
||||||
) error {
|
) error {
|
||||||
|
|||||||
@ -97,7 +97,7 @@ func (suite *ItemIntegrationSuite) TestItemReader_oneDrive() {
|
|||||||
// This item collector tries to find "a" drive item that is a file to test the reader function
|
// This item collector tries to find "a" drive item that is a file to test the reader function
|
||||||
itemCollector := func(
|
itemCollector := func(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
driveID string,
|
driveID, driveName string,
|
||||||
items []models.DriveItemable,
|
items []models.DriveItemable,
|
||||||
paths map[string]string,
|
paths map[string]string,
|
||||||
) error {
|
) error {
|
||||||
@ -110,7 +110,7 @@ func (suite *ItemIntegrationSuite) TestItemReader_oneDrive() {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
_, _, err := collectItems(ctx, suite, suite.userDriveID, itemCollector)
|
_, _, err := collectItems(ctx, suite, suite.userDriveID, "General", itemCollector)
|
||||||
require.NoError(suite.T(), err)
|
require.NoError(suite.T(), err)
|
||||||
|
|
||||||
// Test Requirement 2: Need a file
|
// Test Requirement 2: Need a file
|
||||||
|
|||||||
@ -96,7 +96,7 @@ func (suite *SharePointLibrariesSuite) TestUpdateCollections() {
|
|||||||
&MockGraphService{},
|
&MockGraphService{},
|
||||||
nil,
|
nil,
|
||||||
control.Options{})
|
control.Options{})
|
||||||
err := c.UpdateCollections(ctx, "driveID", test.items, paths)
|
err := c.UpdateCollections(ctx, "driveID", "General", test.items, paths)
|
||||||
test.expect(t, err)
|
test.expect(t, err)
|
||||||
assert.Equal(t, len(test.expectedCollectionPaths), len(c.CollectionMap), "collection paths")
|
assert.Equal(t, len(test.expectedCollectionPaths), len(c.CollectionMap), "collection paths")
|
||||||
assert.Equal(t, test.expectedItemCount, c.NumItems, "item count")
|
assert.Equal(t, test.expectedItemCount, c.NumItems, "item count")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user