disguise user's default drive as enum (#3339)

When calling drive enumeration, secretly return only the user's default drive if running in onedrive, to prevent us from loading multiple drives unintentionally.

---

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

- [x]  Yes, it's included

#### Type of change

- [x] 🐛 Bugfix

#### Issue(s)

* #3335

#### Test Plan

- [x] 💪 Manual
- [x]  Unit test
- [x] 💚 E2E
This commit is contained in:
Keepers 2023-05-05 16:58:36 -06:00 committed by GitHub
parent f5365f19c5
commit 1dcdd28a90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 2 deletions

View File

@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- --user and --mailbox flags have been removed from CLI examples for details and restore commands (they were already not supported, this only updates the docs). - --user and --mailbox flags have been removed from CLI examples for details and restore commands (they were already not supported, this only updates the docs).
- Improve restore time on large restores by optimizing how items are loaded from the remote repository. - Improve restore time on large restores by optimizing how items are loaded from the remote repository.
- Remove exchange item filtering based on m365 item ID via the CLI. - Remove exchange item filtering based on m365 item ID via the CLI.
- OneDrive backups no longer include a user's non-default drives.
## [v0.7.0] (beta) - 2023-05-02 ## [v0.7.0] (beta) - 2023-05-02

View File

@ -104,6 +104,7 @@ func (p *driveItemPager) ValuesIn(l api.DeltaPageLinker) ([]models.DriveItemable
} }
type userDrivePager struct { type userDrivePager struct {
userID string
gs graph.Servicer gs graph.Servicer
builder *users.ItemDrivesRequestBuilder builder *users.ItemDrivesRequestBuilder
options *users.ItemDrivesRequestBuilderGetRequestConfiguration options *users.ItemDrivesRequestBuilderGetRequestConfiguration
@ -121,6 +122,7 @@ func NewUserDrivePager(
} }
res := &userDrivePager{ res := &userDrivePager{
userID: userID,
gs: gs, gs: gs,
options: requestConfig, options: requestConfig,
builder: gs.Client().UsersById(userID).Drives(), builder: gs.Client().UsersById(userID).Drives(),
@ -129,17 +131,33 @@ func NewUserDrivePager(
return res return res
} }
type nopUserDrivePageLinker struct {
drive models.Driveable
}
func (nl nopUserDrivePageLinker) GetOdataNextLink() *string { return nil }
func (p *userDrivePager) GetPage(ctx context.Context) (api.PageLinker, error) { func (p *userDrivePager) GetPage(ctx context.Context) (api.PageLinker, error) {
var ( var (
resp api.PageLinker resp api.PageLinker
err error err error
) )
resp, err = p.builder.Get(ctx, p.options) d, err := p.gs.Client().UsersById(p.userID).Drive().Get(ctx, nil)
if err != nil { if err != nil {
return nil, graph.Stack(ctx, err) return nil, graph.Stack(ctx, err)
} }
resp = &nopUserDrivePageLinker{drive: d}
// TODO(keepers): turn back on when we can separate drive enumeration
// from default drive lookup.
// resp, err = p.builder.Get(ctx, p.options)
// if err != nil {
// return nil, graph.Stack(ctx, err)
// }
return resp, nil return resp, nil
} }
@ -148,7 +166,17 @@ func (p *userDrivePager) SetNext(link string) {
} }
func (p *userDrivePager) ValuesIn(l api.PageLinker) ([]models.Driveable, error) { func (p *userDrivePager) ValuesIn(l api.PageLinker) ([]models.Driveable, error) {
return getValues[models.Driveable](l) nl, ok := l.(*nopUserDrivePageLinker)
if !ok || nl == nil {
return nil, clues.New(fmt.Sprintf("improper page linker struct for user drives: %T", l))
}
// TODO(keepers): turn back on when we can separate drive enumeration
// from default drive lookup.
// return getValues[models.Driveable](l)
return []models.Driveable{nl.drive}, nil
} }
type siteDrivePager struct { type siteDrivePager struct {