Skip to content

Commit

Permalink
Collecting errors from fetching memberships and using a WithContext e…
Browse files Browse the repository at this point in the history
…rror group
  • Loading branch information
mvbrock committed Jan 9, 2025
1 parent 24c1f9d commit 301278b
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/srv/discovery/fetchers/azure-sync/memberships.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,28 @@ import (
const parallelism = 10 //nolint:unused // invoked in a dependent PR

func expandMemberships(ctx context.Context, cli *msgraph.Client, principals []*accessgraphv1alpha.AzurePrincipal) ([]*accessgraphv1alpha.AzurePrincipal, error) { //nolint:unused // invoked in a dependent PR
var eg errgroup.Group
eg, _ := errgroup.WithContext(ctx)
eg.SetLimit(parallelism)
errCh := make(chan error, len(principals))
for _, principal := range principals {
eg.Go(func() error {
err := cli.IterateUserMembership(ctx, principal.Id, func(obj *msgraph.DirectoryObject) bool {
principal.MemberOf = append(principal.MemberOf, *obj.ID)
return true
})
if err != nil {
return trace.Wrap(err)
errCh <- err
}
return nil
})
}
return principals, eg.Wait()
_ = eg.Wait()
var errs []error
for chErr := range errCh {
errs = append(errs, chErr)
}
if len(errs) > 0 {
return nil, trace.NewAggregate(errs...)
}
return principals, nil
}

0 comments on commit 301278b

Please sign in to comment.