Abin Simon a3d573973e
Drop GroupsMap in favor of api.GetAllIDsAndNames (#4967)
Follow up from https://github.com/alcionai/corso/pull/4955#discussion_r1440922835

---

#### Does this PR need a docs update or release note?

- [ ]  Yes, it's included
- [ ] 🕐 Yes, but in a later PR
- [x]  No

#### Type of change

<!--- Please check the type of change your PR introduces: --->
- [ ] 🌻 Feature
- [ ] 🐛 Bugfix
- [ ] 🗺️ Documentation
- [ ] 🤖 Supportability/Tests
- [ ] 💻 CI/Deployment
- [x] 🧹 Tech Debt/Cleanup

#### Issue(s)

<!-- Can reference multiple issues. Use one of the following "magic words" - "closes, fixes" to auto-close the Github issue. -->
* #<issue>

#### Test Plan

<!-- How will this be tested prior to merging.-->
- [ ] 💪 Manual
- [ ]  Unit test
- [x] 💚 E2E
2024-01-08 14:19:33 +00:00

70 lines
1.8 KiB
Go

package m365
import (
"context"
"github.com/alcionai/clues"
"github.com/alcionai/corso/src/pkg/account"
"github.com/alcionai/corso/src/pkg/control"
"github.com/alcionai/corso/src/pkg/count"
"github.com/alcionai/corso/src/pkg/fault"
"github.com/alcionai/corso/src/pkg/path"
"github.com/alcionai/corso/src/pkg/services/m365/api"
"github.com/alcionai/corso/src/pkg/services/m365/api/graph"
)
type client struct {
AC api.Client
}
func NewM365Client(
ctx context.Context,
acct account.Account,
opts ...graph.Option,
) (client, error) {
ac, err := makeAC(ctx, acct, opts...)
return client{ac}, clues.Stack(err).OrNil()
}
// ---------------------------------------------------------------------------
// interfaces & structs
// ---------------------------------------------------------------------------
type getAller[T any] interface {
GetAll(ctx context.Context, errs *fault.Bus) ([]T, error)
}
// ---------------------------------------------------------------------------
// helpers
// ---------------------------------------------------------------------------
func makeAC(
ctx context.Context,
acct account.Account,
opts ...graph.Option,
) (api.Client, error) {
// exchange service inits a limit to concurrency.
api.InitConcurrencyLimit(ctx, path.ExchangeService)
creds, err := acct.M365Config()
if err != nil {
return api.Client{}, clues.WrapWC(ctx, err, "getting m365 account creds")
}
cli, err := api.NewClient(
creds,
control.DefaultOptions(),
count.New())
if err != nil {
return api.Client{}, clues.WrapWC(ctx, err, "constructing api client")
}
// run a test to ensure credentials work for the client
if err := cli.Access().GetToken(ctx); err != nil {
return api.Client{}, clues.Wrap(err, "checking client connection")
}
return cli, nil
}