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:
Danny 2023-01-18 22:19:15 -05:00 committed by GitHub
parent 9f185a9b41
commit 936789b6b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 11 deletions

View File

@ -24,6 +24,7 @@ const (
OneDriveSource
SharePointSource
)
const restrictedDirectory = "Site Pages"
func (ds driveSource) toPathServiceCat() (path.ServiceType, path.CategoryType) {
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
for _, d := range drives {
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 {
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)
func (c *Collections) UpdateCollections(
ctx context.Context,
driveID string,
driveID, driveName string,
items []models.DriveItemable,
paths map[string]string,
) error {
@ -188,7 +190,7 @@ func (c *Collections) UpdateCollections(
}
// 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())
continue
}
@ -239,6 +241,11 @@ func (c *Collections) UpdateCollections(
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.
func GetCanonicalPath(p, tenant, resourceOwner string, source driveSource) (path.Path, error) {
var (

View File

@ -326,7 +326,7 @@ func (suite *OneDriveCollectionsSuite) TestUpdateCollections() {
nil,
control.Options{})
err := c.UpdateCollections(ctx, "driveID", tt.items, paths)
err := c.UpdateCollections(ctx, "driveID", "General", tt.items, paths)
tt.expect(t, err)
assert.Equal(t, len(tt.expectedCollectionPaths), len(c.CollectionMap), "collection paths")
assert.Equal(t, tt.expectedItemCount, c.NumItems, "item count")

View File

@ -163,7 +163,7 @@ func userDrives(ctx context.Context, service graph.Servicer, user string) ([]mod
// itemCollector functions collect the items found in a drive
type itemCollector func(
ctx context.Context,
driveID string,
driveID, driveName string,
driveItems []models.DriveItemable,
paths map[string]string,
) error
@ -173,7 +173,7 @@ type itemCollector func(
func collectItems(
ctx context.Context,
service graph.Servicer,
driveID string,
driveID, driveName string,
collector itemCollector,
) (string, map[string]string, error) {
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 {
return "", nil, err
}
@ -349,9 +349,10 @@ func GetAllFolders(
ctx,
gs,
*d.GetId(),
*d.GetName(),
func(
innerCtx context.Context,
driveID string,
driveID, driveName string,
items []models.DriveItemable,
paths map[string]string,
) error {

View File

@ -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
itemCollector := func(
ctx context.Context,
driveID string,
driveID, driveName string,
items []models.DriveItemable,
paths map[string]string,
) error {
@ -110,7 +110,7 @@ func (suite *ItemIntegrationSuite) TestItemReader_oneDrive() {
return nil
}
_, _, err := collectItems(ctx, suite, suite.userDriveID, itemCollector)
_, _, err := collectItems(ctx, suite, suite.userDriveID, "General", itemCollector)
require.NoError(suite.T(), err)
// Test Requirement 2: Need a file

View File

@ -96,7 +96,7 @@ func (suite *SharePointLibrariesSuite) TestUpdateCollections() {
&MockGraphService{},
nil,
control.Options{})
err := c.UpdateCollections(ctx, "driveID", test.items, paths)
err := c.UpdateCollections(ctx, "driveID", "General", test.items, paths)
test.expect(t, err)
assert.Equal(t, len(test.expectedCollectionPaths), len(c.CollectionMap), "collection paths")
assert.Equal(t, test.expectedItemCount, c.NumItems, "item count")