From 436a016653c0f2d351a61139d925db9b762e0a17 Mon Sep 17 00:00:00 2001 From: Preslav Gerchev Date: Tue, 26 Mar 2024 14:49:06 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fetch=20all=20microsoft=20groups?= =?UTF-8?q?=20using=20the=20iterator.=20(#3647)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Preslav --- providers/ms365/resources/groups.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/providers/ms365/resources/groups.go b/providers/ms365/resources/groups.go index c677280311..e93a251c27 100644 --- a/providers/ms365/resources/groups.go +++ b/providers/ms365/resources/groups.go @@ -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" ) @@ -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{