diff --git a/src/internal/m365/collection/drive/collection_test.go b/src/internal/m365/collection/drive/collection_test.go index 51052a828..ca52b70e6 100644 --- a/src/internal/m365/collection/drive/collection_test.go +++ b/src/internal/m365/collection/drive/collection_test.go @@ -182,9 +182,9 @@ func (suite *CollectionUnitTestSuite) TestCollection() { folderPath, err := pb.ToDataLayerOneDrivePath("tenant", "owner", false) require.NoError(t, err, clues.ToCore(err)) - mbh := mock.DefaultOneDriveBH() + mbh := mock.DefaultOneDriveBH("a-user") if test.service == path.SharePointService { - mbh = mock.DefaultSharePointBH() + mbh = mock.DefaultSharePointBH("a-site") mbh.ItemInfo.SharePoint.Modified = now mbh.ItemInfo.SharePoint.ItemName = stubItemName } else { @@ -301,7 +301,7 @@ func (suite *CollectionUnitTestSuite) TestCollectionReadError() { folderPath, err := pb.ToDataLayerOneDrivePath("a-tenant", "a-user", false) require.NoError(t, err, clues.ToCore(err)) - mbh := mock.DefaultOneDriveBH() + mbh := mock.DefaultOneDriveBH("a-user") mbh.GI = mock.GetsItem{Err: assert.AnError} mbh.GIP = mock.GetsItemPermission{Perm: models.NewPermissionCollectionResponse()} mbh.GetResps = []*http.Response{ @@ -378,7 +378,7 @@ func (suite *CollectionUnitTestSuite) TestCollectionReadUnauthorizedErrorRetry() folderPath, err := pb.ToDataLayerOneDrivePath("a-tenant", "a-user", false) require.NoError(t, err) - mbh := mock.DefaultOneDriveBH() + mbh := mock.DefaultOneDriveBH("a-user") mbh.GI = mock.GetsItem{Item: stubItem} mbh.GIP = mock.GetsItemPermission{Perm: models.NewPermissionCollectionResponse()} mbh.GetResps = []*http.Response{ @@ -436,7 +436,7 @@ func (suite *CollectionUnitTestSuite) TestCollectionPermissionBackupLatestModTim folderPath, err := pb.ToDataLayerOneDrivePath("a-tenant", "a-user", false) require.NoError(t, err, clues.ToCore(err)) - mbh := mock.DefaultOneDriveBH() + mbh := mock.DefaultOneDriveBH("a-user") mbh.ItemInfo = details.ItemInfo{OneDrive: &details.OneDriveInfo{ItemName: "fakeName", Modified: time.Now()}} mbh.GIP = mock.GetsItemPermission{Perm: models.NewPermissionCollectionResponse()} mbh.GetResps = []*http.Response{{ @@ -587,7 +587,7 @@ func (suite *GetDriveItemUnitTestSuite) TestGetDriveItem_error() { true, false) - mbh := mock.DefaultOneDriveBH() + mbh := mock.DefaultOneDriveBH("a-user") mbh.GI = mock.GetsItem{Item: stubItem} mbh.GetResps = []*http.Response{{StatusCode: http.StatusOK}} mbh.GetErrs = []error{test.err} @@ -766,7 +766,7 @@ func (suite *GetDriveItemUnitTestSuite) TestDownloadContent() { } } - mbh := mock.DefaultOneDriveBH() + mbh := mock.DefaultOneDriveBH("a-user") mbh.GI = test.mgi mbh.ItemInfo = test.itemInfo mbh.GetResps = resps @@ -932,7 +932,7 @@ func (suite *CollectionUnitTestSuite) TestItemExtensions() { wg.Add(1) - mbh := mock.DefaultOneDriveBH() + mbh := mock.DefaultOneDriveBH("a-user") mbh.GI = mock.GetsItem{Err: assert.AnError} mbh.GIP = mock.GetsItemPermission{Perm: models.NewPermissionCollectionResponse()} mbh.GetResps = []*http.Response{ diff --git a/src/internal/m365/collection/drive/collections.go b/src/internal/m365/collection/drive/collections.go index b88de4aaa..d788a9a34 100644 --- a/src/internal/m365/collection/drive/collections.go +++ b/src/internal/m365/collection/drive/collections.go @@ -349,7 +349,7 @@ func (c *Collections) Get( continue } - p, err := c.handler.CanonicalPath(odConsts.DriveFolderPrefixBuilder(driveID), c.tenantID, c.resourceOwner) + p, err := c.handler.CanonicalPath(odConsts.DriveFolderPrefixBuilder(driveID), c.tenantID) if err != nil { return nil, false, clues.Wrap(err, "making exclude prefix").WithClues(ictx) } @@ -413,7 +413,7 @@ func (c *Collections) Get( // generate tombstones for drives that were removed. for driveID := range driveTombstones { - prevDrivePath, err := c.handler.PathPrefix(c.tenantID, c.resourceOwner, driveID) + prevDrivePath, err := c.handler.PathPrefix(c.tenantID, driveID) if err != nil { return nil, false, clues.Wrap(err, "making drive tombstone for previous path").WithClues(ctx) } @@ -642,7 +642,7 @@ func (c *Collections) getCollectionPath( pb = path.Builder{}.Append(path.Split(ptr.Val(item.GetParentReference().GetPath()))...) } - collectionPath, err := c.handler.CanonicalPath(pb, c.tenantID, c.resourceOwner) + collectionPath, err := c.handler.CanonicalPath(pb, c.tenantID) if err != nil { return nil, clues.Wrap(err, "making item path") } diff --git a/src/internal/m365/collection/drive/collections_test.go b/src/internal/m365/collection/drive/collections_test.go index e716c12ba..5604c4f42 100644 --- a/src/internal/m365/collection/drive/collections_test.go +++ b/src/internal/m365/collection/drive/collections_test.go @@ -40,7 +40,7 @@ type statePath struct { func getExpectedStatePathGenerator( t *testing.T, bh BackupHandler, - tenant, user, base string, + tenant, base string, ) func(data.CollectionState, ...string) statePath { return func(state data.CollectionState, pths ...string) statePath { var ( @@ -56,12 +56,12 @@ func getExpectedStatePathGenerator( } else { require.Len(t, pths, 2, "invalid number of paths to getExpectedStatePathGenerator") pb := path.Builder{}.Append(path.Split(base + pths[1])...) - p2, err = bh.CanonicalPath(pb, tenant, user) + p2, err = bh.CanonicalPath(pb, tenant) require.NoError(t, err, clues.ToCore(err)) } pb := path.Builder{}.Append(path.Split(base + pths[0])...) - p1, err = bh.CanonicalPath(pb, tenant, user) + p1, err = bh.CanonicalPath(pb, tenant) require.NoError(t, err, clues.ToCore(err)) switch state { @@ -88,11 +88,11 @@ func getExpectedStatePathGenerator( func getExpectedPathGenerator( t *testing.T, bh BackupHandler, - tenant, user, base string, + tenant, base string, ) func(string) string { return func(p string) string { pb := path.Builder{}.Append(path.Split(base + p)...) - cp, err := bh.CanonicalPath(pb, tenant, user) + cp, err := bh.CanonicalPath(pb, tenant) require.NoError(t, err, clues.ToCore(err)) return cp.String() @@ -129,10 +129,10 @@ func (suite *OneDriveCollectionsUnitSuite) TestUpdateCollections() { pkg = "/package" ) - bh := itemBackupHandler{} + bh := itemBackupHandler{userID: user} testBaseDrivePath := odConsts.DriveFolderPrefixBuilder("driveID1").String() - expectedPath := getExpectedPathGenerator(suite.T(), bh, tenant, user, testBaseDrivePath) - expectedStatePath := getExpectedStatePathGenerator(suite.T(), bh, tenant, user, testBaseDrivePath) + expectedPath := getExpectedPathGenerator(suite.T(), bh, tenant, testBaseDrivePath) + expectedStatePath := getExpectedStatePathGenerator(suite.T(), bh, tenant, testBaseDrivePath) tests := []struct { testCase string @@ -744,7 +744,7 @@ func (suite *OneDriveCollectionsUnitSuite) TestUpdateCollections() { maps.Copy(outputFolderMap, tt.inputFolderMap) c := NewCollections( - &itemBackupHandler{api.Drives{}, tt.scope}, + &itemBackupHandler{api.Drives{}, user, tt.scope}, tenant, user, nil, @@ -1208,13 +1208,13 @@ func (suite *OneDriveCollectionsUnitSuite) TestGet() { drive2.SetName(&driveID2) var ( - bh = itemBackupHandler{} + bh = itemBackupHandler{userID: user} driveBasePath1 = odConsts.DriveFolderPrefixBuilder(driveID1).String() driveBasePath2 = odConsts.DriveFolderPrefixBuilder(driveID2).String() - expectedPath1 = getExpectedPathGenerator(suite.T(), bh, tenant, user, driveBasePath1) - expectedPath2 = getExpectedPathGenerator(suite.T(), bh, tenant, user, driveBasePath2) + expectedPath1 = getExpectedPathGenerator(suite.T(), bh, tenant, driveBasePath1) + expectedPath2 = getExpectedPathGenerator(suite.T(), bh, tenant, driveBasePath2) rootFolderPath1 = expectedPath1("") folderPath1 = expectedPath1("/folder") @@ -2279,7 +2279,7 @@ func (suite *OneDriveCollectionsUnitSuite) TestGet() { } } - mbh := mock.DefaultOneDriveBH() + mbh := mock.DefaultOneDriveBH("a-user") mbh.DrivePagerV = mockDrivePager mbh.ItemPagerV = itemPagers @@ -2650,7 +2650,7 @@ func (suite *OneDriveCollectionsUnitSuite) TestAddURLCacheToDriveCollections() { itemPagers := map[string]api.DeltaPager[models.DriveItemable]{} itemPagers[driveID] = &apiMock.DeltaPager[models.DriveItemable]{} - mbh := mock.DefaultOneDriveBH() + mbh := mock.DefaultOneDriveBH("test-user") mbh.ItemPagerV = itemPagers c := NewCollections( @@ -2667,7 +2667,7 @@ func (suite *OneDriveCollectionsUnitSuite) TestAddURLCacheToDriveCollections() { // Add a few collections for i := 0; i < collCount; i++ { coll, err := NewCollection( - &itemBackupHandler{api.Drives{}, anyFolder}, + &itemBackupHandler{api.Drives{}, "test-user", anyFolder}, nil, nil, driveID, diff --git a/src/internal/m365/collection/drive/group_handler.go b/src/internal/m365/collection/drive/group_handler.go index d6faad8fb..585bf738d 100644 --- a/src/internal/m365/collection/drive/group_handler.go +++ b/src/internal/m365/collection/drive/group_handler.go @@ -1,6 +1,7 @@ package drive import ( + odConsts "github.com/alcionai/corso/src/internal/m365/service/onedrive/consts" "github.com/alcionai/corso/src/pkg/path" "github.com/alcionai/corso/src/pkg/selectors" "github.com/alcionai/corso/src/pkg/services/m365/api" @@ -14,10 +15,15 @@ type groupBackupHandler struct { scope selectors.GroupsScope } -func NewGroupBackupHandler(groupID string, ac api.Drives, scope selectors.GroupsScope) groupBackupHandler { +func NewGroupBackupHandler( + groupID, siteID string, + ac api.Drives, + scope selectors.GroupsScope, +) groupBackupHandler { return groupBackupHandler{ libraryBackupHandler{ - ac: ac, + ac: ac, + siteID: siteID, // Not adding scope here. Anything that needs scope has to // be from group handler service: path.GroupsService, @@ -27,16 +33,36 @@ func NewGroupBackupHandler(groupID string, ac api.Drives, scope selectors.Groups } } -func (h groupBackupHandler) CanonicalPath( - folders *path.Builder, - tenantID, resourceOwner string, +func (h groupBackupHandler) PathPrefix( + tenantID, driveID string, ) (path.Path, error) { - // TODO(meain): path fixes - return folders.ToDataLayerPath(tenantID, h.groupID, h.service, path.LibrariesCategory, false) + // TODO: move tenantID to struct + return path.Build( + tenantID, + h.groupID, + h.service, + path.LibrariesCategory, + false, + odConsts.SitesPathDir, + h.siteID, + odConsts.DrivesPathDir, + driveID, + odConsts.RootPathDir) } -func (h groupBackupHandler) ServiceCat() (path.ServiceType, path.CategoryType) { - return path.GroupsService, path.LibrariesCategory +func (h groupBackupHandler) CanonicalPath( + folders *path.Builder, + tenantID string, +) (path.Path, error) { + return folders.ToDataLayerPath( + tenantID, + h.groupID, + h.service, + path.LibrariesCategory, + false, + odConsts.SitesPathDir, + h.siteID, + ) } func (h groupBackupHandler) IsAllPass() bool { diff --git a/src/internal/m365/collection/drive/handlers.go b/src/internal/m365/collection/drive/handlers.go index 11860b802..947f949ca 100644 --- a/src/internal/m365/collection/drive/handlers.go +++ b/src/internal/m365/collection/drive/handlers.go @@ -39,14 +39,11 @@ type BackupHandler interface { // PathPrefix constructs the service and category specific path prefix for // the given values. - PathPrefix(tenantID, resourceOwner, driveID string) (path.Path, error) + PathPrefix(tenantID, driveID string) (path.Path, error) // CanonicalPath constructs the service and category specific path for // the given values. - CanonicalPath( - folders *path.Builder, - tenantID, resourceOwner string, - ) (path.Path, error) + CanonicalPath(folders *path.Builder, tenantID string) (path.Path, error) // ServiceCat returns the service and category used by this implementation. ServiceCat() (path.ServiceType, path.CategoryType) diff --git a/src/internal/m365/collection/drive/item_collector_test.go b/src/internal/m365/collection/drive/item_collector_test.go index d57ca23f6..7d7e146f8 100644 --- a/src/internal/m365/collection/drive/item_collector_test.go +++ b/src/internal/m365/collection/drive/item_collector_test.go @@ -344,7 +344,7 @@ func (suite *OneDriveIntgSuite) TestOneDriveNewCollections() { ) colls := NewCollections( - &itemBackupHandler{suite.ac.Drives(), scope}, + &itemBackupHandler{suite.ac.Drives(), test.user, scope}, creds.AzureTenantID, test.user, service.updateStatus, diff --git a/src/internal/m365/collection/drive/item_handler.go b/src/internal/m365/collection/drive/item_handler.go index 80eea5b06..16ae4dc3a 100644 --- a/src/internal/m365/collection/drive/item_handler.go +++ b/src/internal/m365/collection/drive/item_handler.go @@ -23,12 +23,13 @@ import ( var _ BackupHandler = &itemBackupHandler{} type itemBackupHandler struct { - ac api.Drives - scope selectors.OneDriveScope + ac api.Drives + userID string + scope selectors.OneDriveScope } -func NewItemBackupHandler(ac api.Drives, scope selectors.OneDriveScope) *itemBackupHandler { - return &itemBackupHandler{ac, scope} +func NewItemBackupHandler(ac api.Drives, userID string, scope selectors.OneDriveScope) *itemBackupHandler { + return &itemBackupHandler{ac, userID, scope} } func (h itemBackupHandler) Get( @@ -40,11 +41,11 @@ func (h itemBackupHandler) Get( } func (h itemBackupHandler) PathPrefix( - tenantID, resourceOwner, driveID string, + tenantID, driveID string, ) (path.Path, error) { return path.Build( tenantID, - resourceOwner, + h.userID, path.OneDriveService, path.FilesCategory, false, @@ -55,9 +56,9 @@ func (h itemBackupHandler) PathPrefix( func (h itemBackupHandler) CanonicalPath( folders *path.Builder, - tenantID, resourceOwner string, + tenantID string, ) (path.Path, error) { - return folders.ToDataLayerOneDrivePath(tenantID, resourceOwner, false) + return folders.ToDataLayerOneDrivePath(tenantID, h.userID, false) } func (h itemBackupHandler) ServiceCat() (path.ServiceType, path.CategoryType) { diff --git a/src/internal/m365/collection/drive/item_handler_test.go b/src/internal/m365/collection/drive/item_handler_test.go index 76767acce..e8657abac 100644 --- a/src/internal/m365/collection/drive/item_handler_test.go +++ b/src/internal/m365/collection/drive/item_handler_test.go @@ -36,10 +36,10 @@ func (suite *ItemBackupHandlerUnitSuite) TestCanonicalPath() { for _, test := range table { suite.Run(test.name, func() { t := suite.T() - h := itemBackupHandler{} + h := itemBackupHandler{userID: resourceOwner} p := path.Builder{}.Append("prefix") - result, err := h.CanonicalPath(p, tenantID, resourceOwner) + result, err := h.CanonicalPath(p, tenantID) test.expectErr(t, err, clues.ToCore(err)) if result != nil { diff --git a/src/internal/m365/collection/drive/item_test.go b/src/internal/m365/collection/drive/item_test.go index dfec42e2d..5d8d7a613 100644 --- a/src/internal/m365/collection/drive/item_test.go +++ b/src/internal/m365/collection/drive/item_test.go @@ -124,6 +124,7 @@ func (suite *ItemIntegrationSuite) TestItemReader_oneDrive() { bh := itemBackupHandler{ suite.service.ac.Drives(), + suite.user, (&selectors.OneDriveBackup{}).Folders(selectors.Any())[0], } diff --git a/src/internal/m365/collection/drive/library_handler.go b/src/internal/m365/collection/drive/library_handler.go index a27033424..f098be8ea 100644 --- a/src/internal/m365/collection/drive/library_handler.go +++ b/src/internal/m365/collection/drive/library_handler.go @@ -21,16 +21,18 @@ var _ BackupHandler = &libraryBackupHandler{} type libraryBackupHandler struct { ac api.Drives + siteID string scope selectors.SharePointScope service path.ServiceType } func NewLibraryBackupHandler( ac api.Drives, + siteID string, scope selectors.SharePointScope, service path.ServiceType, ) libraryBackupHandler { - return libraryBackupHandler{ac, scope, service} + return libraryBackupHandler{ac, siteID, scope, service} } func (h libraryBackupHandler) Get( @@ -42,11 +44,11 @@ func (h libraryBackupHandler) Get( } func (h libraryBackupHandler) PathPrefix( - tenantID, resourceOwner, driveID string, + tenantID, driveID string, ) (path.Path, error) { return path.Build( tenantID, - resourceOwner, + h.siteID, h.service, path.LibrariesCategory, false, @@ -57,13 +59,13 @@ func (h libraryBackupHandler) PathPrefix( func (h libraryBackupHandler) CanonicalPath( folders *path.Builder, - tenantID, resourceOwner string, + tenantID string, ) (path.Path, error) { - return folders.ToDataLayerPath(tenantID, resourceOwner, h.service, path.LibrariesCategory, false) + return folders.ToDataLayerPath(tenantID, h.siteID, h.service, path.LibrariesCategory, false) } func (h libraryBackupHandler) ServiceCat() (path.ServiceType, path.CategoryType) { - return path.SharePointService, path.LibrariesCategory + return h.service, path.LibrariesCategory } func (h libraryBackupHandler) NewDrivePager( diff --git a/src/internal/m365/collection/drive/library_handler_test.go b/src/internal/m365/collection/drive/library_handler_test.go index 93ff8d2ae..47163b610 100644 --- a/src/internal/m365/collection/drive/library_handler_test.go +++ b/src/internal/m365/collection/drive/library_handler_test.go @@ -36,10 +36,10 @@ func (suite *LibraryBackupHandlerUnitSuite) TestCanonicalPath() { for _, test := range table { suite.Run(test.name, func() { t := suite.T() - h := libraryBackupHandler{service: path.SharePointService} + h := libraryBackupHandler{service: path.SharePointService, siteID: resourceOwner} p := path.Builder{}.Append("prefix") - result, err := h.CanonicalPath(p, tenantID, resourceOwner) + result, err := h.CanonicalPath(p, tenantID) test.expectErr(t, err, clues.ToCore(err)) if result != nil { @@ -52,7 +52,7 @@ func (suite *LibraryBackupHandlerUnitSuite) TestCanonicalPath() { func (suite *LibraryBackupHandlerUnitSuite) TestServiceCat() { t := suite.T() - s, c := libraryBackupHandler{}.ServiceCat() + s, c := libraryBackupHandler{service: path.SharePointService}.ServiceCat() assert.Equal(t, path.SharePointService, s) assert.Equal(t, path.LibrariesCategory, c) } diff --git a/src/internal/m365/service/groups/backup.go b/src/internal/m365/service/groups/backup.go index b74b5fde0..b9431bdbe 100644 --- a/src/internal/m365/service/groups/backup.go +++ b/src/internal/m365/service/groups/backup.go @@ -80,7 +80,12 @@ func ProduceBackupCollections( dbcs, canUsePreviousBackup, err = site.CollectLibraries( ctx, sbpc, - drive.NewGroupBackupHandler(bpc.ProtectedResource.ID(), ac.Drives(), scope), + drive.NewGroupBackupHandler( + bpc.ProtectedResource.ID(), + ptr.Val(resp.GetId()), + ac.Drives(), + scope, + ), creds.AzureTenantID, ssmb, su, diff --git a/src/internal/m365/service/onedrive/backup.go b/src/internal/m365/service/onedrive/backup.go index c369afe11..b94ce918d 100644 --- a/src/internal/m365/service/onedrive/backup.go +++ b/src/internal/m365/service/onedrive/backup.go @@ -49,7 +49,7 @@ func ProduceBackupCollections( logger.Ctx(ctx).Debug("creating OneDrive collections") nc := drive.NewCollections( - drive.NewItemBackupHandler(ac.Drives(), scope), + drive.NewItemBackupHandler(ac.Drives(), bpc.ProtectedResource.ID(), scope), tenant, bpc.ProtectedResource.ID(), su, diff --git a/src/internal/m365/service/onedrive/consts/consts.go b/src/internal/m365/service/onedrive/consts/consts.go index 956faaf1b..0cfd01617 100644 --- a/src/internal/m365/service/onedrive/consts/consts.go +++ b/src/internal/m365/service/onedrive/consts/consts.go @@ -3,6 +3,7 @@ package onedrive import "github.com/alcionai/corso/src/pkg/path" const ( + SitesPathDir = "sites" // const used as the root dir for the drive portion of a path prefix. // eg: tid/onedrive/ro/files/drives/driveid/... DrivesPathDir = "drives" diff --git a/src/internal/m365/service/onedrive/mock/handlers.go b/src/internal/m365/service/onedrive/mock/handlers.go index d8b12b3bb..248034f29 100644 --- a/src/internal/m365/service/onedrive/mock/handlers.go +++ b/src/internal/m365/service/onedrive/mock/handlers.go @@ -31,8 +31,9 @@ type BackupHandler struct { CanonPathFn canonPather CanonPathErr error - Service path.ServiceType - Category path.CategoryType + ResourceOwner string + Service path.ServiceType + Category path.CategoryType DrivePagerV api.Pager[models.Driveable] // driveID -> itemPager @@ -45,44 +46,46 @@ type BackupHandler struct { GetErrs []error } -func DefaultOneDriveBH() *BackupHandler { +func DefaultOneDriveBH(resourceOwner string) *BackupHandler { return &BackupHandler{ ItemInfo: details.ItemInfo{ OneDrive: &details.OneDriveInfo{}, Extension: &details.ExtensionData{}, }, - GI: GetsItem{Err: clues.New("not defined")}, - GIP: GetsItemPermission{Err: clues.New("not defined")}, - PathPrefixFn: defaultOneDrivePathPrefixer, - CanonPathFn: defaultOneDriveCanonPather, - Service: path.OneDriveService, - Category: path.FilesCategory, - LocationIDFn: defaultOneDriveLocationIDer, - GetResps: []*http.Response{nil}, - GetErrs: []error{clues.New("not defined")}, + GI: GetsItem{Err: clues.New("not defined")}, + GIP: GetsItemPermission{Err: clues.New("not defined")}, + PathPrefixFn: defaultOneDrivePathPrefixer, + CanonPathFn: defaultOneDriveCanonPather, + ResourceOwner: resourceOwner, + Service: path.OneDriveService, + Category: path.FilesCategory, + LocationIDFn: defaultOneDriveLocationIDer, + GetResps: []*http.Response{nil}, + GetErrs: []error{clues.New("not defined")}, } } -func DefaultSharePointBH() *BackupHandler { +func DefaultSharePointBH(resourceOwner string) *BackupHandler { return &BackupHandler{ ItemInfo: details.ItemInfo{ SharePoint: &details.SharePointInfo{}, Extension: &details.ExtensionData{}, }, - GI: GetsItem{Err: clues.New("not defined")}, - GIP: GetsItemPermission{Err: clues.New("not defined")}, - PathPrefixFn: defaultSharePointPathPrefixer, - CanonPathFn: defaultSharePointCanonPather, - Service: path.SharePointService, - Category: path.LibrariesCategory, - LocationIDFn: defaultSharePointLocationIDer, - GetResps: []*http.Response{nil}, - GetErrs: []error{clues.New("not defined")}, + GI: GetsItem{Err: clues.New("not defined")}, + GIP: GetsItemPermission{Err: clues.New("not defined")}, + PathPrefixFn: defaultSharePointPathPrefixer, + CanonPathFn: defaultSharePointCanonPather, + ResourceOwner: resourceOwner, + Service: path.SharePointService, + Category: path.LibrariesCategory, + LocationIDFn: defaultSharePointLocationIDer, + GetResps: []*http.Response{nil}, + GetErrs: []error{clues.New("not defined")}, } } -func (h BackupHandler) PathPrefix(tID, ro, driveID string) (path.Path, error) { - pp, err := h.PathPrefixFn(tID, ro, driveID) +func (h BackupHandler) PathPrefix(tID, driveID string) (path.Path, error) { + pp, err := h.PathPrefixFn(tID, h.ResourceOwner, driveID) if err != nil { return nil, err } @@ -90,8 +93,8 @@ func (h BackupHandler) PathPrefix(tID, ro, driveID string) (path.Path, error) { return pp, h.PathPrefixErr } -func (h BackupHandler) CanonicalPath(pb *path.Builder, tID, ro string) (path.Path, error) { - cp, err := h.CanonPathFn(pb, tID, ro) +func (h BackupHandler) CanonicalPath(pb *path.Builder, tID string) (path.Path, error) { + cp, err := h.CanonPathFn(pb, tID, h.ResourceOwner) if err != nil { return nil, err } diff --git a/src/internal/m365/service/sharepoint/backup.go b/src/internal/m365/service/sharepoint/backup.go index ad34ef9c9..e64f91a4c 100644 --- a/src/internal/m365/service/sharepoint/backup.go +++ b/src/internal/m365/service/sharepoint/backup.go @@ -80,7 +80,11 @@ func ProduceBackupCollections( spcs, canUsePreviousBackup, err = site.CollectLibraries( ctx, bpc, - drive.NewLibraryBackupHandler(ac.Drives(), scope, bpc.Selector.PathService()), + drive.NewLibraryBackupHandler( + ac.Drives(), + bpc.ProtectedResource.ID(), + scope, + bpc.Selector.PathService()), creds.AzureTenantID, ssmb, su, diff --git a/src/internal/m365/service/sharepoint/backup_test.go b/src/internal/m365/service/sharepoint/backup_test.go index 8365cb099..bcd37dd6b 100644 --- a/src/internal/m365/service/sharepoint/backup_test.go +++ b/src/internal/m365/service/sharepoint/backup_test.go @@ -50,8 +50,8 @@ func (suite *LibrariesBackupUnitSuite) TestUpdateCollections() { ) pb := path.Builder{}.Append(testBaseDrivePath.Elements()...) - ep, err := drive.NewLibraryBackupHandler(api.Drives{}, nil, path.SharePointService). - CanonicalPath(pb, tenantID, siteID) + ep, err := drive.NewLibraryBackupHandler(api.Drives{}, siteID, nil, path.SharePointService). + CanonicalPath(pb, tenantID) require.NoError(suite.T(), err, clues.ToCore(err)) tests := []struct { @@ -101,7 +101,7 @@ func (suite *LibrariesBackupUnitSuite) TestUpdateCollections() { ) c := drive.NewCollections( - drive.NewLibraryBackupHandler(api.Drives{}, test.scope, path.SharePointService), + drive.NewLibraryBackupHandler(api.Drives{}, siteID, test.scope, path.SharePointService), tenantID, siteID, nil, diff --git a/src/pkg/path/builder.go b/src/pkg/path/builder.go index ec1f71ee3..7b27f6586 100644 --- a/src/pkg/path/builder.go +++ b/src/pkg/path/builder.go @@ -306,6 +306,7 @@ func (pb Builder) ToDataLayerPath( service ServiceType, category CategoryType, isItem bool, + elems ...string, ) (Path, error) { if err := ValidateServiceAndCategory(service, category); err != nil { return nil, err @@ -315,12 +316,15 @@ func (pb Builder) ToDataLayerPath( return nil, err } + prefixItems := append([]string{ + tenant, + service.String(), + user, + category.String(), + }, elems...) + return &dataLayerResourcePath{ - Builder: *pb.withPrefix( - tenant, - service.String(), - user, - category.String()), + Builder: *pb.withPrefix(prefixItems...), service: service, category: category, hasItem: isItem, diff --git a/src/pkg/path/builder_test.go b/src/pkg/path/builder_test.go index cb483606d..335a08912 100644 --- a/src/pkg/path/builder_test.go +++ b/src/pkg/path/builder_test.go @@ -367,3 +367,39 @@ func (suite *BuilderUnitSuite) TestPIIHandling() { }) } } + +func (suite *BuilderUnitSuite) TestToDataLayerPath() { + location := Builder{}.Append("foo", "bar") + + table := []struct { + name string + extra []string + expect string + }{ + { + name: "no extra", + extra: []string{}, + expect: "t/onedrive/u/files/foo/bar", + }, + { + name: "single extra", + extra: []string{"oof"}, + expect: "t/onedrive/u/files/oof/foo/bar", + }, + { + name: "multi extra", + extra: []string{"oof", "rab"}, + expect: "t/onedrive/u/files/oof/rab/foo/bar", + }, + } + for _, test := range table { + suite.Run(test.name, func() { + t := suite.T() + + dlp, err := location.ToDataLayerPath("t", "u", OneDriveService, FilesCategory, false, test.extra...) + require.NoError(t, err, clues.ToCore(err)) + + assert.Equal(t, test.expect, dlp.PlainString()) + }) + } +}