From 82e472b35947b7dc78e542d01922a8bc001951ca Mon Sep 17 00:00:00 2001 From: vjeffrey Date: Thu, 24 Oct 2024 12:54:25 -0600 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20catch=20nil=20errors=20when=20as?= =?UTF-8?q?sembling=20ms365=20exchange=20report=20(#4778)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- providers/ms365/resources/ms365_exchange.go | 26 +++++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/providers/ms365/resources/ms365_exchange.go b/providers/ms365/resources/ms365_exchange.go index f192f10cfe..d8c85e3afc 100644 --- a/providers/ms365/resources/ms365_exchange.go +++ b/providers/ms365/resources/ms365_exchange.go @@ -202,6 +202,9 @@ func convertTeamsProtectionPolicy(r *mqlMs365Exchangeonline, data []*TeamsProtec func convertReportSubmissionPolicy(r *mqlMs365Exchangeonline, data []*ReportSubmissionPolicy) ([]interface{}, error) { var result []interface{} for _, t := range data { + if t == nil { + continue + } policy, err := CreateResource(r.MqlRuntime, "ms365.exchangeonline.reportSubmissionPolicy", map[string]*llx.RawData{ "reportJunkToCustomizedAddress": llx.BoolData(t.ReportJunkToCustomizedAddress), @@ -338,6 +341,9 @@ func (r *mqlMs365Exchangeonline) getExchangeReport() error { externalInOutlook := []interface{}{} var externalInOutlookErr error for _, e := range report.ExternalInOutlook { + if e == nil { + continue + } mql, err := CreateResource(r.MqlRuntime, "ms365.exchangeonline.externalSender", map[string]*llx.RawData{ "identity": llx.StringData(e.Identity), @@ -356,6 +362,9 @@ func (r *mqlMs365Exchangeonline) getExchangeReport() error { sharedMailboxes := []interface{}{} var sharedMailboxesErr error for _, m := range report.ExoMailbox { + if m == nil { + continue + } mql, err := CreateResource(r.MqlRuntime, "ms365.exchangeonline.exoMailbox", map[string]*llx.RawData{ "identity": llx.StringData(m.Identity), @@ -371,13 +380,20 @@ func (r *mqlMs365Exchangeonline) getExchangeReport() error { r.SharedMailboxes = plugin.TValue[[]interface{}]{Data: sharedMailboxes, State: plugin.StateIsSet, Error: sharedMailboxesErr} // Related to TeamsProtectionPolicy - teamsProtectionPolicies, teamsProtectionPolicyErr := convertTeamsProtectionPolicy(r, report.TeamsProtectionPolicy) - r.TeamsProtectionPolicies = plugin.TValue[[]interface{}]{Data: teamsProtectionPolicies, State: plugin.StateIsSet, Error: teamsProtectionPolicyErr} + if report.TeamsProtectionPolicy != nil { + teamsProtectionPolicies, teamsProtectionPolicyErr := convertTeamsProtectionPolicy(r, report.TeamsProtectionPolicy) + r.TeamsProtectionPolicies = plugin.TValue[[]interface{}]{Data: teamsProtectionPolicies, State: plugin.StateIsSet, Error: teamsProtectionPolicyErr} + } else { + r.TeamsProtectionPolicies = plugin.TValue[[]interface{}]{State: plugin.StateIsSet | plugin.StateIsNull} + } // Related to ReportSubmissionPolicy - reportSubmissionPolicies, reportSubmissionPolicyErr := convertReportSubmissionPolicy(r, report.ReportSubmissionPolicy) - r.ReportSubmissionPolicies = plugin.TValue[[]interface{}]{Data: reportSubmissionPolicies, State: plugin.StateIsSet, Error: reportSubmissionPolicyErr} - + if report.ReportSubmissionPolicy != nil { + reportSubmissionPolicies, reportSubmissionPolicyErr := convertReportSubmissionPolicy(r, report.ReportSubmissionPolicy) + r.ReportSubmissionPolicies = plugin.TValue[[]interface{}]{Data: reportSubmissionPolicies, State: plugin.StateIsSet, Error: reportSubmissionPolicyErr} + } else { + r.ReportSubmissionPolicies = plugin.TValue[[]interface{}]{State: plugin.StateIsSet | plugin.StateIsNull} + } return nil }