Skip to content

Commit

Permalink
🐛 Fix fetching of latest security score. (#3069)
Browse files Browse the repository at this point in the history
Signed-off-by: Preslav <[email protected]>
  • Loading branch information
preslavgerchev authored Jan 19, 2024
1 parent 5b3e794 commit 4198bb6
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions providers/ms365/resources/securescores.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4198bb6

Please sign in to comment.