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

View File

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

View File

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

View File

@ -1,6 +1,18 @@
package graph 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 { type Service interface {
// Client() returns msgraph Service client that can be used to process and execute // 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) allCollections := make([]*exchange.Collection, 0)
// Create collection of ExchangeDataCollection // Create collection of ExchangeDataCollection
for _, user := range users { for _, user := range users {
qp := graph.QueryParams{
User: user,
Scope: scope,
FailFast: gc.failFast,
Credentials: gc.credentials,
}
collections := make(map[string]*exchange.Collection) collections := make(map[string]*exchange.Collection)
response, err := query(&gc.graphService, user) response, err := query(&gc.graphService, qp.User)
if err != nil { if err != nil {
return nil, errors.Wrapf( return nil, errors.Wrapf(
err, err,
"user %s M365 query: %s", "user %s M365 query: %s",
user, support.ConnectorStackErrorTrace(err)) qp.User, support.ConnectorStackErrorTrace(err))
} }
pageIterator, err := msgraphgocore.NewPageIterator(response, &gc.graphService.adapter, transformer) 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[] // callbackFunc iterates through all M365 object target and fills exchange.Collection.jobs[]
// with corresponding item M365IDs. New collections are created for each directory. // 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 // 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) iterateError := pageIterator.Iterate(callbackFunc)
if iterateError != nil { if iterateError != nil {