Skip to content

Commit

Permalink
add in nobom fix to ScubaCached
Browse files Browse the repository at this point in the history
  • Loading branch information
buidav committed Sep 19, 2024
1 parent 4b94871 commit 5424f50
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
13 changes: 8 additions & 5 deletions PowerShell/ScubaGear/Modules/Orchestrator.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -1733,19 +1733,22 @@ function Invoke-SCuBACached {
Invoke-ProviderList @ProviderParams
}

$FileName = Join-Path -Path $OutPath -ChildPath "$($OutProviderFileName).json"
if (-not (Test-Path $FileName)) {
$ProviderJSONFilePath = Join-Path -Path $OutPath -ChildPath "$($OutProviderFileName).json"
if (-not (Test-Path $ProviderJSONFilePath)) {
# When running Invoke-ScubaCached, the provider output might not exist as a stand-alone
# file depending on what version of ScubaGear created the output. If the provider output
# does not exist as a stand-alone file, create it from the ScubaResults file so the other functions
# can execute as normal.
$ScubaResultsFileName = Join-Path -Path $OutPath -ChildPath "$($OutJsonFileName).json"
$SettingsExport = $(Get-Content $ScubaResultsFileName | ConvertFrom-Json).Raw

# Immediate TODO: Change this to the custom UTF8 NoBOM function when available
$SettingsExport | ConvertTo-Json -Depth 20 | Set-Content -Path $FileName -Encoding $(Get-FileEncoding) -ErrorAction 'Stop'
# Uses the custom UTF8 NoBOM function when available
$ProviderContent = $SettingsExport | ConvertTo-Json -Depth 20
$ActualSavedLocation = Set-Utf8NoBom -Content $ProviderContent `
-Location $ProviderJSONFilePath -FileName "$OutProviderFileName.json"
Write-Debug $ActualSavedLocation
}
$SettingsExport = Get-Content $FileName | ConvertFrom-Json
$SettingsExport = Get-Content $ProviderJSONFilePath | ConvertFrom-Json
$TenantDetails = $SettingsExport.tenant_details
$RegoParams = @{
'ProductNames' = $ProductNames;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ InModuleScope Orchestrator {
function Disconnect-SCuBATenant {}
Mock -ModuleName Orchestrator Disconnect-SCuBATenant

function Set-Utf8NoBom {}
Mock -ModuleName Orchestrator Set-Utf8NoBom

Mock -CommandName Write-Debug {}
Mock -CommandName New-Item {}
Mock -CommandName Get-Content {}
}
Expand Down

0 comments on commit 5424f50

Please sign in to comment.