-
Notifications
You must be signed in to change notification settings - Fork 28
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
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9e655e0
add basic groups boilerplate
ryanfkeepers 3526530
split details into multiple files (#3972)
ryanfkeepers 4c998a1
Merge branch 'main' into groups-boilerplate
aviator-app[bot] de6ef5c
appease the whitespace linter
ryanfkeepers 8d0073f
Merge branch 'main' into groups-boilerplate
aviator-app[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
||
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"` | ||
} | ||
|
@@ -1025,6 +1026,50 @@ | |
return updateFolderWithinDrive(OneDriveItem, i.DriveName, i.DriveID, f) | ||
} | ||
|
||
// GroupsInfo describes a groups item | ||
type GroupsInfo struct { | ||
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) { | ||
return nil, clues.New("not yet implemented") | ||
} | ||
|
||
func (i *GroupsInfo) updateFolder(f *FolderInfo) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can maybe add it to There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 ofGroups
as others are singular, for exampleOneDriveInfo
andExchangeInfo
.There was a problem hiding this comment.
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?