Skip to content

Commit

Permalink
🧹 dump ms365 output in debug files, stop scripts on error. (#2699)
Browse files Browse the repository at this point in the history
  • Loading branch information
preslavgerchev authored Dec 1, 2023
1 parent 174ede1 commit cb48efb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions providers/ms365/connection/exchange_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
"github.com/pkg/errors"
"go.mondoo.com/cnquery/v9/logger"
)

var exchangeReport = `
Expand Down Expand Up @@ -102,6 +103,9 @@ func (c *Ms365Connection) getReport(outlookToken, organization string) (*Exchang
if err != nil {
return nil, err
}

logger.DebugDumpJSON("exchange-online-report", data)

err = json.Unmarshal(data, report)
if err != nil {
return nil, err
Expand All @@ -112,6 +116,7 @@ func (c *Ms365Connection) getReport(outlookToken, organization string) (*Exchang
return nil, err
}

logger.DebugDumpJSON("exchange-online-report", data)
return nil, fmt.Errorf("failed to generate exchange online report (exit code %d): %s", res.ExitStatus, string(data))
}
return report, nil
Expand Down
6 changes: 6 additions & 0 deletions providers/ms365/connection/sharepoint_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import (
"io"

"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
"go.mondoo.com/cnquery/v9/logger"
)

var sharepointReport = `
$ErrorActionPreference = "Stop"
$token = '%s'
$url = "%s"
Install-Module PnP.PowerShell -Force -Scope CurrentUser -RequiredVersion 1.12.0
Expand Down Expand Up @@ -75,6 +77,9 @@ func (c *Ms365Connection) getSharepointReport(spToken, url string) (*SharepointO
if err != nil {
return nil, err
}

logger.DebugDumpJSON("sharepoint-online-report", string(data))

err = json.Unmarshal(data, report)
if err != nil {
return nil, err
Expand All @@ -85,6 +90,7 @@ func (c *Ms365Connection) getSharepointReport(spToken, url string) (*SharepointO
return nil, err
}

logger.DebugDumpJSON("sharepoint-online-report", string(data))
return nil, fmt.Errorf("failed to generate sharepoint online report (exit code %d): %s", res.ExitStatus, string(data))
}
return report, nil
Expand Down
5 changes: 5 additions & 0 deletions providers/ms365/connection/teams_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import (
"strings"

"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
"go.mondoo.com/cnquery/v9/logger"
)

var teamsReport = `
$ErrorActionPreference = "Stop"
$graphToken= '%s'
$teamsToken = '%s'
Expand Down Expand Up @@ -77,6 +79,8 @@ func (c *Ms365Connection) getTeamsReport(accessToken, teamsToken string) (*MsTea
idx := strings.IndexByte(str, '{')
after := str[idx:]
newData := []byte(after)

logger.DebugDumpJSON("ms-teams-report", string(newData))
err = json.Unmarshal(newData, report)
if err != nil {
return nil, err
Expand All @@ -87,6 +91,7 @@ func (c *Ms365Connection) getTeamsReport(accessToken, teamsToken string) (*MsTea
return nil, err
}

logger.DebugDumpJSON("ms-teams-report", string(data))
return nil, fmt.Errorf("failed to generate ms teams report (exit code %d): %s", res.ExitStatus, string(data))
}
return report, nil
Expand Down

0 comments on commit cb48efb

Please sign in to comment.