From 4198bb6c9ece9a2cf451fd30137f1016ee6c34e3 Mon Sep 17 00:00:00 2001 From: Preslav Gerchev Date: Fri, 19 Jan 2024 17:19:19 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20fetching=20of=20latest=20s?= =?UTF-8?q?ecurity=20score.=20(#3069)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Preslav --- providers/ms365/resources/securescores.go | 29 ++++++++--------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/providers/ms365/resources/securescores.go b/providers/ms365/resources/securescores.go index 7ab3a6c6c9..747646d02c 100644 --- a/providers/ms365/resources/securescores.go +++ b/providers/ms365/resources/securescores.go @@ -74,31 +74,22 @@ func msSecureScoreToMql(runtime *plugin.Runtime, score models.SecureScoreable) ( } func (a *mqlMicrosoftSecurity) latestSecureScores() (*mqlMicrosoftSecuritySecurityscore, error) { - conn := a.MqlRuntime.Connection.(*connection.Ms365Connection) - graphClient, err := graphClient(conn) - if err != nil { - return nil, err - } - ctx := context.Background() - resp, err := graphClient.Security().SecureScores().Get(ctx, &security.SecureScoresRequestBuilderGetRequestConfiguration{}) - if err != nil { - return nil, transformError(err) + secureScores := a.GetSecureScores() + if secureScores.Error != nil { + return nil, secureScores.Error } - - scores := resp.GetValue() - if len(scores) == 0 { + if len(secureScores.Data) == 0 { return nil, errors.New("could not retrieve any score") } - latestScore := scores[0] - for i := range scores { - score := scores[i] - if score.GetCreatedDateTime() != nil && (latestScore.GetCreatedDateTime() == nil || score.GetCreatedDateTime().Before(*latestScore.GetCreatedDateTime())) { - latestScore = score + latest := secureScores.Data[0].(*mqlMicrosoftSecuritySecurityscore) + for _, s := range secureScores.Data { + mqlS := s.(*mqlMicrosoftSecuritySecurityscore) + if mqlS.CreatedDateTime.Data.After(*latest.CreatedDateTime.Data) { + latest = mqlS } } - - return msSecureScoreToMql(a.MqlRuntime, latestScore) + return latest, nil } // see https://docs.microsoft.com/en-us/graph/api/securescore-get?view=graph-rest-1.0&tabs=http