linter and error fixes
This commit is contained in:
parent
3246f6135e
commit
2c96d06de5
@ -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:]
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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 {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user