MCPcopy Create free account
hub / github.com/bytebase/bytebase / getIDByEmail

Method getIDByEmail

backend/plugin/webhook/teams/app.go:205–242  ·  view source on GitHub ↗

getIDByEmail gets user AAD object ID by email using Microsoft Graph API. https://learn.microsoft.com/en-us/graph/api/user-get

(ctx context.Context, emails []string)

Source from the content-addressed store, hash-verified

203// getIDByEmail gets user AAD object ID by email using Microsoft Graph API.
204// https://learn.microsoft.com/en-us/graph/api/user-get
205func (p *provider) getIDByEmail(ctx context.Context, emails []string) (map[string]string, error) {
206 userID := make(map[string]string)
207 var emailsToGet []string
208
209 for _, email := range emails {
210 id, ok := userIDCache.Get(email)
211 if ok {
212 if id != "" {
213 userID[email] = id
214 }
215 } else {
216 emailsToGet = append(emailsToGet, email)
217 }
218 }
219
220 if len(emailsToGet) == 0 {
221 return userID, nil
222 }
223
224 if p.graphToken == "" {
225 if err := p.refreshGraphToken(ctx); err != nil {
226 return nil, errors.Wrapf(err, "failed to refresh graph token")
227 }
228 }
229
230 for _, email := range emailsToGet {
231 id, err := p.getUserIDByEmail(ctx, email)
232 if err != nil {
233 // Cache empty string for not found users to avoid repeated lookups.
234 userIDCache.Add(email, "")
235 continue
236 }
237 userID[email] = id
238 userIDCache.Add(email, id)
239 }
240
241 return userID, nil
242}
243
244// usersResponse is the response from Microsoft Graph API for user list queries.
245type usersResponse struct {

Callers 2

postDirectMessageFunction · 0.45
ValidateFunction · 0.45

Calls 3

refreshGraphTokenMethod · 0.95
getUserIDByEmailMethod · 0.95
GetMethod · 0.80

Tested by

no test coverage detected