Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 catch nil errors when assembling ms365 exchange report #4778

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions providers/ms365/resources/ms365_exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand All @@ -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),
Expand All @@ -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
}

Expand Down
Loading