Skip to content

Commit

Permalink
resync (#548)
Browse files Browse the repository at this point in the history
  • Loading branch information
techlake authored Apr 10, 2024
1 parent 684b99c commit 84e3a4e
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
5 changes: 4 additions & 1 deletion Scripts/Helpers/Get-GlobalSettings.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ function Get-GlobalSettings {
$keepDfcSecurityAssignments = $desired.keepDfcSecurityAssignments
if ($null -eq $keepDfcSecurityAssignments) {
Write-Host -ForegroundColor Red "Error in global-settings.jsonc: pacEnvironment $pacSelector does not contain required desiredState.keepDfcSecurityAssignments field."
$hasErrors = $true
}
else {
if ($keepDfcSecurityAssignments -is [bool]) {
Expand All @@ -248,7 +249,7 @@ function Get-GlobalSettings {
}
}
$excludedScopes = $desired.excludedScopes
if ($null -ne $excluded) {
if ($null -ne $excludedScopes) {
if ($excludedScopes -isnot [array]) {
Write-Host -ForegroundColor Red "Error in global-settings.jsonc: pacEnvironment $pacSelector field desiredState.excludedScopes must be an array of strings."
$hasErrors = $true
Expand Down Expand Up @@ -307,10 +308,12 @@ function Get-GlobalSettings {
$deleteExpired = $desired.deleteExpiredExemptions
if ($null -ne $deleteExpired) {
Write-Host -ForegroundColor Red "Error in global-settings.jsonc: pacEnvironment $pacSelector field desiredState.deleteExpiredExemptions is deprecated. Remove it!"
$hasErrors = $true
}
$deleteOrphaned = $desired.deleteOrphanedExemptions
if ($null -ne $deleteOrphaned) {
Write-Host -ForegroundColor Red "Error in global-settings.jsonc: pacEnvironment $pacSelector field desiredState.deleteOrphanedExemptions is deprecated. Remove it!"
$hasErrors = $true
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function Set-AzPolicyExemptionRestMethod {
Write-Warning "Ignoring scope locked error: $($statusCode) -- $($content)"
}
else {
Write-Error "Policy Exemption error $($statusCode) -- $($content)"
Write-Error "Policy Exemption error $($statusCode) -- $($content)" -ErrorAction Continue
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,20 @@ function Set-AzRoleAssignmentRestMethod {

$properties = $RoleAssignment.properties
$path = $null
$scope = $RoleAssignment.scope
if ($null -ne $RoleAssignment.id) {
# update existing role assignment
$path = "$($RoleAssignment.id)?api-version=$ApiVersion"
$scope = $RoleAssignment.scope
}
else {
# create new role assignment
$guid = New-Guid
$scope = $RoleAssignment.scope
$path = "$scope/providers/Microsoft.Authorization/roleAssignments/$($guid.ToString())?api-version=$ApiVersion"
}
$body = @{
properties = $RoleAssignment.properties
}
Write-Information "Assignment '$($RoleAssignment.assignmentDisplayName)', principalId $($properties.principalId), role '$($RoleAssignment.roleDisplayName)' at $($RoleAssignment.scope)"
Write-Information "Assignment '$($RoleAssignment.assignmentDisplayName)', principalId $($properties.principalId), role '$($RoleAssignment.roleDisplayName)' at $($scope)"

# Invoke the REST API
$bodyJson = ConvertTo-Json $body -Depth 100 -Compress
Expand All @@ -36,7 +35,7 @@ function Set-AzRoleAssignmentRestMethod {
Write-Information $errorBody.error.message
}
else {
Write-Error "Role Assignment error $($statusCode) -- $($content)" -ErrorAction Stop
Write-Error "Role Assignment error $($statusCode) -- $($content)" -ErrorAction Continue
}
}
}
8 changes: 3 additions & 5 deletions Scripts/Helpers/Split-ArrayIntoChunks.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ function Split-ArrayIntoChunks {
# split array into chunks
$count = $Array.Count
if ($count -le $MinChunkingSize) {
[array] $chunks = [array]::CreateInstance([array], 1)
$chunks[0] = $Array
$chunks = @( $Array )
return , $chunks
}
else {
Expand All @@ -23,13 +22,12 @@ function Split-ArrayIntoChunks {
$NumberOfChunks = [math]::Ceiling($count / $MinChunkingSize)
$chunkingSize = [math]::Ceiling($count / $NumberOfChunks)
}
[array] $chunks = [array]::CreateInstance([array], $NumberOfChunks)
if ($NumberOfChunks -eq 1) {
Write-Error "Coding error: NumberOfChunks is 1" -ErrorAction Continue
$chunks[0] = $Array
$chunks = @( $Array )
return , $chunks
}
else {
[array] $chunks = [array]::CreateInstance([array], $NumberOfChunks)
for ($i = 0; $i -lt $NumberOfChunks; $i++) {
$start = $i * $chunkingSize
$end = $start + $chunkingSize - 1
Expand Down
8 changes: 3 additions & 5 deletions Scripts/Helpers/Split-HashtableIntoChunks.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ function Split-HashtableIntoChunks {
# split definition array into chunks
$count = $Table.Count
if ($count -le $MinChunkingSize) {
[array] $chunks = [array]::CreateInstance([array], 1)
$chunks[0] = $Table
$chunks = @( $Table )
return , $chunks
}
else {
Expand All @@ -23,13 +22,12 @@ function Split-HashtableIntoChunks {
$NumberOfChunks = [math]::Ceiling($count / $MinChunkingSize)
$chunkingSize = [math]::Ceiling($count / $NumberOfChunks)
}
[array] $chunks = [array]::CreateInstance([array], $NumberOfChunks)
if ($NumberOfChunks -eq 1) {
Write-Error "Coding error: NumberOfChunks is 1" -ErrorAction Continue
$chunks[0] = $Table
$chunks = @( $Table )
return , $chunks
}
else {
[array] $chunks = [array]::CreateInstance([array], $NumberOfChunks)
$chunk = @{}
$itemCount = 0
$i = 0
Expand Down
4 changes: 3 additions & 1 deletion Scripts/Operations/New-AzPolicyReaderRole.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ $perms = @(
"Microsoft.Authorization/roleAssignments/read",
"Microsoft.PolicyInsights/*",
"Microsoft.Management/register/action",
"Microsoft.Management/managementGroups/read"
"Microsoft.Management/managementGroups/read",
"Microsoft.Resources/subscriptions/read",
"Microsoft.Resources/subscriptions/resourceGroups/read"
)

$role.Actions = $perms
Expand Down

0 comments on commit 84e3a4e

Please sign in to comment.