-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Add page iterator for fetching users and service principals in MS365.
Signed-off-by: Preslav <[email protected]>
- Loading branch information
1 parent
3adc50a
commit 966105c
Showing
3 changed files
with
41 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (c) Mondoo, Inc. | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
package resources | ||
|
||
import ( | ||
"context" | ||
|
||
abstractions "github.com/microsoft/kiota-abstractions-go" | ||
"github.com/microsoft/kiota-abstractions-go/serialization" | ||
msgraphgocore "github.com/microsoftgraph/msgraph-sdk-go-core" | ||
) | ||
|
||
func iterate[T interface{}](ctx context.Context, res interface{}, adapter abstractions.RequestAdapter, constructorFunc serialization.ParsableFactory) ([]T, error) { | ||
resp := []T{} | ||
iterator, err := msgraphgocore.NewPageIterator[T](res, adapter, constructorFunc) | ||
if err != nil { | ||
return nil, transformError(err) | ||
} | ||
err = iterator.Iterate(ctx, func(u T) bool { | ||
resp = append(resp, u) | ||
return true | ||
}) | ||
if err != nil { | ||
return nil, transformError(err) | ||
} | ||
return resp, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters