add foldermatcher to handler (#3565)

Missed adding the foldermatcher to the handlers
for onedrive and sharepoint during the api refactor.

---

#### Does this PR need a docs update or release note?

- [x]  No

#### Type of change

- [x] 🧹 Tech Debt/Cleanup

#### Issue(s)

* #1996

#### Test Plan

- [x]  Unit test
- [x] 💚 E2E
This commit is contained in:
Keepers 2023-06-15 12:28:31 -06:00 committed by GitHub
parent c0f428ddc8
commit 5184920b52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 66 additions and 86 deletions

View File

@ -19,20 +19,6 @@ import (
"github.com/alcionai/corso/src/pkg/services/m365/api" "github.com/alcionai/corso/src/pkg/services/m365/api"
) )
type odFolderMatcher struct {
scope selectors.OneDriveScope
}
func (fm odFolderMatcher) IsAny() bool {
return fm.scope.IsAny(selectors.OneDriveFolder)
}
func (fm odFolderMatcher) Matches(dir string) bool {
return fm.scope.Matches(selectors.OneDriveFolder, dir)
}
// ProduceBackupCollections returns a set of DataCollection which represents the OneDrive data
// for the specified user
func ProduceBackupCollections( func ProduceBackupCollections(
ctx context.Context, ctx context.Context,
ac api.Client, ac api.Client,
@ -68,10 +54,9 @@ func ProduceBackupCollections(
logger.Ctx(ctx).Debug("creating OneDrive collections") logger.Ctx(ctx).Debug("creating OneDrive collections")
nc := NewCollections( nc := NewCollections(
&itemBackupHandler{ac.Drives()}, &itemBackupHandler{ac.Drives(), scope},
tenant, tenant,
user.ID(), user.ID(),
odFolderMatcher{scope},
su, su,
ctrlOpts) ctrlOpts)

View File

@ -42,11 +42,6 @@ const (
const restrictedDirectory = "Site Pages" const restrictedDirectory = "Site Pages"
type folderMatcher interface {
IsAny() bool
Matches(string) bool
}
// Collections is used to retrieve drive data for a // Collections is used to retrieve drive data for a
// resource owner, which can be either a user or a sharepoint site. // resource owner, which can be either a user or a sharepoint site.
type Collections struct { type Collections struct {
@ -54,7 +49,7 @@ type Collections struct {
tenantID string tenantID string
resourceOwner string resourceOwner string
matcher folderMatcher
statusUpdater support.StatusUpdater statusUpdater support.StatusUpdater
ctrl control.Options ctrl control.Options
@ -74,7 +69,6 @@ func NewCollections(
bh BackupHandler, bh BackupHandler,
tenantID string, tenantID string,
resourceOwner string, resourceOwner string,
matcher folderMatcher,
statusUpdater support.StatusUpdater, statusUpdater support.StatusUpdater,
ctrlOpts control.Options, ctrlOpts control.Options,
) *Collections { ) *Collections {
@ -82,7 +76,6 @@ func NewCollections(
handler: bh, handler: bh,
tenantID: tenantID, tenantID: tenantID,
resourceOwner: resourceOwner, resourceOwner: resourceOwner,
matcher: matcher,
CollectionMap: map[string]map[string]*Collection{}, CollectionMap: map[string]map[string]*Collection{},
statusUpdater: statusUpdater, statusUpdater: statusUpdater,
ctrl: ctrlOpts, ctrl: ctrlOpts,
@ -697,7 +690,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 shouldSkipDrive(ctx, collectionPath, c.matcher, driveName) { if shouldSkip(ctx, collectionPath, c.handler, driveName) {
logger.Ctx(ictx).Debugw("path not selected", "skipped_path", collectionPath.String()) logger.Ctx(ictx).Debugw("path not selected", "skipped_path", collectionPath.String())
continue continue
} }
@ -827,12 +820,17 @@ func (c *Collections) UpdateCollections(
return el.Failure() return el.Failure()
} }
func shouldSkipDrive(ctx context.Context, drivePath path.Path, m folderMatcher, driveName string) bool { type dirScopeChecker interface {
return !includePath(ctx, m, drivePath) || IsAllPass() bool
IncludesDir(dir string) bool
}
func shouldSkip(ctx context.Context, drivePath path.Path, dsc dirScopeChecker, driveName string) bool {
return !includePath(ctx, dsc, drivePath) ||
(drivePath.Category() == path.LibrariesCategory && restrictedDirectory == driveName) (drivePath.Category() == path.LibrariesCategory && restrictedDirectory == driveName)
} }
func includePath(ctx context.Context, m folderMatcher, folderPath path.Path) bool { func includePath(ctx context.Context, dsc dirScopeChecker, folderPath path.Path) bool {
// Check if the folder is allowed by the scope. // Check if the folder is allowed by the scope.
pb, err := path.GetDriveFolderPath(folderPath) pb, err := path.GetDriveFolderPath(folderPath)
if err != nil { if err != nil {
@ -842,11 +840,11 @@ func includePath(ctx context.Context, m folderMatcher, folderPath path.Path) boo
// Hack for the edge case where we're looking at the root folder and can // Hack for the edge case where we're looking at the root folder and can
// select any folder. Right now the root folder has an empty folder path. // select any folder. Right now the root folder has an empty folder path.
if len(pb.Elements()) == 0 && m.IsAny() { if len(pb.Elements()) == 0 && dsc.IsAllPass() {
return true return true
} }
return m.Matches(pb.String()) return dsc.IncludesDir(pb.String())
} }
func updatePath(paths map[string]string, id, newPath string) { func updatePath(paths map[string]string, id, newPath string) {

View File

@ -743,10 +743,9 @@ func (suite *OneDriveCollectionsUnitSuite) TestUpdateCollections() {
maps.Copy(outputFolderMap, tt.inputFolderMap) maps.Copy(outputFolderMap, tt.inputFolderMap)
c := NewCollections( c := NewCollections(
&itemBackupHandler{api.Drives{}}, &itemBackupHandler{api.Drives{}, tt.scope},
tenant, tenant,
user, user,
testFolderMatcher{tt.scope},
nil, nil,
control.Options{ToggleFeatures: control.Toggles{}}) control.Options{ToggleFeatures: control.Toggles{}})
@ -1238,13 +1237,12 @@ func (p *mockItemPager) ValuesIn(api.DeltaPageLinker) ([]models.DriveItemable, e
func (suite *OneDriveCollectionsUnitSuite) TestGet() { func (suite *OneDriveCollectionsUnitSuite) TestGet() {
var ( var (
anyFolder = (&selectors.OneDriveBackup{}).Folders(selectors.Any())[0] tenant = "a-tenant"
tenant = "a-tenant" user = "a-user"
user = "a-user" empty = ""
empty = "" next = "next"
next = "next" delta = "delta1"
delta = "delta1" delta2 = "delta2"
delta2 = "delta2"
) )
metadataPath, err := path.Builder{}.ToServiceCategoryMetadataPath( metadataPath, err := path.Builder{}.ToServiceCategoryMetadataPath(
@ -2345,7 +2343,6 @@ func (suite *OneDriveCollectionsUnitSuite) TestGet() {
mbh, mbh,
tenant, tenant,
user, user,
testFolderMatcher{anyFolder},
func(*support.ControllerOperationStatus) {}, func(*support.ControllerOperationStatus) {},
control.Options{ToggleFeatures: control.Toggles{}}) control.Options{ToggleFeatures: control.Toggles{}})

View File

@ -54,6 +54,10 @@ type BackupHandler interface {
// provided path. // provided path.
FormatDisplayPath(driveName string, parentPath *path.Builder) string FormatDisplayPath(driveName string, parentPath *path.Builder) string
NewLocationIDer(driveID string, elems ...string) details.LocationIDer NewLocationIDer(driveID string, elems ...string) details.LocationIDer
// scope wrapper funcs
IsAllPass() bool
IncludesDir(dir string) bool
} }
type GetItemPermissioner interface { type GetItemPermissioner interface {

View File

@ -390,7 +390,10 @@ func (suite *OneDriveIntgSuite) TestCreateGetDeleteFolder() {
for _, test := range table { for _, test := range table {
suite.Run(test.name, func() { suite.Run(test.name, func() {
t := suite.T() t := suite.T()
bh := itemBackupHandler{suite.ac.Drives()} bh := itemBackupHandler{
suite.ac.Drives(),
(&selectors.OneDriveBackup{}).Folders(selectors.Any())[0],
}
pager := suite.ac.Drives().NewUserDrivePager(suite.userID, nil) pager := suite.ac.Drives().NewUserDrivePager(suite.userID, nil)
ctx, flush := tester.NewContext(t) ctx, flush := tester.NewContext(t)
@ -415,18 +418,6 @@ func (suite *OneDriveIntgSuite) TestCreateGetDeleteFolder() {
} }
} }
type testFolderMatcher struct {
scope selectors.OneDriveScope
}
func (fm testFolderMatcher) IsAny() bool {
return fm.scope.IsAny(selectors.OneDriveFolder)
}
func (fm testFolderMatcher) Matches(p string) bool {
return fm.scope.Matches(selectors.OneDriveFolder, p)
}
func (suite *OneDriveIntgSuite) TestOneDriveNewCollections() { func (suite *OneDriveIntgSuite) TestOneDriveNewCollections() {
creds, err := tester.NewM365Account(suite.T()).M365Config() creds, err := tester.NewM365Account(suite.T()).M365Config()
require.NoError(suite.T(), err, clues.ToCore(err)) require.NoError(suite.T(), err, clues.ToCore(err))
@ -459,10 +450,9 @@ func (suite *OneDriveIntgSuite) TestOneDriveNewCollections() {
) )
colls := NewCollections( colls := NewCollections(
&itemBackupHandler{suite.ac.Drives()}, &itemBackupHandler{suite.ac.Drives(), scope},
creds.AzureTenantID, creds.AzureTenantID,
test.user, test.user,
testFolderMatcher{scope},
service.updateStatus, service.updateStatus,
control.Options{ control.Options{
ToggleFeatures: control.Toggles{}, ToggleFeatures: control.Toggles{},

View File

@ -12,6 +12,7 @@ import (
odConsts "github.com/alcionai/corso/src/internal/m365/onedrive/consts" odConsts "github.com/alcionai/corso/src/internal/m365/onedrive/consts"
"github.com/alcionai/corso/src/pkg/backup/details" "github.com/alcionai/corso/src/pkg/backup/details"
"github.com/alcionai/corso/src/pkg/path" "github.com/alcionai/corso/src/pkg/path"
"github.com/alcionai/corso/src/pkg/selectors"
"github.com/alcionai/corso/src/pkg/services/m365/api" "github.com/alcionai/corso/src/pkg/services/m365/api"
) )
@ -22,7 +23,8 @@ import (
var _ BackupHandler = &itemBackupHandler{} var _ BackupHandler = &itemBackupHandler{}
type itemBackupHandler struct { type itemBackupHandler struct {
ac api.Drives ac api.Drives
scope selectors.OneDriveScope
} }
func (h itemBackupHandler) Get( func (h itemBackupHandler) Get(
@ -108,6 +110,14 @@ func (h itemBackupHandler) GetItem(
return h.ac.GetItem(ctx, driveID, itemID) return h.ac.GetItem(ctx, driveID, itemID)
} }
func (h itemBackupHandler) IsAllPass() bool {
return h.scope.IsAny(selectors.OneDriveFolder)
}
func (h itemBackupHandler) IncludesDir(dir string) bool {
return h.scope.Matches(selectors.OneDriveFolder, dir)
}
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// Restore // Restore
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------

View File

@ -17,6 +17,7 @@ import (
"github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/internal/tester"
"github.com/alcionai/corso/src/pkg/control/testdata" "github.com/alcionai/corso/src/pkg/control/testdata"
"github.com/alcionai/corso/src/pkg/fault" "github.com/alcionai/corso/src/pkg/fault"
"github.com/alcionai/corso/src/pkg/selectors"
"github.com/alcionai/corso/src/pkg/services/m365/api" "github.com/alcionai/corso/src/pkg/services/m365/api"
) )
@ -118,7 +119,10 @@ func (suite *ItemIntegrationSuite) TestItemReader_oneDrive() {
suite.user, suite.user,
suite.userDriveID) suite.userDriveID)
bh := itemBackupHandler{suite.service.ac.Drives()} bh := itemBackupHandler{
suite.service.ac.Drives(),
(&selectors.OneDriveBackup{}).Folders(selectors.Any())[0],
}
// Read data for the file // Read data for the file
itemData, err := downloadItem(ctx, bh, driveItem) itemData, err := downloadItem(ctx, bh, driveItem)

View File

@ -184,6 +184,14 @@ var defaultSharePointLocationIDer = func(driveID string, elems ...string) detail
return details.NewSharePointLocationIDer(driveID, elems...) return details.NewSharePointLocationIDer(driveID, elems...)
} }
func (h BackupHandler) IsAllPass() bool {
return true
}
func (h BackupHandler) IncludesDir(string) bool {
return true
}
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// Get Itemer // Get Itemer
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------

View File

@ -220,10 +220,9 @@ func collectLibraries(
var ( var (
collections = []data.BackupCollection{} collections = []data.BackupCollection{}
colls = onedrive.NewCollections( colls = onedrive.NewCollections(
&libraryBackupHandler{ad}, &libraryBackupHandler{ad, scope},
tenantID, tenantID,
site.ID(), site.ID(),
folderMatcher{scope},
updater.UpdateStatus, updater.UpdateStatus,
ctrlOpts) ctrlOpts)
) )
@ -301,15 +300,3 @@ func collectPages(
return spcs, el.Failure() return spcs, el.Failure()
} }
type folderMatcher struct {
scope selectors.SharePointScope
}
func (fm folderMatcher) IsAny() bool {
return fm.scope.IsAny(selectors.SharePointLibraryFolder)
}
func (fm folderMatcher) Matches(dir string) bool {
return fm.scope.Matches(selectors.SharePointLibraryFolder, dir)
}

View File

@ -29,18 +29,6 @@ var testBaseDrivePath = path.Builder{}.Append(
"driveID1", "driveID1",
odConsts.RootPathDir) odConsts.RootPathDir)
type testFolderMatcher struct {
scope selectors.SharePointScope
}
func (fm testFolderMatcher) IsAny() bool {
return fm.scope.IsAny(selectors.SharePointLibraryFolder)
}
func (fm testFolderMatcher) Matches(p string) bool {
return fm.scope.Matches(selectors.SharePointLibraryFolder, p)
}
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// tests // tests
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
@ -113,10 +101,9 @@ func (suite *LibrariesBackupUnitSuite) TestUpdateCollections() {
) )
c := onedrive.NewCollections( c := onedrive.NewCollections(
&libraryBackupHandler{api.Drives{}}, &libraryBackupHandler{api.Drives{}, test.scope},
tenantID, tenantID,
site, site,
testFolderMatcher{test.scope},
nil, nil,
control.Defaults()) control.Defaults())

View File

@ -13,13 +13,15 @@ import (
odConsts "github.com/alcionai/corso/src/internal/m365/onedrive/consts" odConsts "github.com/alcionai/corso/src/internal/m365/onedrive/consts"
"github.com/alcionai/corso/src/pkg/backup/details" "github.com/alcionai/corso/src/pkg/backup/details"
"github.com/alcionai/corso/src/pkg/path" "github.com/alcionai/corso/src/pkg/path"
"github.com/alcionai/corso/src/pkg/selectors"
"github.com/alcionai/corso/src/pkg/services/m365/api" "github.com/alcionai/corso/src/pkg/services/m365/api"
) )
var _ onedrive.BackupHandler = &libraryBackupHandler{} var _ onedrive.BackupHandler = &libraryBackupHandler{}
type libraryBackupHandler struct { type libraryBackupHandler struct {
ac api.Drives ac api.Drives
scope selectors.SharePointScope
} }
func (h libraryBackupHandler) Get( func (h libraryBackupHandler) Get(
@ -139,6 +141,14 @@ func (h libraryBackupHandler) GetItem(
return h.ac.GetItem(ctx, driveID, itemID) return h.ac.GetItem(ctx, driveID, itemID)
} }
func (h libraryBackupHandler) IsAllPass() bool {
return h.scope.IsAny(selectors.SharePointLibraryFolder)
}
func (h libraryBackupHandler) IncludesDir(dir string) bool {
return h.scope.Matches(selectors.SharePointLibraryFolder, dir)
}
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// Restore // Restore
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------