Keepers b3d4b4687b
discovery api, filter guest and external users (#2188)
## Description

Adds the api client pkg pattern to the connector/
discovery package.  Most code changes are plain
lift-n-shift, with minor clean-ups along the way.

User retrieval is now filtered to only include
member and on-premise accounts.

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

- [x]  Yes, it's included

## Type of change

- [x] 🌻 Feature

## Issue(s)

* #2094

## Test Plan

- [x] 💪 Manual
- [x]  Unit test
2023-01-20 20:09:59 +00:00

55 lines
1.3 KiB
Go

package discovery
import (
"context"
"github.com/microsoftgraph/msgraph-sdk-go/models"
"github.com/pkg/errors"
"github.com/alcionai/corso/src/internal/connector/discovery/api"
)
// ---------------------------------------------------------------------------
// interfaces
// ---------------------------------------------------------------------------
type getAller interface {
GetAll(context.Context) ([]models.Userable, error)
}
type getter interface {
GetByID(context.Context, string) (models.Userable, error)
}
type getInfoer interface {
GetInfo(context.Context, string) (*api.UserInfo, error)
}
type getWithInfoer interface {
getter
getInfoer
}
// ---------------------------------------------------------------------------
// api
// ---------------------------------------------------------------------------
// Users fetches all users in the tenant.
func Users(ctx context.Context, ga getAller) ([]models.Userable, error) {
return ga.GetAll(ctx)
}
func User(ctx context.Context, gwi getWithInfoer, userID string) (models.Userable, *api.UserInfo, error) {
u, err := gwi.GetByID(ctx, userID)
if err != nil {
return nil, nil, errors.Wrap(err, "getting user")
}
ui, err := gwi.GetInfo(ctx, userID)
if err != nil {
return nil, nil, errors.Wrap(err, "getting user info")
}
return u, ui, nil
}