-
Notifications
You must be signed in to change notification settings - Fork 265
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrating to Invoke-AzRestMethod (#450)
- Loading branch information
Showing
6 changed files
with
109 additions
and
53 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
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,18 @@ | ||
function Get-AzPolicyAssignmentRestMethod { | ||
[CmdletBinding()] | ||
param ( | ||
[string] $AssignmentID | ||
) | ||
|
||
# Invoke the REST API | ||
$response = Invoke-AzRestMethod -Path "$($AssignmentId)?api-version=2022-06-01" -Method GET | ||
|
||
# Process response | ||
$statusCode = $response.StatusCode | ||
if ($statusCode -lt 200 -or $statusCode -ge 300) { | ||
$content = $response.Content | ||
Write-Error "Get Policy Assignment error for '$policyAssignmentId' $($statusCode) -- $($content)" -ErrorAction Stop | ||
} | ||
|
||
return $response.Content | ConvertFrom-Json -Depth 100 | ||
} |
20 changes: 0 additions & 20 deletions
20
Scripts/Helpers/Get-AzPolicyExemptionsAtScopeRestMethod.ps1
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
function Set-AzRoleAssignmentRestMethod { | ||
[CmdletBinding()] | ||
param ( | ||
$Scope, | ||
$ObjectType, | ||
$ObjectId, | ||
$RoleDefinitionId, | ||
$AssignmentDisplayName, | ||
$RoleDisplayName, | ||
[switch] $IgnoreDuplicateError | ||
) | ||
|
||
# Write log info | ||
Write-Information "Assignment '$AssignmentDisplayName', principalId $ObjectId, role $RoleDisplayName($roleDefinitionId) at $scope" | ||
|
||
# Build the Path | ||
$guid = New-Guid | ||
$path = "$scope/providers/Microsoft.Authorization/roleAssignments/$($guid.ToString())?api-version=2022-04-01" | ||
|
||
# Build the REST API body | ||
$body = @{ | ||
properties = @{ | ||
roleDefinitionId = $RoleDefinitionId | ||
principalId = $ObjectId | ||
principalType = $ObjectType | ||
} | ||
} | ||
|
||
# Invoke the REST API | ||
$bodyJson = ConvertTo-Json $body -Depth 100 -Compress | ||
$response = Invoke-AzRestMethod -Path $path -Method PUT -Payload $bodyJson | ||
|
||
# Process response | ||
$statusCode = $response.StatusCode | ||
if ($statusCode -lt 200 -or $statusCode -ge 300) { | ||
$content = $response.Content | ||
if ($IgnoreDuplicateError -and $statusCode -eq 409) { | ||
$errorBody = $content | ConvertFrom-Json -Depth 100 | ||
Write-Information $errorBody.error.message | ||
} | ||
else { | ||
Write-Error "Role Assignment error $($statusCode) -- $($content)" -ErrorAction Stop | ||
} | ||
} | ||
} |