forked from KelvinTegelaar/CIPP-API
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
- Loading branch information
Showing
6 changed files
with
226 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
Modules/CIPPCore/Public/Standards/Convert-SingleStandardObject.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
function Convert-SingleStandardObject { | ||
param( | ||
[Parameter(Mandatory = $true)] | ||
$Obj | ||
) | ||
|
||
# Ensure we have a PSCustomObject we can modify | ||
$Obj = [pscustomobject]$Obj | ||
|
||
# Extract action arrays | ||
$AllActionValues = @() | ||
if ($Obj.PSObject.Properties.Name -contains 'combinedActions') { | ||
$AllActionValues = $Obj.combinedActions | ||
$Obj.PSObject.Properties.Remove('combinedActions') | Out-Null | ||
} elseif ($Obj.PSObject.Properties.Name -contains 'action') { | ||
if ($Obj.action -and $Obj.action.value) { | ||
$AllActionValues = $Obj.action.value | ||
} | ||
$Obj.PSObject.Properties.Remove('action') | Out-Null | ||
} | ||
|
||
# Convert to booleans | ||
$Obj | Add-Member -NotePropertyName 'remediate' -NotePropertyValue ($AllActionValues -contains 'Remediate') -Force | ||
$Obj | Add-Member -NotePropertyName 'alert' -NotePropertyValue ($AllActionValues -contains 'warn') -Force | ||
$Obj | Add-Member -NotePropertyName 'report' -NotePropertyValue ($AllActionValues -contains 'Report') -Force | ||
|
||
# Flatten "standards" if present | ||
if ($Obj.PSObject.Properties.Name -contains 'standards' -and $Obj.standards) { | ||
foreach ($standardKey in $Obj.standards.PSObject.Properties.Name) { | ||
$NestedStandard = $Obj.standards.$standardKey | ||
if ($NestedStandard) { | ||
foreach ($nsProp in $NestedStandard.PSObject.Properties) { | ||
$Obj | Add-Member -NotePropertyName $nsProp.Name -NotePropertyValue $nsProp.Value -Force | ||
} | ||
} | ||
} | ||
$Obj.PSObject.Properties.Remove('standards') | Out-Null | ||
} | ||
|
||
return $Obj | ||
} |
49 changes: 4 additions & 45 deletions
49
Modules/CIPPCore/Public/Standards/ConvertTo-CippStandardObject.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,18 @@ | ||
function ConvertTo-CippStandardObject { | ||
|
||
param( | ||
[Parameter(Mandatory = $true)] | ||
$StandardObject | ||
) | ||
|
||
# If $StandardObject is an array (like for ConditionalAccessTemplate or IntuneTemplate), | ||
# we need to process each item individually. | ||
# If it's an array of items, process each item | ||
if ($StandardObject -is [System.Collections.IEnumerable] -and -not ($StandardObject -is [string])) { | ||
$ProcessedItems = New-Object System.Collections.ArrayList | ||
foreach ($Item in $StandardObject) { | ||
$ProcessedItems.Add((Convert-SingleStandardObject $Item)) | Out-Null | ||
} | ||
return [System.Collections.ArrayList]$ProcessedItems | ||
return $ProcessedItems | ||
} else { | ||
# Single object scenario | ||
# Single object | ||
return Convert-SingleStandardObject $StandardObject | ||
} | ||
} | ||
|
||
function Convert-SingleStandardObject { | ||
param( | ||
[Parameter(Mandatory = $true)] | ||
$Obj | ||
) | ||
|
||
$Obj = [pscustomobject]$Obj | ||
|
||
$AllActionValues = @() | ||
if ($Obj.PSObject.Properties.Name -contains 'combinedActions') { | ||
$AllActionValues = $Obj.combinedActions | ||
$null = $Obj.PSObject.Properties.Remove('combinedActions') | ||
} elseif ($Obj.PSObject.Properties.Name -contains 'action') { | ||
if ($Obj.action -and $Obj.action.value) { | ||
$AllActionValues = $Obj.action.value | ||
} | ||
$null = $Obj.PSObject.Properties.Remove('action') | ||
} | ||
|
||
# Convert actions to booleans | ||
$Obj | Add-Member -NotePropertyName 'remediate' -NotePropertyValue ($AllActionValues -contains 'Remediate') -Force | ||
$Obj | Add-Member -NotePropertyName 'alert' -NotePropertyValue ($AllActionValues -contains 'warn') -Force | ||
$Obj | Add-Member -NotePropertyName 'report' -NotePropertyValue ($AllActionValues -contains 'Report') -Force | ||
|
||
# Flatten standards if present | ||
if ($Obj.PSObject.Properties.Name -contains 'standards' -and $Obj.standards) { | ||
foreach ($standardKey in $Obj.standards.PSObject.Properties.Name) { | ||
$NestedStandard = $Obj.standards.$standardKey | ||
if ($NestedStandard) { | ||
foreach ($nsProp in $NestedStandard.PSObject.Properties) { | ||
$Obj | Add-Member -NotePropertyName $nsProp.Name -NotePropertyValue $nsProp.Value -Force | ||
} | ||
} | ||
} | ||
$null = $Obj.PSObject.Properties.Remove('standards') | ||
} | ||
|
||
return $Obj | ||
} |
Oops, something went wrong.