Skip to content

Commit

Permalink
🐛 Fetch all microsoft groups using the iterator. (#3647)
Browse files Browse the repository at this point in the history
Signed-off-by: Preslav <[email protected]>
  • Loading branch information
preslavgerchev authored Mar 26, 2024
1 parent 1d86261 commit 436a016
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions providers/ms365/resources/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"errors"

"github.com/microsoftgraph/msgraph-sdk-go/groups"
"github.com/microsoftgraph/msgraph-sdk-go/models"

"go.mondoo.com/cnquery/v10/llx"
"go.mondoo.com/cnquery/v10/providers/ms365/connection"
)
Expand All @@ -27,14 +29,22 @@ func (a *mqlMicrosoft) groups() ([]interface{}, error) {
return nil, err
}

top := int32(200)
queryParams := &groups.GroupsRequestBuilderGetQueryParameters{
Top: &top,
}
ctx := context.Background()
resp, err := graphClient.Groups().Get(ctx, &groups.GroupsRequestBuilderGetRequestConfiguration{})
resp, err := graphClient.Groups().Get(ctx, &groups.GroupsRequestBuilderGetRequestConfiguration{
QueryParameters: queryParams,
})
if err != nil {
return nil, transformError(err)
}
grps, err := iterate[*models.Group](ctx, resp, graphClient.GetAdapter(), groups.CreateDeltaGetResponseFromDiscriminatorValue)
if err != nil {
return nil, transformError(err)
}

res := []interface{}{}
grps := resp.GetValue()
for _, grp := range grps {
graphGrp, err := CreateResource(a.MqlRuntime, "microsoft.group",
map[string]*llx.RawData{
Expand Down

0 comments on commit 436a016

Please sign in to comment.