diff --git a/src/cmd/factory/exchange.go b/src/cmd/factory/exchange.go index b7bbb4afa..6a292a8dc 100644 --- a/src/cmd/factory/exchange.go +++ b/src/cmd/factory/exchange.go @@ -47,7 +47,7 @@ func handleExchangeEmailFactory(cmd *cobra.Command, args []string) error { return nil } - gc, tenantID, err := getGCAndVerifyUser(ctx, user) + gc, acct, err := getGCAndVerifyUser(ctx, user) if err != nil { return Only(ctx, err) } @@ -55,10 +55,11 @@ func handleExchangeEmailFactory(cmd *cobra.Command, args []string) error { deets, err := generateAndRestoreItems( ctx, gc, + acct, service, category, selectors.NewExchangeRestore([]string{user}).Selector, - tenantID, user, destination, + user, destination, count, func(id, now, subject, body string) []byte { return mockconnector.GetMockMessageWith( @@ -87,7 +88,7 @@ func handleExchangeCalendarEventFactory(cmd *cobra.Command, args []string) error return nil } - gc, tenantID, err := getGCAndVerifyUser(ctx, user) + gc, acct, err := getGCAndVerifyUser(ctx, user) if err != nil { return Only(ctx, err) } @@ -95,10 +96,11 @@ func handleExchangeCalendarEventFactory(cmd *cobra.Command, args []string) error deets, err := generateAndRestoreItems( ctx, gc, + acct, service, category, selectors.NewExchangeRestore([]string{user}).Selector, - tenantID, user, destination, + user, destination, count, func(id, now, subject, body string) []byte { return mockconnector.GetMockEventWith( @@ -126,7 +128,7 @@ func handleExchangeContactFactory(cmd *cobra.Command, args []string) error { return nil } - gc, tenantID, err := getGCAndVerifyUser(ctx, user) + gc, acct, err := getGCAndVerifyUser(ctx, user) if err != nil { return Only(ctx, err) } @@ -134,10 +136,11 @@ func handleExchangeContactFactory(cmd *cobra.Command, args []string) error { deets, err := generateAndRestoreItems( ctx, gc, + acct, service, category, selectors.NewExchangeRestore([]string{user}).Selector, - tenantID, user, destination, + user, destination, count, func(id, now, subject, body string) []byte { given, mid, sur := id[:8], id[9:13], id[len(id)-12:] diff --git a/src/cmd/factory/factory.go b/src/cmd/factory/factory.go index 361c7625c..30474f32c 100644 --- a/src/cmd/factory/factory.go +++ b/src/cmd/factory/factory.go @@ -108,10 +108,11 @@ type dataBuilderFunc func(id, now, subject, body string) []byte func generateAndRestoreItems( ctx context.Context, gc *connector.GraphConnector, + acct account.Account, service path.ServiceType, cat path.CategoryType, sel selectors.Selector, - tenantID, userID, destFldr string, + userID, destFldr string, howMany int, dbf dataBuilderFunc, ) (*details.Details, error) { @@ -144,7 +145,7 @@ func generateAndRestoreItems( dataColls, err := buildCollections( service, - tenantID, userID, + acct.ID(), userID, dest, collections, ) @@ -154,14 +155,14 @@ func generateAndRestoreItems( Infof(ctx, "Generating %d %s items in %s\n", howMany, cat, destination) - return gc.RestoreDataCollections(ctx, sel, dest, dataColls) + return gc.RestoreDataCollections(ctx, acct, sel, dest, dataColls) } // ------------------------------------------------------------------------------------------ // Common Helpers // ------------------------------------------------------------------------------------------ -func getGCAndVerifyUser(ctx context.Context, userID string) (*connector.GraphConnector, string, error) { +func getGCAndVerifyUser(ctx context.Context, userID string) (*connector.GraphConnector, account.Account, error) { tid := common.First(tenant, os.Getenv(account.AzureTenantID)) // get account info @@ -172,13 +173,13 @@ func getGCAndVerifyUser(ctx context.Context, userID string) (*connector.GraphCon acct, err := account.NewAccount(account.ProviderM365, m365Cfg) if err != nil { - return nil, "", errors.Wrap(err, "finding m365 account details") + return nil, account.Account{}, errors.Wrap(err, "finding m365 account details") } // build a graph connector gc, err := connector.NewGraphConnector(ctx, acct, connector.Users) if err != nil { - return nil, "", errors.Wrap(err, "connecting to graph api") + return nil, account.Account{}, errors.Wrap(err, "connecting to graph api") } normUsers := map[string]struct{}{} @@ -188,10 +189,10 @@ func getGCAndVerifyUser(ctx context.Context, userID string) (*connector.GraphCon } if _, ok := normUsers[strings.ToLower(user)]; !ok { - return nil, "", errors.New("user not found within tenant") + return nil, account.Account{}, errors.New("user not found within tenant") } - return gc, tid, nil + return gc, acct, nil } type item struct { diff --git a/src/internal/connector/exchange/api/api.go b/src/internal/connector/exchange/api/api.go index 8c8ad3392..93a25e13d 100644 --- a/src/internal/connector/exchange/api/api.go +++ b/src/internal/connector/exchange/api/api.go @@ -83,5 +83,6 @@ func newService(creds account.M365Config) (*graph.Service, error) { if err != nil { return nil, errors.Wrap(err, "generating graph api service client") } + return graph.NewService(adapter), nil } diff --git a/src/internal/connector/exchange/api/api_test.go b/src/internal/connector/exchange/api/api_test.go index dffd398ff..00291087f 100644 --- a/src/internal/connector/exchange/api/api_test.go +++ b/src/internal/connector/exchange/api/api_test.go @@ -164,7 +164,8 @@ func (suite *ExchangeServiceSuite) TestGraphQueryFunctions() { ctx, flush := tester.NewContext() defer flush() - c := Client{suite.credentials} + c, err := NewClient(suite.credentials) + require.NoError(suite.T(), err) userID := tester.M365UserID(suite.T()) tests := []struct {