Skip to content

Commit

Permalink
Refactor escape sequence processing (#822)
Browse files Browse the repository at this point in the history
  • Loading branch information
adhilto authored Jan 25, 2024
1 parent 562d397 commit 2f6b048
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 26 deletions.
10 changes: 8 additions & 2 deletions PowerShell/ScubaGear/Modules/Orchestrator.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -528,8 +528,14 @@ function Invoke-ProviderList {
$ProviderJSON
}
"@
$BaselineSettingsExport = $BaselineSettingsExport.replace("\`"", "'")
$BaselineSettingsExport = $BaselineSettingsExport.replace("\", "")

# Strip the character sequences that Rego tries to interpret as escape sequences,
# resulting in the error "unable to parse input: yaml: line x: found unknown escape character"
# "\/", ex: "\/Date(1705651200000)\/"
$BaselineSettingsExport = $BaselineSettingsExport.replace("\/", "")
# "\B", ex: "Removed an entry in Tenant Allow\Block List"
$BaselineSettingsExport = $BaselineSettingsExport.replace("\B", "/B")

$FinalPath = Join-Path -Path $OutFolderPath -ChildPath "$($OutProviderFileName).json" -ErrorAction 'Stop'
$BaselineSettingsExport | Set-Content -Path $FinalPath -Encoding $(Get-FileEncoding) -ErrorAction 'Stop'
$ProdProviderFailed
Expand Down
5 changes: 0 additions & 5 deletions PowerShell/ScubaGear/Modules/Providers/ExportAADProvider.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,6 @@ function Export-AADProvider {
"aad_unsuccessful_commands": $UnSuccessfulCommands,
"@

# We need to remove the backslash characters from the
# json, otherwise rego gets mad.
$json = $json.replace("\`"", "'")
$json = $json.replace("\", "")

$json
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,5 @@ function Export-DefenderProvider {
"defender_unsuccessful_commands": $UnSuccessfulCommands,
"@

# We need to remove the backslash characters from the
# json, otherwise rego gets mad.
$json = $json.replace("\`"", "'")
$json = $json.replace("\", "")
$json
}
4 changes: 0 additions & 4 deletions PowerShell/ScubaGear/Modules/Providers/ExportEXOProvider.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,6 @@ function Export-EXOProvider {
"exo_unsuccessful_commands": $UnSuccessfulCommands,
"@

# We need to remove the backslash characters from the
# json, otherwise rego gets mad.
$json = $json.replace("\`"", "'")
$json = $json.replace("\", "")
$json
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,6 @@ $($_)
"powerplatform_unsuccessful_commands": $PowerPlatformUnSuccessfulCommands,
"@

# We need to remove the backslash characters from the
# json, otherwise rego gets mad.
$json = $json.replace("\`"", "'")
$json = $json.replace("\", "")
$json = $json -replace "[^\x00-\x7f]","" # remove all characters that are not utf-8
$json
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,5 @@ function Export-SharePointProvider {
"SharePoint_unsuccessful_commands": $UnSuccessfulCommands,
"@

# We need to remove the backslash characters from the json, otherwise rego gets mad.
$json = $json.replace("\`"", "'")
$json = $json.replace("\", "")
$json
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ function Export-TeamsProvider {
"teams_unsuccessful_commands": $TeamsUnSuccessfulCommands,
"@

# We need to remove the backslash characters from the
# json, otherwise rego gets mad.
$json = $json.replace("\`"", "'")
$json = $json.replace("\", "")
$json
}

Expand Down

0 comments on commit 2f6b048

Please sign in to comment.