Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add basic groups boilerplate #3971

Merged
merged 5 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/internal/m365/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (ctrl *Controller) ProduceBackupCollections(
bpc,
ctrl.AC,
ctrl.credentials,
ctrl,
ctrl.UpdateStatus,
errs)
if err != nil {
return nil, nil, false, err
Expand Down
2 changes: 1 addition & 1 deletion src/internal/m365/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ func (suite *DataCollectionIntgSuite) TestSharePointDataCollection() {
bpc,
suite.ac,
ctrl.credentials,
ctrl,
ctrl.UpdateStatus,
fault.New(true))
require.NoError(t, err, clues.ToCore(err))
assert.True(t, canUsePreviousBackup, "can use previous backup")
Expand Down
86 changes: 86 additions & 0 deletions src/internal/m365/groups/backup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package groups

import (
"context"

"github.com/alcionai/clues"

"github.com/alcionai/corso/src/internal/common/prefixmatcher"
"github.com/alcionai/corso/src/internal/data"
"github.com/alcionai/corso/src/internal/m365/graph"
"github.com/alcionai/corso/src/internal/m365/support"
"github.com/alcionai/corso/src/internal/observe"
"github.com/alcionai/corso/src/internal/operations/inject"
"github.com/alcionai/corso/src/pkg/account"
"github.com/alcionai/corso/src/pkg/fault"
"github.com/alcionai/corso/src/pkg/path"
"github.com/alcionai/corso/src/pkg/services/m365/api"
)

func ProduceBackupCollections(
ctx context.Context,
bpc inject.BackupProducerConfig,
ac api.Client,
creds account.M365Config,
su support.StatusUpdater,
errs *fault.Bus,
) ([]data.BackupCollection, *prefixmatcher.StringSetMatcher, bool, error) {
b, err := bpc.Selector.ToGroupsBackup()
if err != nil {
return nil, nil, false, clues.Wrap(err, "groupsDataCollection: parsing selector")
}

var (
el = errs.Local()
collections = []data.BackupCollection{}
categories = map[path.CategoryType]struct{}{}
ssmb = prefixmatcher.NewStringSetBuilder()
canUsePreviousBackup bool
)

ctx = clues.Add(
ctx,
"group_id", clues.Hide(bpc.ProtectedResource.ID()),
"group_name", clues.Hide(bpc.ProtectedResource.Name()))

for _, scope := range b.Scopes() {
if el.Failure() != nil {
break
}

progressBar := observe.MessageWithCompletion(
ctx,
observe.Bulletf("%s", scope.Category().PathType()))
defer close(progressBar)

var dbcs []data.BackupCollection

switch scope.Category().PathType() {
case path.LibrariesCategory:
// TODO
}

Check failure on line 61 in src/internal/m365/groups/backup.go

View workflow job for this annotation

GitHub Actions / Source-Code-Linting

block should not end with a whitespace (or comment) (wsl)

collections = append(collections, dbcs...)

categories[scope.Category().PathType()] = struct{}{}
}

if len(collections) > 0 {
baseCols, err := graph.BaseCollections(
ctx,
collections,
creds.AzureTenantID,
bpc.ProtectedResource.ID(),
path.UnknownService, // path.GroupsService
categories,
su,
errs)
if err != nil {
return nil, nil, false, err
}

collections = append(collections, baseCols...)
}

return collections, ssmb.ToReader(), canUsePreviousBackup, el.Failure()
}
93 changes: 93 additions & 0 deletions src/internal/m365/groups/restore.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package groups

import (
"context"
"errors"

"github.com/alcionai/clues"

"github.com/alcionai/corso/src/internal/common/idname"
"github.com/alcionai/corso/src/internal/data"
"github.com/alcionai/corso/src/internal/m365/support"
"github.com/alcionai/corso/src/internal/operations/inject"
"github.com/alcionai/corso/src/pkg/backup/details"
"github.com/alcionai/corso/src/pkg/count"
"github.com/alcionai/corso/src/pkg/fault"
"github.com/alcionai/corso/src/pkg/path"
"github.com/alcionai/corso/src/pkg/services/m365/api"
)

// ConsumeRestoreCollections will restore the specified data collections into OneDrive
func ConsumeRestoreCollections(
ctx context.Context,
rcc inject.RestoreConsumerConfig,
ac api.Client,
backupDriveIDNames idname.Cacher,
dcs []data.RestoreCollection,
deets *details.Builder,
errs *fault.Bus,
ctr *count.Bus,
) (*support.ControllerOperationStatus, error) {
var (
restoreMetrics support.CollectionMetrics
// caches = onedrive.NewRestoreCaches(backupDriveIDNames)
el = errs.Local()
)

// TODO: uncomment when a handler is available
// err := caches.Populate(ctx, lrh, rcc.ProtectedResource.ID())
// if err != nil {
// return nil, clues.Wrap(err, "initializing restore caches")
// }

// Reorder collections so that the parents directories are created
// before the child directories; a requirement for permissions.
data.SortRestoreCollections(dcs)

// Iterate through the data collections and restore the contents of each
for _, dc := range dcs {
if el.Failure() != nil {
break
}

var (
err error
category = dc.FullPath().Category()
metrics support.CollectionMetrics
ictx = clues.Add(ctx,
"category", category,
"restore_location", clues.Hide(rcc.RestoreConfig.Location),
"protected_resource", clues.Hide(dc.FullPath().ResourceOwner()),
"full_path", dc.FullPath())
)

switch dc.FullPath().Category() {
case path.LibrariesCategory:
// TODO

default:
return nil, clues.New("data category not supported").
With("category", category).
WithClues(ictx)
}

restoreMetrics = support.CombineMetrics(restoreMetrics, metrics)

if err != nil {
el.AddRecoverable(ctx, err)
}

if errors.Is(err, context.Canceled) {
break
}
}

status := support.CreateStatus(
ctx,
support.Restore,
len(dcs),
restoreMetrics,
rcc.RestoreConfig.Location)

return status, el.Failure()
}
22 changes: 8 additions & 14 deletions src/internal/m365/sharepoint/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,12 @@ import (
"github.com/alcionai/corso/src/pkg/services/m365/api"
)

type statusUpdater interface {
UpdateStatus(status *support.ControllerOperationStatus)
}

// ProduceBackupCollections returns a set of DataCollection which represents the SharePoint data
// for the specified user
func ProduceBackupCollections(
ctx context.Context,
bpc inject.BackupProducerConfig,
ac api.Client,
creds account.M365Config,
su statusUpdater,
su support.StatusUpdater,
errs *fault.Bus,
) ([]data.BackupCollection, *prefixmatcher.StringSetMatcher, bool, error) {
b, err := bpc.Selector.ToSharePointBackup()
Expand Down Expand Up @@ -129,7 +123,7 @@ func ProduceBackupCollections(
bpc.ProtectedResource.ID(),
path.SharePointService,
categories,
su.UpdateStatus,
su,
errs)
if err != nil {
return nil, nil, false, err
Expand All @@ -146,7 +140,7 @@ func collectLists(
bpc inject.BackupProducerConfig,
ac api.Client,
tenantID string,
updater statusUpdater,
su support.StatusUpdater,
errs *fault.Bus,
) ([]data.BackupCollection, error) {
logger.Ctx(ctx).Debug("Creating SharePoint List Collections")
Expand Down Expand Up @@ -181,7 +175,7 @@ func collectLists(
dir,
ac,
List,
updater.UpdateStatus,
su,
bpc.Options)
collection.AddJob(tuple.id)

Expand All @@ -200,7 +194,7 @@ func collectLibraries(
tenantID string,
ssmb *prefixmatcher.StringSetMatchBuilder,
scope selectors.SharePointScope,
updater statusUpdater,
su support.StatusUpdater,
errs *fault.Bus,
) ([]data.BackupCollection, bool, error) {
logger.Ctx(ctx).Debug("creating SharePoint Library collections")
Expand All @@ -211,7 +205,7 @@ func collectLibraries(
&libraryBackupHandler{ad, scope},
tenantID,
bpc.ProtectedResource.ID(),
updater.UpdateStatus,
su,
bpc.Options)
)

Expand All @@ -230,7 +224,7 @@ func collectPages(
bpc inject.BackupProducerConfig,
creds account.M365Config,
ac api.Client,
updater statusUpdater,
su support.StatusUpdater,
errs *fault.Bus,
) ([]data.BackupCollection, error) {
logger.Ctx(ctx).Debug("creating SharePoint Pages collections")
Expand Down Expand Up @@ -277,7 +271,7 @@ func collectPages(
dir,
ac,
Pages,
updater.UpdateStatus,
su,
bpc.Options)
collection.betaService = betaService
collection.AddJob(tuple.ID)
Expand Down
2 changes: 1 addition & 1 deletion src/internal/m365/sharepoint/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func (suite *SharePointPagesSuite) TestCollectPages() {
bpc,
creds,
ac,
&MockGraphService{},
(&MockGraphService{}).UpdateStatus,
fault.New(true))
assert.NoError(t, err, clues.ToCore(err))
assert.NotEmpty(t, col)
Expand Down
45 changes: 45 additions & 0 deletions src/pkg/backup/details/details.go
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,7 @@
Exchange *ExchangeInfo `json:"exchange,omitempty"`
SharePoint *SharePointInfo `json:"sharePoint,omitempty"`
OneDrive *OneDriveInfo `json:"oneDrive,omitempty"`
Groups *GroupsInfo `json:"groups,omitempty"`
// Optional item extension data
Extension *ExtensionData `json:"extension,omitempty"`
}
Expand Down Expand Up @@ -1025,6 +1026,50 @@
return updateFolderWithinDrive(OneDriveItem, i.DriveName, i.DriveID, f)
}

// GroupsInfo describes a groups item
type GroupsInfo struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like it should be singular Group instead of Groups as others are singular, for example OneDriveInfo and ExchangeInfo.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm waffling on that. Groups (and similarly, Teams) with the plural is the formal name of the service. Unlike the others, which are formally named by their singular. Let's talk this over briefly in the meeting tomorrow to see if there are strong feelings either way, yeah?

Created time.Time `json:"created,omitempty"`
DriveName string `json:"driveName,omitempty"`
DriveID string `json:"driveID,omitempty"`
ItemName string `json:"itemName,omitempty"`
ItemType ItemType `json:"itemType,omitempty"`
Modified time.Time `json:"modified,omitempty"`
Owner string `json:"owner,omitempty"`
ParentPath string `json:"parentPath,omitempty"`
Size int64 `json:"size,omitempty"`
}

// Headers returns the human-readable names of properties in a SharePointInfo
// for printing out to a terminal in a columnar display.
func (i GroupsInfo) Headers() []string {
return []string{"Created", "Modified"}
}

// Values returns the values matching the Headers list for printing
// out to a terminal in a columnar display.
func (i GroupsInfo) Values() []string {
return []string{
dttm.FormatToTabularDisplay(i.Created),
dttm.FormatToTabularDisplay(i.Modified),
}
}

func (i *GroupsInfo) UpdateParentPath(newLocPath *path.Builder) {
i.ParentPath = newLocPath.PopFront().String()
}

func (i *GroupsInfo) uniqueLocation(baseLoc *path.Builder) (*uniqueLoc, error) {

Check failure on line 1061 in src/pkg/backup/details/details.go

View workflow job for this annotation

GitHub Actions / Source-Code-Linting

func `(*GroupsInfo).uniqueLocation` is unused (unused)
return nil, clues.New("not yet implemented")
}

func (i *GroupsInfo) updateFolder(f *FolderInfo) error {

Check failure on line 1065 in src/pkg/backup/details/details.go

View workflow job for this annotation

GitHub Actions / Source-Code-Linting

func `(*GroupsInfo).updateFolder` is unused (unused)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can maybe add it to updateFolder. Same for uniqueLocation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I got this in a follow-up PR.

return clues.New("not yet implemented")
}

// ---------------------------------------------------------------------------
// helpers
// ---------------------------------------------------------------------------

func updateFolderWithinDrive(
t ItemType,
driveName, driveID string,
Expand Down
Loading
Loading