From fb46f5c7f3f2fef0bbb48abe62f241cb456577cb Mon Sep 17 00:00:00 2001 From: Eno Thereska Date: Mon, 17 Oct 2022 19:17:39 +0100 Subject: [PATCH] Export call to get user ids (#1069) ## Description Exposing user IDs in addition to user emails. ## Type of change - [ ] :sunflower: Feature - [ ] :bug: Bugfix - [ ] :world_map: Documentation - [ ] :robot: Test - [ ] :computer: CI/Deployment - [X] :hamster: Trivial/Minor ## Issue(s) * # ## Test Plan - [ ] :muscle: Manual - [X] :zap: Unit test - [ ] :green_heart: E2E --- src/pkg/services/m365/m365.go | 20 ++++++++++++++++++++ src/pkg/services/m365/m365_test.go | 21 +++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/pkg/services/m365/m365.go b/src/pkg/services/m365/m365.go index 1c7482b56..bb7c949ee 100644 --- a/src/pkg/services/m365/m365.go +++ b/src/pkg/services/m365/m365.go @@ -19,3 +19,23 @@ func Users(ctx context.Context, m365Account account.Account) ([]string, error) { return gc.GetUsers(), nil } + +// UserIDs returns a list of user IDs for the specified M365 tenant +// TODO: Implement paging support +func UserIDs(ctx context.Context, m365Account account.Account) ([]string, error) { + gc, err := connector.NewGraphConnector(ctx, m365Account) + if err != nil { + return nil, errors.Wrap(err, "could not initialize M365 graph connection") + } + + return gc.GetUsersIds(), nil +} + +func GetEmailAndUserID(ctx context.Context, m365Account account.Account) (map[string]string, error) { + gc, err := connector.NewGraphConnector(ctx, m365Account) + if err != nil { + return nil, errors.Wrap(err, "could not initialize M365 graph connection") + } + + return gc.Users, nil +} diff --git a/src/pkg/services/m365/m365_test.go b/src/pkg/services/m365/m365_test.go index 16b0c04f8..bf8d2a881 100644 --- a/src/pkg/services/m365/m365_test.go +++ b/src/pkg/services/m365/m365_test.go @@ -1,6 +1,7 @@ package m365 import ( + "context" "testing" "github.com/stretchr/testify/require" @@ -41,3 +42,23 @@ func (suite *M365IntegrationSuite) TestUsers() { require.NotNil(suite.T(), users) require.Greater(suite.T(), len(users), 0) } + +func (suite *M365IntegrationSuite) TestUserIDs() { + acct := tester.NewM365Account(suite.T()) + + ids, err := UserIDs(context.Background(), acct) + require.NoError(suite.T(), err) + + require.NotNil(suite.T(), ids) + require.Greater(suite.T(), len(ids), 0) +} + +func (suite *M365IntegrationSuite) TestGetEmailAndUserID() { + acct := tester.NewM365Account(suite.T()) + + ids, err := GetEmailAndUserID(context.Background(), acct) + require.NoError(suite.T(), err) + + require.NotNil(suite.T(), ids) + require.Greater(suite.T(), len(ids), 0) +}