Export call to get user ids (#1069)

## Description

Exposing user IDs in addition to user emails.

## Type of change

<!--- Please check the type of change your PR introduces: --->
- [ ] 🌻 Feature
- [ ] 🐛 Bugfix
- [ ] 🗺️ Documentation
- [ ] 🤖 Test
- [ ] 💻 CI/Deployment
- [X] 🐹 Trivial/Minor

## 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
- [X]  Unit test
- [ ] 💚 E2E
This commit is contained in:
Eno Thereska 2022-10-17 19:17:39 +01:00 committed by GitHub
parent 72a3c7ab3b
commit fb46f5c7f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 0 deletions

View File

@ -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
}

View File

@ -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)
}