Cleanup parameters to functions to appease linters (#730)

## Description

Group like parameters to graph functions so SonarCloud is happier

## Type of change

Please check the type of change your PR introduces:
- [ ] 🌻 Feature
- [ ] 🐛 Bugfix
- [ ] 🗺️ Documentation
- [ ] 🤖 Test
- [x] 🐹 Trivial/Minor

## Issue(s)
<!-- Can reference multiple issues. Use one of the following "magic words" - "closes, fixes" to auto-close the Github issue. -->
on the path to:
* #456 

## Test Plan

<!-- How will this be tested prior to merging.-->

- [ ] 💪 Manual
- [x]  Unit test
- [x] 💚 E2E
This commit is contained in:
ashmrtn 2022-09-01 17:26:31 -07:00 committed by GitHub
parent 5e0fe9561c
commit 61ce920972
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 68 additions and 71 deletions

View File

@ -11,6 +11,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"github.com/alcionai/corso/internal/connector/graph"
"github.com/alcionai/corso/internal/connector/mockconnector"
"github.com/alcionai/corso/internal/connector/support"
"github.com/alcionai/corso/internal/tester"
@ -137,6 +138,13 @@ func (suite *ExchangeIteratorSuite) TestIterativeFunctions() {
&service.adapter,
test.transformer)
require.NoError(t, err)
qp := graph.QueryParams{
User: userID,
Scope: test.scope,
Credentials: service.credentials,
FailFast: false,
}
// Create collection for iterate test
collections := make(map[string]*Collection)
var errs error
@ -144,10 +152,8 @@ func (suite *ExchangeIteratorSuite) TestIterativeFunctions() {
// with corresponding item IDs. New collections are created for each directory
callbackFunc := test.iterativeFunction(
ctx,
userID,
test.scope,
errs, false,
service.credentials,
qp,
errs,
collections,
nil)

View File

@ -9,7 +9,6 @@ import (
"github.com/alcionai/corso/internal/connector/graph"
"github.com/alcionai/corso/internal/connector/support"
"github.com/alcionai/corso/pkg/account"
"github.com/alcionai/corso/pkg/selectors"
)
@ -31,11 +30,8 @@ type displayable interface {
// @returns a callback func that works with msgraphgocore.PageIterator.Iterate function
type GraphIterateFunc func(
ctx context.Context,
user string,
scope selectors.ExchangeScope,
qp graph.QueryParams,
errs error,
failFast bool,
credentials account.M365Config,
collections map[string]*Collection,
graphStatusChannel chan<- *support.ConnectorOperationStatus,
) func(any) bool
@ -46,11 +42,8 @@ type GraphIterateFunc func(
// placed into a Collection based on the parent folder
func IterateSelectAllDescendablesForCollections(
ctx context.Context,
user string,
scope selectors.ExchangeScope,
qp graph.QueryParams,
errs error,
failFast bool,
credentials account.M365Config,
collections map[string]*Collection,
statusCh chan<- *support.ConnectorOperationStatus,
) func(any) bool {
@ -63,12 +56,12 @@ func IterateSelectAllDescendablesForCollections(
return func(pageItem any) bool {
// Defines the type of collection being created within the function
if !isCategorySet {
if scope.IncludesCategory(selectors.ExchangeMail) {
if qp.Scope.IncludesCategory(selectors.ExchangeMail) {
collectionType = messages
category = mailCategory
}
if scope.IncludesCategory(selectors.ExchangeContact) {
if qp.Scope.IncludesCategory(selectors.ExchangeContact) {
collectionType = contacts
category = contactsCategory
}
@ -78,21 +71,21 @@ func IterateSelectAllDescendablesForCollections(
entry, ok := pageItem.(descendable)
if !ok {
errs = support.WrapAndAppendf(user, errors.New("descendable conversion failure"), errs)
errs = support.WrapAndAppendf(qp.User, errors.New("descendable conversion failure"), errs)
return true
}
// Saving to messages to list. Indexed by folder
directory := *entry.GetParentFolderId()
if _, ok = collections[directory]; !ok {
service, err := createService(credentials, failFast)
service, err := createService(qp.Credentials, qp.FailFast)
if err != nil {
errs = support.WrapAndAppend(user, err, errs)
errs = support.WrapAndAppend(qp.User, err, errs)
return true
}
edc := NewCollection(
user,
[]string{credentials.TenantID, user, category, directory},
qp.User,
[]string{qp.Credentials.TenantID, qp.User, category, directory},
collectionType,
service,
statusCh,
@ -112,11 +105,8 @@ func IterateSelectAllDescendablesForCollections(
// the calendarID which originates from M365.
func IterateSelectAllEventsForCollections(
ctx context.Context,
user string,
scope selectors.ExchangeScope,
qp graph.QueryParams,
errs error,
failFast bool,
credentials account.M365Config,
collections map[string]*Collection,
statusCh chan<- *support.ConnectorOperationStatus,
) func(any) bool {
@ -124,7 +114,7 @@ func IterateSelectAllEventsForCollections(
event, ok := eventItem.(models.Eventable)
if !ok {
errs = support.WrapAndAppend(
user,
qp.User,
errors.New("event iteration failure"),
errs,
)
@ -137,7 +127,7 @@ func IterateSelectAllEventsForCollections(
value, ok := adtl["calendar@odata.associationLink"]
if !ok {
errs = support.WrapAndAppend(
user,
qp.User,
fmt.Errorf("%s: does not support calendar look up", *event.GetId()),
errs,
)
@ -148,7 +138,7 @@ func IterateSelectAllEventsForCollections(
link, ok := value.(*string)
if !ok || link == nil {
errs = support.WrapAndAppend(
user,
qp.User,
fmt.Errorf("%s: unable to obtain calendar event data", *event.GetId()),
errs,
)
@ -160,7 +150,7 @@ func IterateSelectAllEventsForCollections(
directory, err := parseCalendarIDFromEvent(*link)
if err != nil {
errs = support.WrapAndAppend(
user,
qp.User,
errors.Wrap(err, *event.GetId()),
errs,
)
@ -169,15 +159,15 @@ func IterateSelectAllEventsForCollections(
}
if _, ok := collections[directory]; !ok {
service, err := createService(credentials, failFast)
service, err := createService(qp.Credentials, qp.FailFast)
if err != nil {
errs = support.WrapAndAppend(user, err, errs)
errs = support.WrapAndAppend(qp.User, err, errs)
return true
}
edc := NewCollection(
user,
[]string{credentials.TenantID, user, eventsCategory, directory},
qp.User,
[]string{qp.Credentials.TenantID, qp.User, eventsCategory, directory},
events,
service,
statusCh,
@ -196,11 +186,8 @@ func IterateSelectAllEventsForCollections(
// into a Collection. Messages outside of those directories are omitted.
func IterateAndFilterMessagesForCollections(
ctx context.Context,
user string,
scope selectors.ExchangeScope,
qp graph.QueryParams,
errs error,
failFast bool,
credentials account.M365Config,
collections map[string]*Collection,
statusCh chan<- *support.ConnectorOperationStatus,
) func(any) bool {
@ -210,15 +197,12 @@ func IterateAndFilterMessagesForCollections(
if !isFilterSet {
err := CollectMailFolders(
ctx,
scope,
user,
qp,
collections,
credentials,
failFast,
statusCh,
)
if err != nil {
errs = support.WrapAndAppend(user, err, errs)
errs = support.WrapAndAppend(qp.User, err, errs)
return false
}
@ -227,7 +211,7 @@ func IterateAndFilterMessagesForCollections(
message, ok := messageItem.(descendable)
if !ok {
errs = support.WrapAndAppend(user, errors.New("message iteration failure"), errs)
errs = support.WrapAndAppend(qp.User, errors.New("message iteration failure"), errs)
return true
}
// Saving only messages for the created directories
@ -244,11 +228,8 @@ func IterateAndFilterMessagesForCollections(
func IterateFilterFolderDirectoriesForCollections(
ctx context.Context,
user string,
scope selectors.ExchangeScope,
qp graph.QueryParams,
errs error,
failFast bool,
credentials account.M365Config,
collections map[string]*Collection,
statusCh chan<- *support.ConnectorOperationStatus,
) func(any) bool {
@ -261,7 +242,7 @@ func IterateFilterFolderDirectoriesForCollections(
folder, ok := folderItem.(displayable)
if !ok {
errs = support.WrapAndAppend(
user,
qp.User,
errors.New("unable to transform folderable item"),
errs,
)
@ -273,19 +254,19 @@ func IterateFilterFolderDirectoriesForCollections(
return true
}
if !scope.Matches(selectors.ExchangeMailFolder, *folder.GetDisplayName()) {
if !qp.Scope.Matches(selectors.ExchangeMailFolder, *folder.GetDisplayName()) {
return true
}
directory := *folder.GetId()
service, err = createService(credentials, failFast)
service, err = createService(qp.Credentials, qp.FailFast)
if err != nil {
errs = support.WrapAndAppend(
*folder.GetDisplayName(),
errors.Wrap(
err,
"unable to create service a folder query service for "+user,
"unable to create service a folder query service for "+qp.User,
),
errs,
)
@ -294,8 +275,8 @@ func IterateFilterFolderDirectoriesForCollections(
}
temp := NewCollection(
user,
[]string{credentials.TenantID, user, mailCategory, directory},
qp.User,
[]string{qp.Credentials.TenantID, qp.User, mailCategory, directory},
messages,
service,
statusCh,

View File

@ -11,8 +11,6 @@ import (
"github.com/alcionai/corso/internal/connector/graph"
"github.com/alcionai/corso/internal/connector/support"
"github.com/alcionai/corso/pkg/account"
"github.com/alcionai/corso/pkg/selectors"
)
// GraphQuery represents functions which perform exchange-specific queries
@ -126,23 +124,20 @@ func RetrieveMessageDataForUser(gs graph.Service, user, m365ID string) (absser.P
func CollectMailFolders(
ctx context.Context,
scope selectors.ExchangeScope,
user string,
qp graph.QueryParams,
collections map[string]*Collection,
credentials account.M365Config,
failFast bool,
statusCh chan<- *support.ConnectorOperationStatus,
) error {
queryService, err := createService(credentials, failFast)
queryService, err := createService(qp.Credentials, qp.FailFast)
if err != nil {
return errors.New("unable to create a mail folder query service for " + user)
return errors.New("unable to create a mail folder query service for " + qp.User)
}
query, err := GetAllFolderNamesForUser(queryService, user)
query, err := GetAllFolderNamesForUser(queryService, qp.User)
if err != nil {
return fmt.Errorf(
"unable to query mail folder for %s: details: %s",
user,
qp.User,
support.ConnectorStackErrorTrace(err),
)
}
@ -158,18 +153,15 @@ func CollectMailFolders(
callbackFunc := IterateFilterFolderDirectoriesForCollections(
ctx,
user,
scope,
qp,
err,
failFast,
credentials,
collections,
statusCh,
)
iterateFailure := pageIterator.Iterate(callbackFunc)
if iterateFailure != nil {
err = support.WrapAndAppend(user+" iterate failure", iterateFailure, err)
err = support.WrapAndAppend(qp.User+" iterate failure", iterateFailure, err)
}
return err

View File

@ -1,6 +1,18 @@
package graph
import msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
import (
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
"github.com/alcionai/corso/pkg/account"
"github.com/alcionai/corso/pkg/selectors"
)
type QueryParams struct {
User string
Scope selectors.ExchangeScope
Credentials account.M365Config
FailFast bool
}
type Service interface {
// Client() returns msgraph Service client that can be used to process and execute

View File

@ -332,14 +332,20 @@ func (gc *GraphConnector) createCollections(
allCollections := make([]*exchange.Collection, 0)
// Create collection of ExchangeDataCollection
for _, user := range users {
qp := graph.QueryParams{
User: user,
Scope: scope,
FailFast: gc.failFast,
Credentials: gc.credentials,
}
collections := make(map[string]*exchange.Collection)
response, err := query(&gc.graphService, user)
response, err := query(&gc.graphService, qp.User)
if err != nil {
return nil, errors.Wrapf(
err,
"user %s M365 query: %s",
user, support.ConnectorStackErrorTrace(err))
qp.User, support.ConnectorStackErrorTrace(err))
}
pageIterator, err := msgraphgocore.NewPageIterator(response, &gc.graphService.adapter, transformer)
@ -350,7 +356,7 @@ func (gc *GraphConnector) createCollections(
// callbackFunc iterates through all M365 object target and fills exchange.Collection.jobs[]
// with corresponding item M365IDs. New collections are created for each directory.
// Each directory used the M365 Identifier. The use of ID stops collisions betweens users
callbackFunc := gIter(ctx, user, scope, errs, gc.failFast, gc.credentials, collections, gc.statusCh)
callbackFunc := gIter(ctx, qp, errs, collections, gc.statusCh)
iterateError := pageIterator.Iterate(callbackFunc)
if iterateError != nil {