linter and error fixes

This commit is contained in:
ryanfkeepers 2023-01-03 14:55:02 -07:00
parent 3246f6135e
commit 2c96d06de5
4 changed files with 21 additions and 15 deletions

View File

@ -47,7 +47,7 @@ func handleExchangeEmailFactory(cmd *cobra.Command, args []string) error {
return nil return nil
} }
gc, tenantID, err := getGCAndVerifyUser(ctx, user) gc, acct, err := getGCAndVerifyUser(ctx, user)
if err != nil { if err != nil {
return Only(ctx, err) return Only(ctx, err)
} }
@ -55,10 +55,11 @@ func handleExchangeEmailFactory(cmd *cobra.Command, args []string) error {
deets, err := generateAndRestoreItems( deets, err := generateAndRestoreItems(
ctx, ctx,
gc, gc,
acct,
service, service,
category, category,
selectors.NewExchangeRestore([]string{user}).Selector, selectors.NewExchangeRestore([]string{user}).Selector,
tenantID, user, destination, user, destination,
count, count,
func(id, now, subject, body string) []byte { func(id, now, subject, body string) []byte {
return mockconnector.GetMockMessageWith( return mockconnector.GetMockMessageWith(
@ -87,7 +88,7 @@ func handleExchangeCalendarEventFactory(cmd *cobra.Command, args []string) error
return nil return nil
} }
gc, tenantID, err := getGCAndVerifyUser(ctx, user) gc, acct, err := getGCAndVerifyUser(ctx, user)
if err != nil { if err != nil {
return Only(ctx, err) return Only(ctx, err)
} }
@ -95,10 +96,11 @@ func handleExchangeCalendarEventFactory(cmd *cobra.Command, args []string) error
deets, err := generateAndRestoreItems( deets, err := generateAndRestoreItems(
ctx, ctx,
gc, gc,
acct,
service, service,
category, category,
selectors.NewExchangeRestore([]string{user}).Selector, selectors.NewExchangeRestore([]string{user}).Selector,
tenantID, user, destination, user, destination,
count, count,
func(id, now, subject, body string) []byte { func(id, now, subject, body string) []byte {
return mockconnector.GetMockEventWith( return mockconnector.GetMockEventWith(
@ -126,7 +128,7 @@ func handleExchangeContactFactory(cmd *cobra.Command, args []string) error {
return nil return nil
} }
gc, tenantID, err := getGCAndVerifyUser(ctx, user) gc, acct, err := getGCAndVerifyUser(ctx, user)
if err != nil { if err != nil {
return Only(ctx, err) return Only(ctx, err)
} }
@ -134,10 +136,11 @@ func handleExchangeContactFactory(cmd *cobra.Command, args []string) error {
deets, err := generateAndRestoreItems( deets, err := generateAndRestoreItems(
ctx, ctx,
gc, gc,
acct,
service, service,
category, category,
selectors.NewExchangeRestore([]string{user}).Selector, selectors.NewExchangeRestore([]string{user}).Selector,
tenantID, user, destination, user, destination,
count, count,
func(id, now, subject, body string) []byte { func(id, now, subject, body string) []byte {
given, mid, sur := id[:8], id[9:13], id[len(id)-12:] given, mid, sur := id[:8], id[9:13], id[len(id)-12:]

View File

@ -108,10 +108,11 @@ type dataBuilderFunc func(id, now, subject, body string) []byte
func generateAndRestoreItems( func generateAndRestoreItems(
ctx context.Context, ctx context.Context,
gc *connector.GraphConnector, gc *connector.GraphConnector,
acct account.Account,
service path.ServiceType, service path.ServiceType,
cat path.CategoryType, cat path.CategoryType,
sel selectors.Selector, sel selectors.Selector,
tenantID, userID, destFldr string, userID, destFldr string,
howMany int, howMany int,
dbf dataBuilderFunc, dbf dataBuilderFunc,
) (*details.Details, error) { ) (*details.Details, error) {
@ -144,7 +145,7 @@ func generateAndRestoreItems(
dataColls, err := buildCollections( dataColls, err := buildCollections(
service, service,
tenantID, userID, acct.ID(), userID,
dest, dest,
collections, collections,
) )
@ -154,14 +155,14 @@ func generateAndRestoreItems(
Infof(ctx, "Generating %d %s items in %s\n", howMany, cat, destination) 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 // 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)) tid := common.First(tenant, os.Getenv(account.AzureTenantID))
// get account info // get account info
@ -172,13 +173,13 @@ func getGCAndVerifyUser(ctx context.Context, userID string) (*connector.GraphCon
acct, err := account.NewAccount(account.ProviderM365, m365Cfg) acct, err := account.NewAccount(account.ProviderM365, m365Cfg)
if err != nil { 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 // build a graph connector
gc, err := connector.NewGraphConnector(ctx, acct, connector.Users) gc, err := connector.NewGraphConnector(ctx, acct, connector.Users)
if err != nil { 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{}{} normUsers := map[string]struct{}{}
@ -188,10 +189,10 @@ func getGCAndVerifyUser(ctx context.Context, userID string) (*connector.GraphCon
} }
if _, ok := normUsers[strings.ToLower(user)]; !ok { 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 { type item struct {

View File

@ -83,5 +83,6 @@ func newService(creds account.M365Config) (*graph.Service, error) {
if err != nil { if err != nil {
return nil, errors.Wrap(err, "generating graph api service client") return nil, errors.Wrap(err, "generating graph api service client")
} }
return graph.NewService(adapter), nil return graph.NewService(adapter), nil
} }

View File

@ -164,7 +164,8 @@ func (suite *ExchangeServiceSuite) TestGraphQueryFunctions() {
ctx, flush := tester.NewContext() ctx, flush := tester.NewContext()
defer flush() defer flush()
c := Client{suite.credentials} c, err := NewClient(suite.credentials)
require.NoError(suite.T(), err)
userID := tester.M365UserID(suite.T()) userID := tester.M365UserID(suite.T())
tests := []struct { tests := []struct {