Skip to content

Commit

Permalink
Add Policy Group Names to ScubaResults.json (#1041)
Browse files Browse the repository at this point in the history
* package Report Results by control group

* finish comment

* upgrade the ScubaGear ScubaResults metadata with even more context

* make comment clearer

* make another comment clearer
  • Loading branch information
buidav committed Apr 16, 2024
1 parent 47c2871 commit 65f333c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
10 changes: 8 additions & 2 deletions PowerShell/ScubaGear/Modules/CreateReport/CreateReport.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,13 @@ function New-Report {
$GroupAnchor = New-MarkdownAnchor -GroupNumber $BaselineGroup.GroupNumber -GroupName $BaselineGroup.GroupName
$MarkdownLink = "<a class='control_group' href=`"$($ScubaGitHubUrl)/blob/v$($SettingsExport.module_version)/PowerShell/ScubaGear/baselines/$($BaselineName.ToLower()).md$GroupAnchor`" target=`"_blank`">$Name</a>"
$Fragments += $Fragment | ConvertTo-Html -PreContent "<h2>$Number $MarkdownLink</h2>" -Fragment
$ReportJson.Results += $Fragment

# Package Assessment Report into Report JSON by Policy Group
$ReportJson.Results += [pscustomobject]@{
GroupName = $BaselineGroup.GroupName;
GroupNumber = $BaselineGroup.GroupNumber;
Controls = $Fragment;
}

# Regex will filter out any <table> tags without an id attribute (replace new fragments only, not <table> tags which have already been modified)
$Fragments = $Fragments -replace ".*(<table(?![^>]+id)*>)", "<table class='policy-data' id='$Number'>"
Expand All @@ -178,7 +184,7 @@ function New-Report {
# Craft the json report
$ReportJson.ReportSummary = $ReportSummary
$JsonFileName = Join-Path -Path $IndividualReportPath -ChildPath "$($BaselineName)Report.json"
$ReportJson = ConvertTo-Json @($ReportJson) -Depth 3
$ReportJson = ConvertTo-Json @($ReportJson) -Depth 5

# ConvertTo-Json for some reason converts the <, >, and ' characters into unicode escape sequences.
# Convert those back to ASCII.
Expand Down
18 changes: 15 additions & 3 deletions PowerShell/ScubaGear/Modules/Orchestrator.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -823,14 +823,25 @@ function Merge-JsonOutput {
$SettingsExport = Get-Content $SettingsExportPath -Raw
$TimestampZulu = $(ConvertFrom-Json $SettingsExport).timestamp_zulu

# Get a list and abbreviation mapping of the products assessed
$FullNames = @()
$ProductAbbreviationMapping = @{}
foreach ($ProductName in $ProductNames) {
$BaselineName = $ArgToProd[$ProductName]
$FullNames += $ProdToFullName[$BaselineName]
$ProductAbbreviationMapping[$ProdToFullName[$BaselineName]] = $BaselineName
}

# Extract the metadata
$Results = [pscustomobject]@{}
$Summary = [pscustomobject]@{}
$MetaData = [pscustomobject]@{
"TenantId" = $TenantDetails.TenantId;
"DisplayName" = $TenantDetails.DisplayName;
"DomainName" = $TenantDetails.DomainName;
"Product" = "M365";
"ProductSuite" = "Microsoft 365";
"ProductsAssessed" = $FullNames;
"ProductAbbreviationMapping" = $ProductAbbreviationMapping
"Tool" = "ScubaGear";
"ToolVersion" = $ModuleVersion;
"TimestampZulu" = $TimestampZulu;
Expand All @@ -844,6 +855,7 @@ function Merge-JsonOutput {
$FileName = Join-Path $IndividualReportPath "$($BaselineName)Report.json"
$DeletionList += $FileName
$IndividualResults = Get-Content $FileName | ConvertFrom-Json

$Results | Add-Member -NotePropertyName $BaselineName `
-NotePropertyValue $IndividualResults.Results

Expand All @@ -855,8 +867,8 @@ function Merge-JsonOutput {
}

# Convert the output a json string
$MetaData = ConvertTo-Json $MetaData
$Results = ConvertTo-Json $Results -Depth 3
$MetaData = ConvertTo-Json $MetaData -Depth 3
$Results = ConvertTo-Json $Results -Depth 5
$Summary = ConvertTo-Json $Summary -Depth 3
$ReportJson = @"
{
Expand Down

0 comments on commit 65f333c

Please sign in to comment.