Skip to content

Commit 656a440

Browse files
authored
Apply changes to support -Playback mode (#24555)
* Update to autorest 4.x Update to Azure Policy 2023-04-01 Move to non-versioned interface types Complete full test suite for existing cmdlets Few bug fixes Add completer for Location parameter Fix record/playback, remove -LiveOnly tags Make test names repeatable to work with record/playback Implement resource group functions that became inaccessible Fix test failures due to default parameter injection * Clean up some transforms in README Remove unsupported (for now) parameters Streamline common test code Move common test code to utils.ps1 Add serialization of test variables to env.json * Remove extra parameters from Get-AzPolicyAssignment Rerecord the tests * Fix $testFilesFolder calculation to work on macOS/linux. * Hide generated parameter sets for New-* Correct definitions, validation, and tests for New-AzPolicyAssignment parameters Re-record all tests * Replace Get-AzContext with Utils\Get-SubscriptionIdTestSafe Move to autorest 4.0.690 Update managed identity properties to match generation changes Remove several parameter transforms no longer needed Rerecord all tests 91 tests still failing on -Playback with the same signature * Remove location completer from exports/docs/examples/help * Improve location completer tests * Remove transforms for Scope and Id parameters no longer needed Update cmdlets to use Scope and Id directly Rerecord all tests All tests pass in -Record mode Failures in -Playback mode unchanged * Change location completer to lazy load (vs. module load) Preserve "extra" input parameters in Update-* calls to Get-* in order to support -Playback test mode Tag test files that don't support -Playback mode as LiveOnly Rerecord all recording files
1 parent 5ae5ed0 commit 656a440

File tree

103 files changed

+19948
-21699
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+19948
-21699
lines changed

src/Resources/Policy.Autorest/custom/Helpers.ps1

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -514,20 +514,66 @@ function LocationCompleter(
514514
$fakeBoundParameter
515515
)
516516
{
517-
$currentLocations | Where-Object { $_ -like "$wordToComplete*" }
517+
if ($global:currentLocations.Count -le 0) {
518+
$response = Invoke-AzRestMethod -Uri "https://management.azure.com/subscriptions/$subscriptionId/locations?api-version=2022-12-01" -Method GET
519+
$global:currentLocations = ($response.Content | ConvertFrom-Json -Depth 100).value | Sort-Object -Property name | Select-Object -ExpandProperty name
520+
}
521+
522+
# If you see the following error, it means your context access has expired
523+
# The given key 'AzureAttestationServiceEndpointSuffix' was not present in the dictionary.
524+
$global:currentLocations | Where-Object { $_ -like "$wordToComplete*" }
518525
}
519526

520527
function Get-SubscriptionId {
521528
(Utils\Get-SubscriptionIdTestSafe)
522529
}
523530

531+
function Get-ExtraParameters
532+
(
533+
$DefaultProfile,
534+
$Break,
535+
$HttpPipelineAppend,
536+
$HttpPipelinePrepend,
537+
$Proxy,
538+
$ProxyCredential,
539+
$ProxyUseDefaultCredentials
540+
) {
541+
$parms = @{}
542+
if ($PSBoundParameters['DefaultProfile']) {
543+
$parms['DefaultProfile'] = $PSBoundParameters['DefaultProfile']
544+
}
545+
546+
if ($PSBoundParameters['Break']) {
547+
$parms['Break'] = $PSBoundParameters['Break']
548+
}
549+
550+
if ($PSBoundParameters['HttpPipelineAppend']) {
551+
$parms['HttpPipelineAppend'] = $PSBoundParameters['HttpPipelineAppend']
552+
}
553+
554+
if ($PSBoundParameters['HttpPipelinePrepend']) {
555+
$parms['HttpPipelinePrepend'] = $PSBoundParameters['HttpPipelinePrepend']
556+
}
557+
558+
if ($PSBoundParameters['Proxy']) {
559+
$parms['Proxy'] = $PSBoundParameters['Proxy']
560+
}
561+
562+
if ($PSBoundParameters['ProxyCredential']) {
563+
$parms['ProxyCredential'] = $PSBoundParameters['ProxyCredential']
564+
}
565+
566+
if ($PSBoundParameters['ProxyUseDefaultCredentials']) {
567+
$parms['ProxyUseDefaultCredentials'] = $PSBoundParameters['ProxyUseDefaultCredentials']
568+
}
569+
570+
return $parms
571+
}
572+
524573
# register the location completer for New-AzPolicyAssignment
525574
Register-ArgumentCompleter -CommandName New-AzPolicyAssignment -ParameterName Location -ScriptBlock ${function:LocationCompleter}
526575

527576
# cache Azure locations to be used by the location completer (Get-AzLocation is not available in this context, need to use REST)
528-
$subscriptionId = (Get-SubscriptionId)
577+
$global:currentLocations = @()
529578

530-
$response = Invoke-AzRestMethod -Uri "https://management.azure.com/subscriptions/$subscriptionId/locations?api-version=2022-12-01" -Method GET
531-
$currentLocations = ($response.Content | ConvertFrom-Json -Depth 100).value | Sort-Object -Property name | Select-Object -ExpandProperty name
532-
# If you see the following error, it means your context access has expired
533-
# The given key 'AzureAttestationServiceEndpointSuffix' was not present in the dictionary.
579+
$subscriptionId = (Get-SubscriptionId)

src/Resources/Policy.Autorest/custom/Update-AzPolicyAssignment.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,9 @@ process {
244244

245245
# construct id for assignment to update
246246
$resolved = ResolvePolicyAssignment $Name $Scope $thisId
247-
$getParameters = @{ Id = $resolved.ResourceId }
247+
248+
$getParameters = Get-ExtraParameters @PSBoundParameters
249+
$getParameters['Id'] = $resolved.ResourceId
248250

249251
if ($writeln) {
250252
Write-Host -ForegroundColor Blue -> Get-AzPolicyAssignment'(' $getParameters ')'

src/Resources/Policy.Autorest/custom/Update-AzPolicyDefinition.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,9 @@ process {
188188

189189
# construct id for definition to update
190190
$resolved = ResolvePolicyDefinition $Name $SubscriptionId $ManagementGroupName $thisId
191-
$getParameters = @{ Id = $resolved.ResourceId }
191+
192+
$getParameters = Get-ExtraParameters @PSBoundParameters
193+
$getParameters['Id'] = $resolved.ResourceId
192194

193195
if ($writeln) {
194196
Write-Host -ForegroundColor Blue -> Get-AzPolicyDefinition'(' $getParameters ')'

src/Resources/Policy.Autorest/custom/Update-AzPolicyExemption.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,9 @@ process {
187187

188188
# construct id for exemption to update
189189
$resolved = ResolvePolicyExemption $Name $Scope $thisId
190-
$getParameters = @{ Id = $resolved.ResourceId }
190+
191+
$getParameters = Get-ExtraParameters @PSBoundParameters
192+
$getParameters['Id'] = $resolved.ResourceId
191193

192194
if ($writeln) {
193195
Write-Host -ForegroundColor Blue -> Get-AzPolicyExemption'(' $getParameters ')'

src/Resources/Policy.Autorest/custom/Update-AzPolicySetDefinition.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,9 @@ process {
189189

190190
# construct id for definition to update
191191
$resolved = ResolvePolicySetDefinition $Name $SubscriptionId $ManagementGroupName $thisId
192-
$getParameters = @{ Id = $resolved.ResourceId }
192+
193+
$getParameters = Get-ExtraParameters @PSBoundParameters
194+
$getParameters['Id'] = $resolved.ResourceId
193195

194196
if ($writeln) {
195197
Write-Host -ForegroundColor Blue -> Get-AzPolicySetDefinition'(' $getParameters ')'

src/Resources/Policy.Autorest/test/Backcompat/Backcompat-GetBuiltinsByName.Recording.json

Lines changed: 2803 additions & 2803 deletions
Large diffs are not rendered by default.

src/Resources/Policy.Autorest/test/Backcompat/Backcompat-GetCmdletFilterParameter.Recording.json

Lines changed: 74 additions & 74 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)