From 7533e67c4f86c5bd007912b78183da69c5a0c4fc Mon Sep 17 00:00:00 2001 From: Yang An Date: Mon, 28 Sep 2026 14:21:55 +1000 Subject: [PATCH 01/12] Fix Change Safety forwarding in read-modify-write cmdlets Keep target command parameters separate from metadata-filtered read parameters so dynamic write parameters are not passed to preliminary GET operations. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- ...ve-AzEventHubPrivateEndpointConnection.ps1 | 27 ++--- ...ny-AzEventHubPrivateEndpointConnection.ps1 | 29 ++--- .../custom/Get-AzEventHubReadParameters.ps1 | 30 +++++ .../custom/Set-AzEventHub.ps1 | 65 ++++++----- .../custom/Set-AzEventHubApplicationGroup.ps1 | 36 +++--- .../Set-AzEventHubAuthorizationRule.ps1 | 53 +++++---- .../custom/Set-AzEventHubCluster.ps1 | 29 ++--- .../custom/Set-AzEventHubConsumerGroup.ps1 | 33 +++--- ...-AzEventHubGeoDRConfigurationBreakPair.ps1 | 31 ++--- ...t-AzEventHubGeoDRConfigurationFailOver.ps1 | 31 ++--- .../custom/Set-AzEventHubNamespace.ps1 | 59 +++++----- .../custom/Set-AzEventHubNetworkRuleSet.ps1 | 37 +++--- .../EventHub.Autorest/generate-info.json | 2 +- .../test/ReadParameterForwarding.Tests.ps1 | 109 ++++++++++++++++++ src/EventHub/EventHub/ChangeLog.md | 1 + src/Network/Network/ChangeLog.md | 2 +- ...NetworkSecurityPerimeterReadParameters.ps1 | 30 +++++ ...e-AzNetworkSecurityPerimeterAccessRule.ps1 | 26 ++--- ...-AzNetworkSecurityPerimeterAssociation.ps1 | 27 +++-- .../Update-AzNetworkSecurityPerimeterLink.ps1 | 27 +++-- ...kSecurityPerimeterLoggingConfiguration.ps1 | 26 ++--- .../generate-info.json | 4 +- .../test/ReadParameterForwarding.Tests.ps1 | 94 +++++++++++++++ ...-AzServiceBusPrivateEndpointConnection.ps1 | 27 ++--- ...-AzServiceBusPrivateEndpointConnection.ps1 | 27 ++--- .../custom/Get-AzServiceBusReadParameters.ps1 | 30 +++++ .../Set-AzServiceBusAuthorizationRule.ps1 | 65 ++++++----- ...zServiceBusGeoDRConfigurationBreakPair.ps1 | 31 ++--- ...AzServiceBusGeoDRConfigurationFailOver.ps1 | 31 ++--- .../custom/Set-AzServiceBusNamespace.ps1 | 65 ++++++----- .../custom/Set-AzServiceBusNetworkRuleSet.ps1 | 37 +++--- .../custom/Set-AzServiceBusQueue.ps1 | 55 ++++----- .../custom/Set-AzServiceBusRule.ps1 | 57 ++++----- .../custom/Set-AzServiceBusSubscription.ps1 | 53 ++++----- .../custom/Set-AzServiceBusTopic.ps1 | 49 ++++---- .../ServiceBus.Autorest/generate-info.json | 2 +- .../test/ReadParameterForwarding.Tests.ps1 | 109 ++++++++++++++++++ src/ServiceBus/ServiceBus/ChangeLog.md | 1 + 38 files changed, 940 insertions(+), 507 deletions(-) create mode 100644 src/EventHub/EventHub.Autorest/custom/Get-AzEventHubReadParameters.ps1 create mode 100644 src/EventHub/EventHub.Autorest/test/ReadParameterForwarding.Tests.ps1 create mode 100644 src/Network/NetworkSecurityPerimeter.Autorest/custom/Get-AzNetworkSecurityPerimeterReadParameters.ps1 create mode 100644 src/Network/NetworkSecurityPerimeter.Autorest/test/ReadParameterForwarding.Tests.ps1 create mode 100644 src/ServiceBus/ServiceBus.Autorest/custom/Get-AzServiceBusReadParameters.ps1 create mode 100644 src/ServiceBus/ServiceBus.Autorest/test/ReadParameterForwarding.Tests.ps1 diff --git a/src/EventHub/EventHub.Autorest/custom/Approve-AzEventHubPrivateEndpointConnection.ps1 b/src/EventHub/EventHub.Autorest/custom/Approve-AzEventHubPrivateEndpointConnection.ps1 index 23aceb2100aa..d6d8afa302d4 100644 --- a/src/EventHub/EventHub.Autorest/custom/Approve-AzEventHubPrivateEndpointConnection.ps1 +++ b/src/EventHub/EventHub.Autorest/custom/Approve-AzEventHubPrivateEndpointConnection.ps1 @@ -134,13 +134,14 @@ function Approve-AzEventHubPrivateEndpointConnection{ } process{ try{ - $hasDescription = $PSBoundParameters.Remove('Description') - $hasAsJob = $PSBoundParameters.Remove('AsJob') - $null = $PSBoundParameters.Remove('WhatIf') - $null = $PSBoundParameters.Remove('Confirm') - - $connection = Get-AzEventHubPrivateEndpointConnection @PSBoundParameters - + $targetParameters = @{} + $PSBoundParameters + $hasDescription = $targetParameters.Remove('Description') + $hasAsJob = $targetParameters.Remove('AsJob') + $null = $targetParameters.Remove('WhatIf') + $null = $targetParameters.Remove('Confirm') + + $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHubPrivateEndpointConnection' -BoundParameters $targetParameters + $connection = Get-AzEventHubPrivateEndpointConnection @readParameters $connection.ConnectionState = "Approved" if($hasDescription){ @@ -151,14 +152,14 @@ function Approve-AzEventHubPrivateEndpointConnection{ } # 2. PUT - $null = $PSBoundParameters.Remove('InputObject') - $null = $PSBoundParameters.Remove('ResourceGroupName') - $null = $PSBoundParameters.Remove('NamespaceName') - $null = $PSBoundParameters.Remove('Name') - $null = $PSBoundParameters.Remove('SubscriptionId') + $null = $targetParameters.Remove('InputObject') + $null = $targetParameters.Remove('ResourceGroupName') + $null = $targetParameters.Remove('NamespaceName') + $null = $targetParameters.Remove('Name') + $null = $targetParameters.Remove('SubscriptionId') if ($PSCmdlet.ShouldProcess("Approve EventHub Namespace PrivateEndpoint Connection $($Name)", "Create or update")) { - Az.EventHub.private\New-AzEventHubPrivateEndpointConnection_CreateViaIdentity -InputObject $connection -Parameter $connection @PSBoundParameters + Az.EventHub.private\New-AzEventHubPrivateEndpointConnection_CreateViaIdentity -InputObject $connection -Parameter $connection @targetParameters } } catch{ diff --git a/src/EventHub/EventHub.Autorest/custom/Deny-AzEventHubPrivateEndpointConnection.ps1 b/src/EventHub/EventHub.Autorest/custom/Deny-AzEventHubPrivateEndpointConnection.ps1 index b75b2a28e820..1c7f47e6a6b6 100644 --- a/src/EventHub/EventHub.Autorest/custom/Deny-AzEventHubPrivateEndpointConnection.ps1 +++ b/src/EventHub/EventHub.Autorest/custom/Deny-AzEventHubPrivateEndpointConnection.ps1 @@ -134,13 +134,14 @@ function Deny-AzEventHubPrivateEndpointConnection{ } process{ try{ - $hasDescription = $PSBoundParameters.Remove('Description') - $hasAsJob = $PSBoundParameters.Remove('AsJob') - $null = $PSBoundParameters.Remove('WhatIf') - $null = $PSBoundParameters.Remove('Confirm') - - $connection = Get-AzEventHubPrivateEndpointConnection @PSBoundParameters - + $targetParameters = @{} + $PSBoundParameters + $hasDescription = $targetParameters.Remove('Description') + $hasAsJob = $targetParameters.Remove('AsJob') + $null = $targetParameters.Remove('WhatIf') + $null = $targetParameters.Remove('Confirm') + + $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHubPrivateEndpointConnection' -BoundParameters $targetParameters + $connection = Get-AzEventHubPrivateEndpointConnection @readParameters $connection.ConnectionState = "Rejected" if($hasDescription){ @@ -151,15 +152,15 @@ function Deny-AzEventHubPrivateEndpointConnection{ } # 2. PUT - $null = $PSBoundParameters.Remove('InputObject') - $null = $PSBoundParameters.Remove('ResourceGroupName') - $null = $PSBoundParameters.Remove('NamespaceName') - $null = $PSBoundParameters.Remove('EventHubName') - $null = $PSBoundParameters.Remove('Name') - $null = $PSBoundParameters.Remove('SubscriptionId') + $null = $targetParameters.Remove('InputObject') + $null = $targetParameters.Remove('ResourceGroupName') + $null = $targetParameters.Remove('NamespaceName') + $null = $targetParameters.Remove('EventHubName') + $null = $targetParameters.Remove('Name') + $null = $targetParameters.Remove('SubscriptionId') if ($PSCmdlet.ShouldProcess("Approve EventHub Namespace PrivateEndpoint Connection $($Name)", "Create or update")) { - Az.EventHub.private\New-AzEventHubPrivateEndpointConnection_CreateViaIdentity -InputObject $connection -Parameter $connection @PSBoundParameters + Az.EventHub.private\New-AzEventHubPrivateEndpointConnection_CreateViaIdentity -InputObject $connection -Parameter $connection @targetParameters } } catch{ diff --git a/src/EventHub/EventHub.Autorest/custom/Get-AzEventHubReadParameters.ps1 b/src/EventHub/EventHub.Autorest/custom/Get-AzEventHubReadParameters.ps1 new file mode 100644 index 000000000000..9871b7a8b785 --- /dev/null +++ b/src/EventHub/EventHub.Autorest/custom/Get-AzEventHubReadParameters.ps1 @@ -0,0 +1,30 @@ +function Get-AzEventHubReadParameters { + [Microsoft.Azure.PowerShell.Cmdlets.EventHub.DoNotExportAttribute()] + [CmdletBinding()] + param( + [Parameter(Mandatory)] + [System.String] + ${CommandName}, + + [Parameter(Mandatory)] + [System.Collections.IDictionary] + ${BoundParameters} + ) + + $command = @(Get-Command -Name $CommandName -ErrorAction Stop)[0] + while ($command.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { + $command = Get-Command -Name $command.ResolvedCommandName -ErrorAction Stop + } + + $parameterNames = @($command.Parameters.Keys) + $parameterNames += @($command.Parameters.Values | ForEach-Object { $_.Aliases }) + + $readParameters = @{} + foreach ($parameter in $BoundParameters.GetEnumerator()) { + if ($parameter.Key -in $parameterNames) { + $readParameters[$parameter.Key] = $parameter.Value + } + } + + return $readParameters +} diff --git a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHub.ps1 b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHub.ps1 index d6d80d465122..cc31843c25cf 100644 --- a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHub.ps1 +++ b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHub.ps1 @@ -146,7 +146,7 @@ function Set-AzEventHub{ [System.String] # Resource id of the storage account to be used to create the blobs ${StorageAccountResourceId}, - + [Parameter(HelpMessage = "Blob naming convention for archive, e.g. {Namespace}/{EventHub}/{PartitionId}/{Year}/{Month}/{Day}/{Hour}/{Minute}/{Second}. Here all the parameters (Namespace,EventHub .. etc) are mandatory irrespective of order")] [Microsoft.Azure.PowerShell.Cmdlets.EventHub.Category('Body')] [System.String] @@ -235,36 +235,37 @@ function Set-AzEventHub{ } process{ try{ - $hasCaptureEnabled = $PSBoundParameters.Remove('CaptureEnabled') - $hasEncoding = $PSBoundParameters.Remove('Encoding') - $hasIntervalInSeconds = $PSBoundParameters.Remove('IntervalInSeconds') - $hasSizeLimitInBytes = $PSBoundParameters.Remove('SizeLimitInBytes') - $hasSkipEmptyArchive = $PSBoundParameters.Remove('SkipEmptyArchive') - $hasUserAssignedIdentityId = $PSBoundParameters.Remove('UserAssignedIdentityId') - $hasIdentityType = $PSBoundParameters.Remove('IdentityType') - $hasRetentionTimeInHour = $PSBoundParameters.Remove('RetentionTimeInHour') - $hasTombstoneRetentionTimeInHour = $PSBoundParameters.Remove('TombstoneRetentionTimeInHour') - $hasStatus = $PSBoundParameters.Remove('Status') - $hasDestinationName = $PSBoundParameters.Remove('DestinationName') - $hasStorageAccountResourceId = $PSBoundParameters.Remove('StorageAccountResourceId') - $hasArchiveNameFormat = $PSBoundParameters.Remove('ArchiveNameFormat') - $hasBlobContainer = $PSBoundParameters.Remove('BlobContainer') - $hasAsJob = $PSBoundParameters.Remove('AsJob') - $hasPartitionCount = $PSBoundParameters.Remove('PartitionCount') - $hasUserMetadata = $PSBoundParameters.Remove('UserMetadata') - $hasMinCompactionLagInMin = $PSBoundParameters.Remove('MinCompactionLagInMin') - $hasTimestampType = $PSBoundParameters.Remove('TimestampType') - $null = $PSBoundParameters.Remove('WhatIf') - $null = $PSBoundParameters.Remove('Confirm') - - $eventHub = Get-AzEventHub @PSBoundParameters - + $targetParameters = @{} + $PSBoundParameters + $hasCaptureEnabled = $targetParameters.Remove('CaptureEnabled') + $hasEncoding = $targetParameters.Remove('Encoding') + $hasIntervalInSeconds = $targetParameters.Remove('IntervalInSeconds') + $hasSizeLimitInBytes = $targetParameters.Remove('SizeLimitInBytes') + $hasSkipEmptyArchive = $targetParameters.Remove('SkipEmptyArchive') + $hasUserAssignedIdentityId = $targetParameters.Remove('UserAssignedIdentityId') + $hasIdentityType = $targetParameters.Remove('IdentityType') + $hasRetentionTimeInHour = $targetParameters.Remove('RetentionTimeInHour') + $hasTombstoneRetentionTimeInHour = $targetParameters.Remove('TombstoneRetentionTimeInHour') + $hasStatus = $targetParameters.Remove('Status') + $hasDestinationName = $targetParameters.Remove('DestinationName') + $hasStorageAccountResourceId = $targetParameters.Remove('StorageAccountResourceId') + $hasArchiveNameFormat = $targetParameters.Remove('ArchiveNameFormat') + $hasBlobContainer = $targetParameters.Remove('BlobContainer') + $hasAsJob = $targetParameters.Remove('AsJob') + $hasPartitionCount = $targetParameters.Remove('PartitionCount') + $hasUserMetadata = $targetParameters.Remove('UserMetadata') + $hasMinCompactionLagInMin = $targetParameters.Remove('MinCompactionLagInMin') + $hasTimestampType = $targetParameters.Remove('TimestampType') + $null = $targetParameters.Remove('WhatIf') + $null = $targetParameters.Remove('Confirm') + + $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHub' -BoundParameters $targetParameters + $eventHub = Get-AzEventHub @readParameters # 2. PUT - $null = $PSBoundParameters.Remove('InputObject') - $null = $PSBoundParameters.Remove('ResourceGroupName') - $null = $PSBoundParameters.Remove('NamespaceName') - $null = $PSBoundParameters.Remove('Name') - $null = $PSBoundParameters.Remove('SubscriptionId') + $null = $targetParameters.Remove('InputObject') + $null = $targetParameters.Remove('ResourceGroupName') + $null = $targetParameters.Remove('NamespaceName') + $null = $targetParameters.Remove('Name') + $null = $targetParameters.Remove('SubscriptionId') $hasProperty = $false @@ -361,11 +362,11 @@ function Set-AzEventHub{ } if ($hasAsJob) { - $PSBoundParameters.Add('AsJob', $true) + $targetParameters.Add('AsJob', $true) } if ($PSCmdlet.ShouldProcess("EventHub Entity $($eventHub.Name)", "Create or update")) { - Az.EventHub.private\New-AzEventHub_CreateViaIdentity -InputObject $eventHub -Parameter $eventHub @PSBoundParameters + Az.EventHub.private\New-AzEventHub_CreateViaIdentity -InputObject $eventHub -Parameter $eventHub @targetParameters } } catch{ diff --git a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubApplicationGroup.ps1 b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubApplicationGroup.ps1 index 05f40fd6ceb8..de959fec3051 100644 --- a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubApplicationGroup.ps1 +++ b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubApplicationGroup.ps1 @@ -73,7 +73,7 @@ function Set-AzEventHubApplicationGroup{ [Microsoft.Azure.PowerShell.Cmdlets.EventHub.Models.IApplicationGroupPolicy[]] # List of group policies that define the behavior of application group. The policies can support resource governance scenarios such as limiting ingress or egress traffic. ${Policy}, - + [Parameter(HelpMessage = "The credentials, account, tenant, and subscription used for communication with Azure.")] [Alias('AzureRMContext', 'AzureCredential')] [ValidateNotNull()] @@ -146,22 +146,22 @@ function Set-AzEventHubApplicationGroup{ } process{ try{ - - $hasIsEnabled = $PSBoundParameters.Remove('IsEnabled') - $hasPolicy = $PSBoundParameters.Remove('Policy') - $hasClientAppGroupIdentifier = $PSBoundParameters.Remove('ClientAppGroupIdentifier') - $hasAsJob = $PSBoundParameters.Remove('AsJob') - $null = $PSBoundParameters.Remove('WhatIf') - $null = $PSBoundParameters.Remove('Confirm') - - $appGroup = Get-AzEventHubApplicationGroup @PSBoundParameters - + $targetParameters = @{} + $PSBoundParameters + $hasIsEnabled = $targetParameters.Remove('IsEnabled') + $hasPolicy = $targetParameters.Remove('Policy') + $hasClientAppGroupIdentifier = $targetParameters.Remove('ClientAppGroupIdentifier') + $hasAsJob = $targetParameters.Remove('AsJob') + $null = $targetParameters.Remove('WhatIf') + $null = $targetParameters.Remove('Confirm') + + $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHubApplicationGroup' -BoundParameters $targetParameters + $appGroup = Get-AzEventHubApplicationGroup @readParameters # 2. PUT - $null = $PSBoundParameters.Remove('InputObject') - $null = $PSBoundParameters.Remove('ResourceGroupName') - $null = $PSBoundParameters.Remove('NamespaceName') - $null = $PSBoundParameters.Remove('Name') - $null = $PSBoundParameters.Remove('SubscriptionId') + $null = $targetParameters.Remove('InputObject') + $null = $targetParameters.Remove('ResourceGroupName') + $null = $targetParameters.Remove('NamespaceName') + $null = $targetParameters.Remove('Name') + $null = $targetParameters.Remove('SubscriptionId') $hasProperty = $false @@ -183,12 +183,12 @@ function Set-AzEventHubApplicationGroup{ } if ($hasAsJob) { - $PSBoundParameters.Add('AsJob', $true) + $targetParameters.Add('AsJob', $true) } if ($PSCmdlet.ShouldProcess("EventHub Application Group $($appGroup.Name)", "Create or update")) { - Az.EventHub.private\New-AzEventHubApplicationGroup_CreateViaIdentity -InputObject $appGroup -Parameter $appGroup @PSBoundParameters + Az.EventHub.private\New-AzEventHubApplicationGroup_CreateViaIdentity -InputObject $appGroup -Parameter $appGroup @targetParameters } } catch{ diff --git a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubAuthorizationRule.ps1 b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubAuthorizationRule.ps1 index 93347f0a95f7..f92c0698cedb 100644 --- a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubAuthorizationRule.ps1 +++ b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubAuthorizationRule.ps1 @@ -72,7 +72,7 @@ function Set-AzEventHubAuthorizationRule{ [System.String[]] # The rights associated with the rule. ${Rights}, - + [Parameter(HelpMessage = "The credentials, account, tenant, and subscription used for communication with Azure.")] [Alias('AzureRMContext', 'AzureCredential')] [ValidateNotNull()] @@ -145,17 +145,20 @@ function Set-AzEventHubAuthorizationRule{ } process{ try{ - $hasRights = $PSBoundParameters.Remove('Rights') - $hasAsJob = $PSBoundParameters.Remove('AsJob') - $null = $PSBoundParameters.Remove('WhatIf') - $null = $PSBoundParameters.Remove('Confirm') + $targetParameters = @{} + $PSBoundParameters + $hasRights = $targetParameters.Remove('Rights') + $hasAsJob = $targetParameters.Remove('AsJob') + $null = $targetParameters.Remove('WhatIf') + $null = $targetParameters.Remove('Confirm') if ($PSCmdlet.ParameterSetName -eq 'SetExpandedNamespace'){ - $authRule = Az.EventHub.private\Get-AzEventHubNamespaceAuthorizationRule_Get @PSBoundParameters + $readParameters = Get-AzEventHubReadParameters -CommandName 'Az.EventHub.private\Get-AzEventHubNamespaceAuthorizationRule_Get' -BoundParameters $targetParameters + $authRule = Az.EventHub.private\Get-AzEventHubNamespaceAuthorizationRule_Get @readParameters } - + elseif($PSCmdlet.ParameterSetName -eq 'SetExpandedEntity'){ - $authRule = Az.EventHub.private\Get-AzEventHubAuthorizationRule_Get @PSBoundParameters + $readParameters = Get-AzEventHubReadParameters -CommandName 'Az.EventHub.private\Get-AzEventHubAuthorizationRule_Get' -BoundParameters $targetParameters + $authRule = Az.EventHub.private\Get-AzEventHubAuthorizationRule_Get @readParameters } elseif ($PSCmdlet.ParameterSetName -eq 'SetViaIdentityExpanded'){ @@ -166,54 +169,56 @@ function Set-AzEventHubAuthorizationRule{ $ResourceHashTable = ParseResourceId -ResourceId $InputObject } if ($ResourceHashTable['EventHubName'] -ne $null){ - $authRule = Az.EventHub.private\Get-AzEventHubAuthorizationRule_GetViaIdentity @PSBoundParameters + $readParameters = Get-AzEventHubReadParameters -CommandName 'Az.EventHub.private\Get-AzEventHubAuthorizationRule_GetViaIdentity' -BoundParameters $targetParameters + $authRule = Az.EventHub.private\Get-AzEventHubAuthorizationRule_GetViaIdentity @readParameters } elseif ($ResourceHashTable['NamespaceName'] -ne $null){ - $authRule = Az.EventHub.private\Get-AzEventHubNamespaceAuthorizationRule_GetViaIdentity @PSBoundParameters + $readParameters = Get-AzEventHubReadParameters -CommandName 'Az.EventHub.private\Get-AzEventHubNamespaceAuthorizationRule_GetViaIdentity' -BoundParameters $targetParameters + $authRule = Az.EventHub.private\Get-AzEventHubNamespaceAuthorizationRule_GetViaIdentity @readParameters } else{ throw 'Invalid -InputObject. Please Check ResourceId' } } - + # 2. PUT - $null = $PSBoundParameters.Remove('InputObject') - $null = $PSBoundParameters.Remove('ResourceGroupName') - $null = $PSBoundParameters.Remove('NamespaceName') - $null = $PSBoundParameters.Remove('EventHubName') - $null = $PSBoundParameters.Remove('Name') - $null = $PSBoundParameters.Remove('SubscriptionId') + $null = $targetParameters.Remove('InputObject') + $null = $targetParameters.Remove('ResourceGroupName') + $null = $targetParameters.Remove('NamespaceName') + $null = $targetParameters.Remove('EventHubName') + $null = $targetParameters.Remove('Name') + $null = $targetParameters.Remove('SubscriptionId') if ($hasRights) { $authRule.Rights = $Rights } if ($hasAsJob) { - $PSBoundParameters.Add('AsJob', $true) + $targetParameters.Add('AsJob', $true) } if ($PSCmdlet.ParameterSetName -eq 'SetExpandedNamespace'){ if ($PSCmdlet.ShouldProcess("EventHub Namespace Authorization Rule $($authRule.Name)", "Create or update")) { - Az.EventHub.private\New-AzEventHubNamespaceAuthorizationRule_CreateViaIdentity -InputObject $authRule -Parameter $authRule @PSBoundParameters + Az.EventHub.private\New-AzEventHubNamespaceAuthorizationRule_CreateViaIdentity -InputObject $authRule -Parameter $authRule @targetParameters } } elseif ($PSCmdlet.ParameterSetName -eq 'SetExpandedEntity'){ if ($PSCmdlet.ShouldProcess("EventHub Entity Authorization Rule $($authRule.Name)", "Create or update")) { - Az.EventHub.private\New-AzEventHubAuthorizationRule_CreateViaIdentity -InputObject $authRule -Parameter $authRule @PSBoundParameters + Az.EventHub.private\New-AzEventHubAuthorizationRule_CreateViaIdentity -InputObject $authRule -Parameter $authRule @targetParameters } } - + elseif ($PSCmdlet.ParameterSetName -eq 'SetViaIdentityExpanded'){ - + if ($ResourceHashTable['EventHubName'] -ne $null){ if ($PSCmdlet.ShouldProcess("EventHub Entity Authorization Rule $($ResourceHashTable['AuthorizationRuleName'])", "Create or update")) { - Az.EventHub.private\New-AzEventHubAuthorizationRule_CreateViaIdentity -InputObject $authRule -Parameter $authRule @PSBoundParameters + Az.EventHub.private\New-AzEventHubAuthorizationRule_CreateViaIdentity -InputObject $authRule -Parameter $authRule @targetParameters } } elseif ($ResourceHashTable['NamespaceName'] -ne $null){ if ($PSCmdlet.ShouldProcess("EventHub Namespace Authorization Rule $($ResourceHashTable['AuthorizationRuleName'])", "Create or update")) { - Az.EventHub.private\New-AzEventHubNamespaceAuthorizationRule_CreateViaIdentity -InputObject $authRule -Parameter $authRule @PSBoundParameters + Az.EventHub.private\New-AzEventHubNamespaceAuthorizationRule_CreateViaIdentity -InputObject $authRule -Parameter $authRule @targetParameters } } else{ diff --git a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubCluster.ps1 b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubCluster.ps1 index a0407b3d9711..3b5969ddef0a 100644 --- a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubCluster.ps1 +++ b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubCluster.ps1 @@ -135,19 +135,20 @@ function Set-AzEventHubCluster{ } process{ try{ - $hasCapacity = $PSBoundParameters.Remove('Capacity') - $hasTag = $PSBoundParameters.Remove('Tag') - $hasAsJob = $PSBoundParameters.Remove('AsJob') - $null = $PSBoundParameters.Remove('WhatIf') - $null = $PSBoundParameters.Remove('Confirm') - - $cluster = Get-AzEventHubCluster @PSBoundParameters - + $targetParameters = @{} + $PSBoundParameters + $hasCapacity = $targetParameters.Remove('Capacity') + $hasTag = $targetParameters.Remove('Tag') + $hasAsJob = $targetParameters.Remove('AsJob') + $null = $targetParameters.Remove('WhatIf') + $null = $targetParameters.Remove('Confirm') + + $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHubCluster' -BoundParameters $targetParameters + $cluster = Get-AzEventHubCluster @readParameters # 2. PUT - $null = $PSBoundParameters.Remove('InputObject') - $null = $PSBoundParameters.Remove('ResourceGroupName') - $null = $PSBoundParameters.Remove('Name') - $null = $PSBoundParameters.Remove('SubscriptionId') + $null = $targetParameters.Remove('InputObject') + $null = $targetParameters.Remove('ResourceGroupName') + $null = $targetParameters.Remove('Name') + $null = $targetParameters.Remove('SubscriptionId') $hasProperty = $false @@ -165,11 +166,11 @@ function Set-AzEventHubCluster{ } if ($hasAsJob) { - $PSBoundParameters.Add('AsJob', $true) + $targetParameters.Add('AsJob', $true) } if ($PSCmdlet.ShouldProcess("EventHub Cluster $($cluster.Name)", "Create or update")) { - Az.EventHub.private\New-AzEventHubCluster_CreateViaIdentity -InputObject $cluster -Parameter $cluster @PSBoundParameters + Az.EventHub.private\New-AzEventHubCluster_CreateViaIdentity -InputObject $cluster -Parameter $cluster @targetParameters } } catch{ diff --git a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubConsumerGroup.ps1 b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubConsumerGroup.ps1 index b16f6914d708..a92141cbfd75 100644 --- a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubConsumerGroup.ps1 +++ b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubConsumerGroup.ps1 @@ -68,7 +68,7 @@ function Set-AzEventHubConsumerGroup{ [System.String] # User Metadata is a placeholder to store user-defined string data with maximum length 1024. e.g. it can be used to store descriptive data, such as list of teams and their contact information also user-defined configuration settings can be stored. ${UserMetadata}, - + [Parameter(HelpMessage = "The credentials, account, tenant, and subscription used for communication with Azure.")] [Alias('AzureRMContext', 'AzureCredential')] [ValidateNotNull()] @@ -141,29 +141,30 @@ function Set-AzEventHubConsumerGroup{ } process{ try{ - $hasUserMetadata = $PSBoundParameters.Remove('UserMetadata') - $hasAsJob = $PSBoundParameters.Remove('AsJob') - $null = $PSBoundParameters.Remove('WhatIf') - $null = $PSBoundParameters.Remove('Confirm') - - $consumerGroup = Get-AzEventHubConsumerGroup @PSBoundParameters - + $targetParameters = @{} + $PSBoundParameters + $hasUserMetadata = $targetParameters.Remove('UserMetadata') + $hasAsJob = $targetParameters.Remove('AsJob') + $null = $targetParameters.Remove('WhatIf') + $null = $targetParameters.Remove('Confirm') + + $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHubConsumerGroup' -BoundParameters $targetParameters + $consumerGroup = Get-AzEventHubConsumerGroup @readParameters # 2. PUT - $null = $PSBoundParameters.Remove('InputObject') - $null = $PSBoundParameters.Remove('ResourceGroupName') - $null = $PSBoundParameters.Remove('NamespaceName') - $null = $PSBoundParameters.Remove('EventHubName') - $null = $PSBoundParameters.Remove('Name') - $null = $PSBoundParameters.Remove('SubscriptionId') + $null = $targetParameters.Remove('InputObject') + $null = $targetParameters.Remove('ResourceGroupName') + $null = $targetParameters.Remove('NamespaceName') + $null = $targetParameters.Remove('EventHubName') + $null = $targetParameters.Remove('Name') + $null = $targetParameters.Remove('SubscriptionId') if ($hasUserMetadata) { $consumerGroup.UserMetadata = $UserMetadata } if ($hasAsJob) { - $PSBoundParameters.Add('AsJob', $true) + $targetParameters.Add('AsJob', $true) } if ($PSCmdlet.ShouldProcess("EventHub Consumer Group $($consumerGroup.Name)", "Create or update")) { - Az.EventHub.private\New-AzEventHubConsumerGroup_CreateViaIdentity -InputObject $consumerGroup -Parameter $consumerGroup @PSBoundParameters + Az.EventHub.private\New-AzEventHubConsumerGroup_CreateViaIdentity -InputObject $consumerGroup -Parameter $consumerGroup @targetParameters } } catch{ diff --git a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubGeoDRConfigurationBreakPair.ps1 b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubGeoDRConfigurationBreakPair.ps1 index 6022a9369e14..6e9642409fa5 100644 --- a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubGeoDRConfigurationBreakPair.ps1 +++ b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubGeoDRConfigurationBreakPair.ps1 @@ -54,7 +54,7 @@ function Set-AzEventHubGeoDRConfigurationBreakPair{ # Identity Parameter # To construct, see NOTES section for INPUTOBJECT properties and create a hash table. ${InputObject}, - + [Parameter(HelpMessage = "The credentials, account, tenant, and subscription used for communication with Azure.")] [Alias('AzureRMContext', 'AzureCredential')] [ValidateNotNull()] @@ -127,43 +127,44 @@ function Set-AzEventHubGeoDRConfigurationBreakPair{ } process{ try{ - $hasAsJob = $PSBoundParameters.Remove('AsJob') - $null = $PSBoundParameters.Remove('WhatIf') - $null = $PSBoundParameters.Remove('Confirm') - - $drConfig = Get-AzEventHubGeoDRConfiguration @PSBoundParameters + $targetParameters = @{} + $PSBoundParameters + $hasAsJob = $targetParameters.Remove('AsJob') + $null = $targetParameters.Remove('WhatIf') + $null = $targetParameters.Remove('Confirm') + $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHubGeoDRConfiguration' -BoundParameters $targetParameters + $drConfig = Get-AzEventHubGeoDRConfiguration @readParameters # 2. PUT - $null = $PSBoundParameters.Remove('InputObject') + $null = $targetParameters.Remove('InputObject') if ($hasAsJob) { - $PSBoundParameters.Add('AsJob', $true) + $targetParameters.Add('AsJob', $true) } if($PSCmdlet.ParameterSetName -eq 'Break'){ if ($PSCmdlet.ShouldProcess("EventHub Disaster Recovery Alias $($Name)", "Break Pair")) { - Az.EventHub.private\Invoke-AzEventHubBreakDisasterRecoveryConfigPairing_Break @PSBoundParameters + Az.EventHub.private\Invoke-AzEventHubBreakDisasterRecoveryConfigPairing_Break @targetParameters } } elseif($PSCmdlet.ParameterSetName -eq 'BreakViaIdentity'){ $EnvPSBoundParameters = @{} - if ($PSBoundParameters.ContainsKey('Debug')) { + if ($targetParameters.ContainsKey('Debug')) { $EnvPSBoundParameters['Debug'] = $Debug } - if ($PSBoundParameters.ContainsKey('HttpPipelineAppend')) { + if ($targetParameters.ContainsKey('HttpPipelineAppend')) { $EnvPSBoundParameters['HttpPipelineAppend'] = $HttpPipelineAppend } - if ($PSBoundParameters.ContainsKey('HttpPipelinePrepend')) { + if ($targetParameters.ContainsKey('HttpPipelinePrepend')) { $EnvPSBoundParameters['HttpPipelinePrepend'] = $HttpPipelinePrepend } - if ($PSBoundParameters.ContainsKey('Proxy')) { + if ($targetParameters.ContainsKey('Proxy')) { $EnvPSBoundParameters['Proxy'] = $Proxy } - if ($PSBoundParameters.ContainsKey('ProxyCredential')) { + if ($targetParameters.ContainsKey('ProxyCredential')) { $EnvPSBoundParameters['ProxyCredential'] = $ProxyCredential } - if ($PSBoundParameters.ContainsKey('ProxyUseDefaultCredentials')) { + if ($targetParameters.ContainsKey('ProxyUseDefaultCredentials')) { $EnvPSBoundParameters['ProxyUseDefaultCredentials'] = $ProxyUseDefaultCredentials } diff --git a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubGeoDRConfigurationFailOver.ps1 b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubGeoDRConfigurationFailOver.ps1 index 67e4ddadda4b..22b3fc96b502 100644 --- a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubGeoDRConfigurationFailOver.ps1 +++ b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubGeoDRConfigurationFailOver.ps1 @@ -54,7 +54,7 @@ function Set-AzEventHubGeoDRConfigurationFailOver{ # Identity Parameter # To construct, see NOTES section for INPUTOBJECT properties and create a hash table. ${InputObject}, - + [Parameter(HelpMessage = "The credentials, account, tenant, and subscription used for communication with Azure.")] [Alias('AzureRMContext', 'AzureCredential')] [ValidateNotNull()] @@ -127,43 +127,44 @@ function Set-AzEventHubGeoDRConfigurationFailOver{ } process{ try{ - $hasAsJob = $PSBoundParameters.Remove('AsJob') - $null = $PSBoundParameters.Remove('WhatIf') - $null = $PSBoundParameters.Remove('Confirm') - - $drConfig = Get-AzEventHubGeoDRConfiguration @PSBoundParameters + $targetParameters = @{} + $PSBoundParameters + $hasAsJob = $targetParameters.Remove('AsJob') + $null = $targetParameters.Remove('WhatIf') + $null = $targetParameters.Remove('Confirm') + $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHubGeoDRConfiguration' -BoundParameters $targetParameters + $drConfig = Get-AzEventHubGeoDRConfiguration @readParameters # 2. PUT - $null = $PSBoundParameters.Remove('InputObject') + $null = $targetParameters.Remove('InputObject') if ($hasAsJob) { - $PSBoundParameters.Add('AsJob', $true) + $targetParameters.Add('AsJob', $true) } if($PSCmdlet.ParameterSetName -eq 'Fail'){ if ($PSCmdlet.ShouldProcess("EventHub Disaster Recovery Alias $($Name)", "Fail Over")) { - Az.EventHub.private\Invoke-AzEventHubFailDisasterRecoveryConfigOver_Fail @PSBoundParameters + Az.EventHub.private\Invoke-AzEventHubFailDisasterRecoveryConfigOver_Fail @targetParameters } } elseif($PSCmdlet.ParameterSetName -eq 'FailViaIdentity'){ $EnvPSBoundParameters = @{} - if ($PSBoundParameters.ContainsKey('Debug')) { + if ($targetParameters.ContainsKey('Debug')) { $EnvPSBoundParameters['Debug'] = $Debug } - if ($PSBoundParameters.ContainsKey('HttpPipelineAppend')) { + if ($targetParameters.ContainsKey('HttpPipelineAppend')) { $EnvPSBoundParameters['HttpPipelineAppend'] = $HttpPipelineAppend } - if ($PSBoundParameters.ContainsKey('HttpPipelinePrepend')) { + if ($targetParameters.ContainsKey('HttpPipelinePrepend')) { $EnvPSBoundParameters['HttpPipelinePrepend'] = $HttpPipelinePrepend } - if ($PSBoundParameters.ContainsKey('Proxy')) { + if ($targetParameters.ContainsKey('Proxy')) { $EnvPSBoundParameters['Proxy'] = $Proxy } - if ($PSBoundParameters.ContainsKey('ProxyCredential')) { + if ($targetParameters.ContainsKey('ProxyCredential')) { $EnvPSBoundParameters['ProxyCredential'] = $ProxyCredential } - if ($PSBoundParameters.ContainsKey('ProxyUseDefaultCredentials')) { + if ($targetParameters.ContainsKey('ProxyUseDefaultCredentials')) { $EnvPSBoundParameters['ProxyUseDefaultCredentials'] = $ProxyUseDefaultCredentials } diff --git a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubNamespace.ps1 b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubNamespace.ps1 index d8d3d593808a..a50c38fd8236 100644 --- a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubNamespace.ps1 +++ b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubNamespace.ps1 @@ -21,7 +21,7 @@ Updates an EventHub Namespace function Set-AzEventHubNamespace{ [Alias("Set-AzEventHubNamespaceV2")] - [OutputType([Microsoft.Azure.PowerShell.Cmdlets.EventHub.Models.IEhNamespace])] + [OutputType([Microsoft.Azure.PowerShell.Cmdlets.EventHub.Models.IEhNamespace])] [CmdletBinding(DefaultParameterSetName = 'SetExpanded', PositionalBinding = $false, SupportsShouldProcess, ConfirmImpact = 'Medium')] param( @@ -204,33 +204,34 @@ function Set-AzEventHubNamespace{ } process{ try{ - $hasAlternateName = $PSBoundParameters.Remove('AlternateName') - $hasDisableLocalAuth = $PSBoundParameters.Remove('DisableLocalAuth') - $hasKeyVaultProperty = $PSBoundParameters.Remove('KeyVaultProperty') - $hasUserAssignedIdentityId = $PSBoundParameters.Remove('UserAssignedIdentityId') - $hasIdentityType = $PSBoundParameters.Remove('IdentityType') - $hasEnableAutoInflate = $PSBoundParameters.Remove('EnableAutoInflate') - $hasMaximumThroughputUnit = $PSBoundParameters.Remove('MaximumThroughputUnit') - $hasMinimumTlsVersion = $PSBoundParameters.Remove('MinimumTlsVersion') - $hasRequireInfrastructureEncryption = $PSBoundParameters.Remove('RequireInfrastructureEncryption') - $hasPublicNetworkAccess = $PSBoundParameters.Remove('PublicNetworkAccess') - $hasSkuCapacity = $PSBoundParameters.Remove('SkuCapacity') - $hasTag = $PSBoundParameters.Remove('Tag') - $hasAsJob = $PSBoundParameters.Remove('AsJob') - $hasIPAddressType = $PSBoundParameters.Remove('IPAddressType') - $hasGeoDataReplicationLocation = $PSBoundParameters.Remove('GeoDataReplicationLocation') - $hasGeoDataReplicationMaxReplicationLagDurationInSecond = $PSBoundParameters.Remove('GeoDataReplicationMaxReplicationLagDurationInSecond') - $null = $PSBoundParameters.Remove('WhatIf') - $null = $PSBoundParameters.Remove('Confirm') - - $eventHubNamespace = Get-AzEventHubNamespace @PSBoundParameters - + $targetParameters = @{} + $PSBoundParameters + $hasAlternateName = $targetParameters.Remove('AlternateName') + $hasDisableLocalAuth = $targetParameters.Remove('DisableLocalAuth') + $hasKeyVaultProperty = $targetParameters.Remove('KeyVaultProperty') + $hasUserAssignedIdentityId = $targetParameters.Remove('UserAssignedIdentityId') + $hasIdentityType = $targetParameters.Remove('IdentityType') + $hasEnableAutoInflate = $targetParameters.Remove('EnableAutoInflate') + $hasMaximumThroughputUnit = $targetParameters.Remove('MaximumThroughputUnit') + $hasMinimumTlsVersion = $targetParameters.Remove('MinimumTlsVersion') + $hasRequireInfrastructureEncryption = $targetParameters.Remove('RequireInfrastructureEncryption') + $hasPublicNetworkAccess = $targetParameters.Remove('PublicNetworkAccess') + $hasSkuCapacity = $targetParameters.Remove('SkuCapacity') + $hasTag = $targetParameters.Remove('Tag') + $hasAsJob = $targetParameters.Remove('AsJob') + $hasIPAddressType = $targetParameters.Remove('IPAddressType') + $hasGeoDataReplicationLocation = $targetParameters.Remove('GeoDataReplicationLocation') + $hasGeoDataReplicationMaxReplicationLagDurationInSecond = $targetParameters.Remove('GeoDataReplicationMaxReplicationLagDurationInSecond') + $null = $targetParameters.Remove('WhatIf') + $null = $targetParameters.Remove('Confirm') + + $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHubNamespace' -BoundParameters $targetParameters + $eventHubNamespace = Get-AzEventHubNamespace @readParameters # 2. PUT - $null = $PSBoundParameters.Remove('InputObject') - $null = $PSBoundParameters.Remove('ResourceGroupName') - $null = $PSBoundParameters.Remove('NamespaceName') - $null = $PSBoundParameters.Remove('Name') - $null = $PSBoundParameters.Remove('SubscriptionId') + $null = $targetParameters.Remove('InputObject') + $null = $targetParameters.Remove('ResourceGroupName') + $null = $targetParameters.Remove('NamespaceName') + $null = $targetParameters.Remove('Name') + $null = $targetParameters.Remove('SubscriptionId') if ($hasAlternateName) { $eventHubNamespace.AlternateName = $AlternateName @@ -285,11 +286,11 @@ function Set-AzEventHubNamespace{ $eventHubNamespace.Tag = $Tag } if ($hasAsJob) { - $PSBoundParameters.Add('AsJob', $true) + $targetParameters.Add('AsJob', $true) } if ($PSCmdlet.ShouldProcess("EventHubNamespace $($eventHubNamespace.Name)", "Create or update")) { - Az.EventHub.private\New-AzEventHubNamespace_CreateViaIdentity -InputObject $eventHubNamespace -Parameter $eventHubNamespace @PSBoundParameters + Az.EventHub.private\New-AzEventHubNamespace_CreateViaIdentity -InputObject $eventHubNamespace -Parameter $eventHubNamespace @targetParameters } } catch{ diff --git a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubNetworkRuleSet.ps1 b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubNetworkRuleSet.ps1 index a1057f2af3fe..1918a8564909 100644 --- a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubNetworkRuleSet.ps1 +++ b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubNetworkRuleSet.ps1 @@ -53,7 +53,7 @@ function Set-AzEventHubNetworkRuleSet{ [Parameter(HelpMessage = "This determines if traffic is allowed over public network. By default it is enabled. If value is SecuredByPerimeter then Inbound and Outbound communication is controlled by the network security perimeter and profile's access rules. ")] [Microsoft.Azure.PowerShell.Cmdlets.EventHub.Category('Body')] [System.String] - #This determines if traffic is allowed over public network. By default it is enabled. If value is SecuredByPerimeter then Inbound and Outbound communication is controlled by the network security perimeter and profile's access rules. + #This determines if traffic is allowed over public network. By default it is enabled. If value is SecuredByPerimeter then Inbound and Outbound communication is controlled by the network security perimeter and profile's access rules. ${PublicNetworkAccess}, [Parameter(HelpMessage = "Value that indicates whether Trusted Service Access is Enabled or not.")] @@ -152,22 +152,23 @@ function Set-AzEventHubNetworkRuleSet{ } process{ try{ - $hasPublicNetworkAccess = $PSBoundParameters.Remove('PublicNetworkAccess') - $hasTrustedServiceAccessEnabled = $PSBoundParameters.Remove('TrustedServiceAccessEnabled') - $hasDefaultAction = $PSBoundParameters.Remove('DefaultAction') - $hasIPRule = $PSBoundParameters.Remove('IPRule') - $hasVirtualNetworkRule = $PSBoundParameters.Remove('VirtualNetworkRule') - $hasAsJob = $PSBoundParameters.Remove('AsJob') - $null = $PSBoundParameters.Remove('WhatIf') - $null = $PSBoundParameters.Remove('Confirm') - - $networkRuleSet = Get-AzEventHubNetworkRuleSet @PSBoundParameters - + $targetParameters = @{} + $PSBoundParameters + $hasPublicNetworkAccess = $targetParameters.Remove('PublicNetworkAccess') + $hasTrustedServiceAccessEnabled = $targetParameters.Remove('TrustedServiceAccessEnabled') + $hasDefaultAction = $targetParameters.Remove('DefaultAction') + $hasIPRule = $targetParameters.Remove('IPRule') + $hasVirtualNetworkRule = $targetParameters.Remove('VirtualNetworkRule') + $hasAsJob = $targetParameters.Remove('AsJob') + $null = $targetParameters.Remove('WhatIf') + $null = $targetParameters.Remove('Confirm') + + $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHubNetworkRuleSet' -BoundParameters $targetParameters + $networkRuleSet = Get-AzEventHubNetworkRuleSet @readParameters # 2. PUT - $null = $PSBoundParameters.Remove('InputObject') - $null = $PSBoundParameters.Remove('ResourceGroupName') - $null = $PSBoundParameters.Remove('NamespaceName') - $null = $PSBoundParameters.Remove('SubscriptionId') + $null = $targetParameters.Remove('InputObject') + $null = $targetParameters.Remove('ResourceGroupName') + $null = $targetParameters.Remove('NamespaceName') + $null = $targetParameters.Remove('SubscriptionId') $hasProperty = $false @@ -197,11 +198,11 @@ function Set-AzEventHubNetworkRuleSet{ } if ($hasAsJob) { - $PSBoundParameters.Add('AsJob', $true) + $targetParameters.Add('AsJob', $true) } if ($PSCmdlet.ShouldProcess("EventHub Network Rule Set on namespace $($networkRuleSet.Name)", "Create or update")) { - Az.EventHub.private\New-AzEventHubNetworkRuleSet_CreateViaIdentity -InputObject $networkRuleSet -Parameter $networkRuleSet @PSBoundParameters + Az.EventHub.private\New-AzEventHubNetworkRuleSet_CreateViaIdentity -InputObject $networkRuleSet -Parameter $networkRuleSet @targetParameters } } catch{ diff --git a/src/EventHub/EventHub.Autorest/generate-info.json b/src/EventHub/EventHub.Autorest/generate-info.json index 1f4d0223bf71..5e91eccfaab6 100644 --- a/src/EventHub/EventHub.Autorest/generate-info.json +++ b/src/EventHub/EventHub.Autorest/generate-info.json @@ -1,3 +1,3 @@ { - "generate_Id": "37e57dcc-9680-41ff-a019-ec549669f7b0" + "generate_Id": "7433a5f8-b6ec-4ce4-a9b6-8b320d711a49" } diff --git a/src/EventHub/EventHub.Autorest/test/ReadParameterForwarding.Tests.ps1 b/src/EventHub/EventHub.Autorest/test/ReadParameterForwarding.Tests.ps1 new file mode 100644 index 000000000000..507292ab582e --- /dev/null +++ b/src/EventHub/EventHub.Autorest/test/ReadParameterForwarding.Tests.ps1 @@ -0,0 +1,109 @@ +$helperPath = Join-Path $PSScriptRoot '..\custom\Get-AzEventHubReadParameters.ps1' +$helperSource = Get-Content -Path $helperPath -Raw +$helperSource = $helperSource -replace '(?m)^\s*\[Microsoft\.Azure\.PowerShell\.Cmdlets\.EventHub\.DoNotExportAttribute\(\)\]\r?\n', '' +. ([scriptblock]::Create($helperSource)) + +function Get-AzEventHubReadTestResource { + [CmdletBinding()] + param( + [Alias('ResourceName')] + [string] $Name, + [object] $DefaultProfile + ) + + $script:eventHubReadParameters = @{} + $PSBoundParameters +} + +function Set-AzEventHubReadTestResource { + [CmdletBinding()] + param( + [string] $Name, + [object] $DefaultProfile, + [switch] $AcquirePolicyToken, + [string] $ChangeReference, + [string] $SyntheticWriteOnly + ) + + $script:eventHubWriteParameters = @{} + $PSBoundParameters +} + +Set-Alias -Name Get-AzEventHubReadTestAlias -Value Get-AzEventHubReadTestResource + +Describe 'EventHub read parameter forwarding' { + It 'filters write-only parameters using read command metadata without changing target parameters' { + $targetParameters = @{ + Name = 'eventhub' + DefaultProfile = 'profile' + ErrorAction = 'Stop' + AcquirePolicyToken = $true + ChangeReference = 'change-123' + SyntheticWriteOnly = 'future-value' + } + + $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHubReadTestAlias' -BoundParameters $targetParameters + Get-AzEventHubReadTestResource @readParameters + Set-AzEventHubReadTestResource @targetParameters + + $script:eventHubReadParameters.Name | Should Be 'eventhub' + $script:eventHubReadParameters.DefaultProfile | Should Be 'profile' + $script:eventHubReadParameters.ErrorAction | Should Be 'Stop' + $script:eventHubReadParameters.ContainsKey('AcquirePolicyToken') | Should Be $false + $script:eventHubReadParameters.ContainsKey('ChangeReference') | Should Be $false + $script:eventHubReadParameters.ContainsKey('SyntheticWriteOnly') | Should Be $false + $script:eventHubWriteParameters.AcquirePolicyToken | Should Be $true + $script:eventHubWriteParameters.ChangeReference | Should Be 'change-123' + $script:eventHubWriteParameters.SyntheticWriteOnly | Should Be 'future-value' + } + + It 'recognizes read parameter aliases' { + $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHubReadTestResource' -BoundParameters @{ ResourceName = 'eventhub' } + + $readParameters.ResourceName | Should Be 'eventhub' + } + + It 'uses separate read and target parameter groups in every affected wrapper' { + $wrappers = @( + 'Approve-AzEventHubPrivateEndpointConnection.ps1', + 'Deny-AzEventHubPrivateEndpointConnection.ps1', + 'Set-AzEventHub.ps1', + 'Set-AzEventHubApplicationGroup.ps1', + 'Set-AzEventHubAuthorizationRule.ps1', + 'Set-AzEventHubCluster.ps1', + 'Set-AzEventHubConsumerGroup.ps1', + 'Set-AzEventHubGeoDRConfigurationBreakPair.ps1', + 'Set-AzEventHubGeoDRConfigurationFailOver.ps1', + 'Set-AzEventHubNamespace.ps1', + 'Set-AzEventHubNetworkRuleSet.ps1' + ) + + foreach ($wrapper in $wrappers) { + $source = Get-Content -Path (Join-Path $PSScriptRoot "..\custom\$wrapper") -Raw + $source | Should Match '\$targetParameters\s*=\s*@\{\}\s*\+\s*\$PSBoundParameters' + $source | Should Match 'Get-AzEventHubReadParameters\s+-CommandName' + $source | Should Match '@readParameters' + $source | Should Match '@targetParameters' + } + } + + It 'keeps exact expanded and via-identity read variants for authorization rules' { + $source = Get-Content -Path (Join-Path $PSScriptRoot '..\custom\Set-AzEventHubAuthorizationRule.ps1') -Raw + + $source | Should Match "CommandName 'Az\.EventHub\.private\\Get-AzEventHubAuthorizationRule_Get'" + $source | Should Match "CommandName 'Az\.EventHub\.private\\Get-AzEventHubAuthorizationRule_GetViaIdentity'" + $source | Should Match "CommandName 'Az\.EventHub\.private\\Get-AzEventHubNamespaceAuthorizationRule_GetViaIdentity'" + } + + It 'packages the internal helper and triggers regeneration' { + $customPath = Join-Path $PSScriptRoot '..\custom' + $helperPath = Join-Path $customPath 'Get-AzEventHubReadParameters.ps1' + $moduleSource = Get-Content -Path (Join-Path $customPath 'Az.EventHub.custom.psm1') -Raw + $helperSource = Get-Content -Path $helperPath -Raw + $generation = Get-Content -Path (Join-Path $PSScriptRoot '..\generate-info.json') -Raw | ConvertFrom-Json + + Test-Path -Path $helperPath | Should Be $true + $helperSource | Should Match '\[Microsoft\.Azure\.PowerShell\.Cmdlets\.EventHub\.DoNotExportAttribute\(\)\]' + $moduleSource | Should Match "Get-ChildItem\s+-Path\s+\`$PSScriptRoot\s+-Recurse\s+-Include\s+'\*\.ps1'" + { [guid]::Parse($generation.generate_Id) } | Should Not Throw + $generation.generate_Id | Should Not Be '37e57dcc-9680-41ff-a019-ec549669f7b0' + } +} diff --git a/src/EventHub/EventHub/ChangeLog.md b/src/EventHub/EventHub/ChangeLog.md index ec175fff137f..6cd93b4bf27f 100644 --- a/src/EventHub/EventHub/ChangeLog.md +++ b/src/EventHub/EventHub/ChangeLog.md @@ -19,6 +19,7 @@ --> ## Upcoming Release * Added Change Safety support for additional cmdlets. +* Fixed Change Safety parameter forwarding in custom GET-before-write cmdlets. ## Version 5.6.0 * Added parameter `IPAddressType` to cmdlets 'New-AzEventHubNamespace' and 'Set-AzEventHubNamespace' diff --git a/src/Network/Network/ChangeLog.md b/src/Network/Network/ChangeLog.md index 83a75cc75cce..679b1c657c0e 100644 --- a/src/Network/Network/ChangeLog.md +++ b/src/Network/Network/ChangeLog.md @@ -26,6 +26,7 @@ * Added support for the `CAPTCHA` action in Application Gateway WAF (Web Application Firewall) policies. - Added `CAPTCHA` as an allowed value for the `-Action` parameter of custom rules (`New-AzApplicationGatewayFirewallCustomRule`) and managed rule overrides (`New-AzApplicationGatewayFirewallPolicyManagedRuleOverride`). - Added the `-CaptchaExpirationInMins` parameter to `New-AzApplicationGatewayFirewallPolicySetting`. +* Fixed Change Safety parameter forwarding in Network Security Perimeter update cmdlets. ## Version 8.2.0 * Added `Get-AzExpressRouteLag`, `New-AzExpressRouteLag`, `Set-AzExpressRouteLag`, `Remove-AzExpressRouteLag`, `New-AzExpressRouteLagLOA`, `Get-AzExpressRouteLagLink`, and `Get-AzExpressRouteLagMember` for `ExpressRouteLag` resources (Microsoft.Network 2025-09-01 API). @@ -96,7 +97,6 @@ ## Version 8.0.1 * Onboarded `Microsoft.HorizonDB/clusters` to Private Link Common Cmdlets - ## Version 8.0.0 * Added ChangeSafety Support * Changed `UserAssignedIdentityId` type to string[] diff --git a/src/Network/NetworkSecurityPerimeter.Autorest/custom/Get-AzNetworkSecurityPerimeterReadParameters.ps1 b/src/Network/NetworkSecurityPerimeter.Autorest/custom/Get-AzNetworkSecurityPerimeterReadParameters.ps1 new file mode 100644 index 000000000000..0e72e74dbfb8 --- /dev/null +++ b/src/Network/NetworkSecurityPerimeter.Autorest/custom/Get-AzNetworkSecurityPerimeterReadParameters.ps1 @@ -0,0 +1,30 @@ +function Get-AzNetworkSecurityPerimeterReadParameters { + [Microsoft.Azure.PowerShell.Cmdlets.NetworkSecurityPerimeter.DoNotExportAttribute()] + [CmdletBinding()] + param( + [Parameter(Mandatory)] + [System.String] + ${CommandName}, + + [Parameter(Mandatory)] + [System.Collections.IDictionary] + ${BoundParameters} + ) + + $command = @(Get-Command -Name $CommandName -ErrorAction Stop)[0] + while ($command.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { + $command = Get-Command -Name $command.ResolvedCommandName -ErrorAction Stop + } + + $parameterNames = @($command.Parameters.Keys) + $parameterNames += @($command.Parameters.Values | ForEach-Object { $_.Aliases }) + + $readParameters = @{} + foreach ($parameter in $BoundParameters.GetEnumerator()) { + if ($parameter.Key -in $parameterNames) { + $readParameters[$parameter.Key] = $parameter.Value + } + } + + return $readParameters +} diff --git a/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterAccessRule.ps1 b/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterAccessRule.ps1 index 4ca2c9c9ad33..93ee0ce91e49 100644 --- a/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterAccessRule.ps1 +++ b/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterAccessRule.ps1 @@ -24,7 +24,7 @@ function Update-AzNetworkSecurityPerimeterAccessRule { [CmdletBinding(DefaultParameterSetName = 'UpdateExpanded', PositionalBinding = $false, SupportsShouldProcess, ConfirmImpact = 'Medium')] param( - #Runtime paramters + #Runtime paramters [Parameter(HelpMessage = "Run the command as a job")] [Microsoft.Azure.PowerShell.Cmdlets.NetworkSecurityPerimeter.Category('Runtime')] @@ -79,7 +79,7 @@ function Update-AzNetworkSecurityPerimeterAccessRule { # Azure parameters - + [Parameter(HelpMessage = "The credentials, account, tenant, and subscription used for communication with Azure.")] [Alias('AzureRMContext', 'AzureCredential')] [ValidateNotNull()] @@ -134,7 +134,7 @@ function Update-AzNetworkSecurityPerimeterAccessRule { # Body paramters - + [Parameter(HelpMessage = "Address Prefix")] [Microsoft.Azure.PowerShell.Cmdlets.NetworkSecurityPerimeter.Category('Body')] [System.String[]] @@ -199,7 +199,7 @@ function Update-AzNetworkSecurityPerimeterAccessRule { process { try { - + $targetParameters = @{} + $PSBoundParameters # 1. GET # body params and AsJob @@ -208,21 +208,21 @@ function Update-AzNetworkSecurityPerimeterAccessRule { $bodyParamsMap = @{} ForEach($bodyParam in $bodyParams){ - $bodyParamsMap[$bodyParam] = $PSBoundParameters.Remove($bodyParam) + $bodyParamsMap[$bodyParam] = $targetParameters.Remove($bodyParam) } - $null = $PSBoundParameters.Remove('WhatIf') - $null = $PSBoundParameters.Remove('Confirm') + $null = $targetParameters.Remove('WhatIf') + $null = $targetParameters.Remove('Confirm') - $GETObject = Get-AzNetworkSecurityPerimeterAccessRule @PSBoundParameters - + $readParameters = Get-AzNetworkSecurityPerimeterReadParameters -CommandName 'Get-AzNetworkSecurityPerimeterAccessRule' -BoundParameters $targetParameters + $GETObject = Get-AzNetworkSecurityPerimeterAccessRule @readParameters # 2. PUT $pathParams = 'InputObject', 'ResourceGroupName', 'Name', 'SubscriptionId', 'SecurityPerimeterName', 'ProfileName' - ForEach($pathParam in $pathParams){ - $null = $PSBoundParameters.Remove($pathParam) + ForEach($pathParam in $pathParams){ + $null = $targetParameters.Remove($pathParam) } foreach ($item in $bodyParamsMap.GetEnumerator() ) @@ -235,9 +235,9 @@ function Update-AzNetworkSecurityPerimeterAccessRule { $GETObject.$key = $variable } } - + # Call PUT method - New-AzNetworkSecurityPerimeterAccessRule_CreateViaIdentity -InputObject $GETObject -Parameter $GETObject @PSBoundParameters + New-AzNetworkSecurityPerimeterAccessRule_CreateViaIdentity -InputObject $GETObject -Parameter $GETObject @targetParameters } diff --git a/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterAssociation.ps1 b/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterAssociation.ps1 index 932f708dc6ac..e2d2bbbf02d4 100644 --- a/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterAssociation.ps1 +++ b/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterAssociation.ps1 @@ -24,7 +24,7 @@ function Update-AzNetworkSecurityPerimeterAssociation { [CmdletBinding(DefaultParameterSetName = 'UpdateExpanded', PositionalBinding = $false, SupportsShouldProcess, ConfirmImpact = 'Medium')] param( - #Runtime paramters + #Runtime paramters [Parameter(HelpMessage = "Run the command as a job")] [Microsoft.Azure.PowerShell.Cmdlets.NetworkSecurityPerimeter.Category('Runtime')] @@ -168,7 +168,7 @@ function Update-AzNetworkSecurityPerimeterAssociation { process { try { - + $targetParameters = @{} + $PSBoundParameters # 1. GET # body params and AsJob @@ -177,23 +177,22 @@ function Update-AzNetworkSecurityPerimeterAssociation { $bodyParamsMap = @{} ForEach($bodyParam in $bodyParams){ - $bodyParamsMap[$bodyParam] = $PSBoundParameters.Remove($bodyParam) + $bodyParamsMap[$bodyParam] = $targetParameters.Remove($bodyParam) } - $null = $PSBoundParameters.Remove('WhatIf') - $null = $PSBoundParameters.Remove('Confirm') + $null = $targetParameters.Remove('WhatIf') + $null = $targetParameters.Remove('Confirm') - $GETObject = Get-AzNetworkSecurityPerimeterAssociation @PSBoundParameters - - + $readParameters = Get-AzNetworkSecurityPerimeterReadParameters -CommandName 'Get-AzNetworkSecurityPerimeterAssociation' -BoundParameters $targetParameters + $GETObject = Get-AzNetworkSecurityPerimeterAssociation @readParameters # 2. PUT - + $pathParams = 'InputObject', 'ResourceGroupName', 'Name', 'SubscriptionId', 'SecurityPerimeterName' - ForEach($pathParam in $pathParams){ - $null = $PSBoundParameters.Remove($pathParam) + ForEach($pathParam in $pathParams){ + $null = $targetParameters.Remove($pathParam) } - + foreach ($item in $bodyParamsMap.GetEnumerator() ) { if ($item.Value){ @@ -205,9 +204,9 @@ function Update-AzNetworkSecurityPerimeterAssociation { } } - + # Call PUT method - Az.NetworkSecurityPerimeter.private\New-AzNetworkSecurityPerimeterAssociation_CreateViaIdentity -InputObject $GETObject -Parameter $GETObject @PSBoundParameters + Az.NetworkSecurityPerimeter.private\New-AzNetworkSecurityPerimeterAssociation_CreateViaIdentity -InputObject $GETObject -Parameter $GETObject @targetParameters } catch { diff --git a/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterLink.ps1 b/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterLink.ps1 index 7a8267e7612d..d9199705f158 100644 --- a/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterLink.ps1 +++ b/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterLink.ps1 @@ -24,7 +24,7 @@ function Update-AzNetworkSecurityPerimeterLink { [CmdletBinding(DefaultParameterSetName = 'UpdateExpanded', PositionalBinding = $false, SupportsShouldProcess, ConfirmImpact = 'Medium')] param( - #Runtime paramters + #Runtime paramters [Parameter(HelpMessage = "Run the command as a job")] [Microsoft.Azure.PowerShell.Cmdlets.NetworkSecurityPerimeter.Category('Runtime')] @@ -169,7 +169,7 @@ function Update-AzNetworkSecurityPerimeterLink { process { try { - + $targetParameters = @{} + $PSBoundParameters # 1. GET # body params and AsJob @@ -178,23 +178,22 @@ function Update-AzNetworkSecurityPerimeterLink { $bodyParamsMap = @{} ForEach($bodyParam in $bodyParams){ - $bodyParamsMap[$bodyParam] = $PSBoundParameters.Remove($bodyParam) + $bodyParamsMap[$bodyParam] = $targetParameters.Remove($bodyParam) } - $null = $PSBoundParameters.Remove('WhatIf') - $null = $PSBoundParameters.Remove('Confirm') + $null = $targetParameters.Remove('WhatIf') + $null = $targetParameters.Remove('Confirm') - $GETObject = Get-AzNetworkSecurityPerimeterLink @PSBoundParameters - - + $readParameters = Get-AzNetworkSecurityPerimeterReadParameters -CommandName 'Get-AzNetworkSecurityPerimeterLink' -BoundParameters $targetParameters + $GETObject = Get-AzNetworkSecurityPerimeterLink @readParameters # 2. PUT - + $pathParams = 'InputObject', 'ResourceGroupName', 'Name', 'SubscriptionId', 'SecurityPerimeterName' - ForEach($pathParam in $pathParams){ - $null = $PSBoundParameters.Remove($pathParam) + ForEach($pathParam in $pathParams){ + $null = $targetParameters.Remove($pathParam) } - + foreach ($item in $bodyParamsMap.GetEnumerator() ) { if ($item.Value){ @@ -206,9 +205,9 @@ function Update-AzNetworkSecurityPerimeterLink { } } - + # Call PUT method - Az.NetworkSecurityPerimeter.private\New-AzNetworkSecurityPerimeterLink_CreateViaIdentity -InputObject $GETObject -Parameter $GETObject @PSBoundParameters + Az.NetworkSecurityPerimeter.private\New-AzNetworkSecurityPerimeterLink_CreateViaIdentity -InputObject $GETObject -Parameter $GETObject @targetParameters } catch { diff --git a/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterLoggingConfiguration.ps1 b/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterLoggingConfiguration.ps1 index 5cb73685d18c..75c21bea806e 100644 --- a/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterLoggingConfiguration.ps1 +++ b/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterLoggingConfiguration.ps1 @@ -24,7 +24,7 @@ function Update-AzNetworkSecurityPerimeterLoggingConfiguration { [CmdletBinding(DefaultParameterSetName = 'UpdateExpanded', PositionalBinding = $false, SupportsShouldProcess, ConfirmImpact = 'Medium')] param( - #Runtime paramters + #Runtime paramters [Parameter(HelpMessage = "Run the command as a job")] [Microsoft.Azure.PowerShell.Cmdlets.NetworkSecurityPerimeter.Category('Runtime')] @@ -157,7 +157,7 @@ function Update-AzNetworkSecurityPerimeterLoggingConfiguration { process { try { - + $targetParameters = @{} + $PSBoundParameters # 1. GET # body params and AsJob @@ -166,22 +166,22 @@ function Update-AzNetworkSecurityPerimeterLoggingConfiguration { $bodyParamsMap = @{} ForEach($bodyParam in $bodyParams){ - $bodyParamsMap[$bodyParam] = $PSBoundParameters.Remove($bodyParam) + $bodyParamsMap[$bodyParam] = $targetParameters.Remove($bodyParam) } - $null = $PSBoundParameters.Remove('WhatIf') - $null = $PSBoundParameters.Remove('Confirm') + $null = $targetParameters.Remove('WhatIf') + $null = $targetParameters.Remove('Confirm') - $GETObject = Get-AzNetworkSecurityPerimeterLoggingConfiguration @PSBoundParameters - + $readParameters = Get-AzNetworkSecurityPerimeterReadParameters -CommandName 'Get-AzNetworkSecurityPerimeterLoggingConfiguration' -BoundParameters $targetParameters + $GETObject = Get-AzNetworkSecurityPerimeterLoggingConfiguration @readParameters # 2. PUT - + $pathParams = 'InputObject', 'ResourceGroupName', 'Name', 'SubscriptionId', 'SecurityPerimeterName' - ForEach($pathParam in $pathParams){ - $null = $PSBoundParameters.Remove($pathParam) + ForEach($pathParam in $pathParams){ + $null = $targetParameters.Remove($pathParam) } - + foreach ($item in $bodyParamsMap.GetEnumerator() ) { if ($item.Value){ @@ -193,9 +193,9 @@ function Update-AzNetworkSecurityPerimeterLoggingConfiguration { } } - + # Call PUT method - New-AzNetworkSecurityPerimeterLoggingConfiguration_CreateViaIdentity -InputObject $GETObject -Parameter $GETObject @PSBoundParameters + New-AzNetworkSecurityPerimeterLoggingConfiguration_CreateViaIdentity -InputObject $GETObject -Parameter $GETObject @targetParameters } catch { diff --git a/src/Network/NetworkSecurityPerimeter.Autorest/generate-info.json b/src/Network/NetworkSecurityPerimeter.Autorest/generate-info.json index 9ea7b3bc480b..35c09d8cac42 100644 --- a/src/Network/NetworkSecurityPerimeter.Autorest/generate-info.json +++ b/src/Network/NetworkSecurityPerimeter.Autorest/generate-info.json @@ -1,3 +1,3 @@ { - "generate_Id": "22876a3f-6f36-449b-a291-2b1c423db247" -} \ No newline at end of file + "generate_Id": "a7c0112b-a248-4f70-984b-9fb17d9d5356" +} diff --git a/src/Network/NetworkSecurityPerimeter.Autorest/test/ReadParameterForwarding.Tests.ps1 b/src/Network/NetworkSecurityPerimeter.Autorest/test/ReadParameterForwarding.Tests.ps1 new file mode 100644 index 000000000000..74b020b57a15 --- /dev/null +++ b/src/Network/NetworkSecurityPerimeter.Autorest/test/ReadParameterForwarding.Tests.ps1 @@ -0,0 +1,94 @@ +$helperPath = Join-Path $PSScriptRoot '..\custom\Get-AzNetworkSecurityPerimeterReadParameters.ps1' +$helperSource = Get-Content -Path $helperPath -Raw +$helperSource = $helperSource -replace '(?m)^\s*\[Microsoft\.Azure\.PowerShell\.Cmdlets\.NetworkSecurityPerimeter\.DoNotExportAttribute\(\)\]\r?\n', '' +. ([scriptblock]::Create($helperSource)) + +function Get-AzNetworkSecurityPerimeterReadTestResource { + [CmdletBinding()] + param( + [Alias('ResourceName')] + [string] $Name, + [object] $DefaultProfile + ) + + $script:nspReadParameters = @{} + $PSBoundParameters +} + +function Set-AzNetworkSecurityPerimeterReadTestResource { + [CmdletBinding()] + param( + [string] $Name, + [object] $DefaultProfile, + [switch] $AcquirePolicyToken, + [string] $ChangeReference, + [string] $SyntheticWriteOnly + ) + + $script:nspWriteParameters = @{} + $PSBoundParameters +} + +Set-Alias -Name Get-AzNetworkSecurityPerimeterReadTestAlias -Value Get-AzNetworkSecurityPerimeterReadTestResource + +Describe 'NetworkSecurityPerimeter read parameter forwarding' { + It 'filters write-only parameters using read command metadata without changing target parameters' { + $targetParameters = @{ + Name = 'access-rule' + DefaultProfile = 'profile' + ErrorAction = 'Stop' + AcquirePolicyToken = $true + ChangeReference = 'change-123' + SyntheticWriteOnly = 'future-value' + } + + $readParameters = Get-AzNetworkSecurityPerimeterReadParameters -CommandName 'Get-AzNetworkSecurityPerimeterReadTestAlias' -BoundParameters $targetParameters + Get-AzNetworkSecurityPerimeterReadTestResource @readParameters + Set-AzNetworkSecurityPerimeterReadTestResource @targetParameters + + $script:nspReadParameters.Name | Should Be 'access-rule' + $script:nspReadParameters.DefaultProfile | Should Be 'profile' + $script:nspReadParameters.ErrorAction | Should Be 'Stop' + $script:nspReadParameters.ContainsKey('AcquirePolicyToken') | Should Be $false + $script:nspReadParameters.ContainsKey('ChangeReference') | Should Be $false + $script:nspReadParameters.ContainsKey('SyntheticWriteOnly') | Should Be $false + $script:nspWriteParameters.AcquirePolicyToken | Should Be $true + $script:nspWriteParameters.ChangeReference | Should Be 'change-123' + $script:nspWriteParameters.SyntheticWriteOnly | Should Be 'future-value' + } + + It 'recognizes read parameter aliases' { + $readParameters = Get-AzNetworkSecurityPerimeterReadParameters -CommandName 'Get-AzNetworkSecurityPerimeterReadTestResource' -BoundParameters @{ ResourceName = 'access-rule' } + + $readParameters.ResourceName | Should Be 'access-rule' + } + + It 'uses separate read and target parameter groups in every affected wrapper' { + $wrappers = @( + 'Update-AzNetworkSecurityPerimeterAccessRule.ps1', + 'Update-AzNetworkSecurityPerimeterAssociation.ps1', + 'Update-AzNetworkSecurityPerimeterLink.ps1', + 'Update-AzNetworkSecurityPerimeterLoggingConfiguration.ps1' + ) + + foreach ($wrapper in $wrappers) { + $source = Get-Content -Path (Join-Path $PSScriptRoot "..\custom\$wrapper") -Raw + $source | Should Match '\$targetParameters\s*=\s*@\{\}\s*\+\s*\$PSBoundParameters' + $source | Should Match 'Get-AzNetworkSecurityPerimeterReadParameters\s+-CommandName' + $source | Should Match '@readParameters' + $source | Should Match '@targetParameters' + } + } + + It 'packages the internal helper and triggers regeneration' { + $customPath = Join-Path $PSScriptRoot '..\custom' + $helperPath = Join-Path $customPath 'Get-AzNetworkSecurityPerimeterReadParameters.ps1' + $moduleSource = Get-Content -Path (Join-Path $customPath 'Az.NetworkSecurityPerimeter.custom.psm1') -Raw + $helperSource = Get-Content -Path $helperPath -Raw + $generation = Get-Content -Path (Join-Path $PSScriptRoot '..\generate-info.json') -Raw | ConvertFrom-Json + + Test-Path -Path $helperPath | Should Be $true + $helperSource | Should Match '\[Microsoft\.Azure\.PowerShell\.Cmdlets\.NetworkSecurityPerimeter\.DoNotExportAttribute\(\)\]' + $moduleSource | Should Match "Get-ChildItem\s+-Path\s+\`$PSScriptRoot\s+-Recurse\s+-Include\s+'\*\.ps1'" + { [guid]::Parse($generation.generate_Id) } | Should Not Throw + $generation.generate_Id | Should Not Be '22876a3f-6f36-449b-a291-2b1c423db247' + } +} diff --git a/src/ServiceBus/ServiceBus.Autorest/custom/Approve-AzServiceBusPrivateEndpointConnection.ps1 b/src/ServiceBus/ServiceBus.Autorest/custom/Approve-AzServiceBusPrivateEndpointConnection.ps1 index ed53fbfa22d5..3040099f93f8 100644 --- a/src/ServiceBus/ServiceBus.Autorest/custom/Approve-AzServiceBusPrivateEndpointConnection.ps1 +++ b/src/ServiceBus/ServiceBus.Autorest/custom/Approve-AzServiceBusPrivateEndpointConnection.ps1 @@ -135,13 +135,14 @@ function Approve-AzServiceBusPrivateEndpointConnection{ } process{ try{ - $hasDescription = $PSBoundParameters.Remove('Description') - $hasAsJob = $PSBoundParameters.Remove('AsJob') - $null = $PSBoundParameters.Remove('WhatIf') - $null = $PSBoundParameters.Remove('Confirm') - - $connection = Get-AzServiceBusPrivateEndpointConnection @PSBoundParameters - + $targetParameters = @{} + $PSBoundParameters + $hasDescription = $targetParameters.Remove('Description') + $hasAsJob = $targetParameters.Remove('AsJob') + $null = $targetParameters.Remove('WhatIf') + $null = $targetParameters.Remove('Confirm') + + $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusPrivateEndpointConnection' -BoundParameters $targetParameters + $connection = Get-AzServiceBusPrivateEndpointConnection @readParameters $connection.ConnectionState = "Approved" if($hasDescription){ @@ -152,14 +153,14 @@ function Approve-AzServiceBusPrivateEndpointConnection{ } # 2. PUT - $null = $PSBoundParameters.Remove('InputObject') - $null = $PSBoundParameters.Remove('ResourceGroupName') - $null = $PSBoundParameters.Remove('NamespaceName') - $null = $PSBoundParameters.Remove('Name') - $null = $PSBoundParameters.Remove('SubscriptionId') + $null = $targetParameters.Remove('InputObject') + $null = $targetParameters.Remove('ResourceGroupName') + $null = $targetParameters.Remove('NamespaceName') + $null = $targetParameters.Remove('Name') + $null = $targetParameters.Remove('SubscriptionId') if ($PSCmdlet.ShouldProcess("Approve ServiceBus Namespace PrivateEndpoint Connection $($Name)", "Create or update")) { - Az.ServiceBus.private\New-AzServiceBusPrivateEndpointConnection_CreateViaIdentity -InputObject $connection -Parameter $connection @PSBoundParameters + Az.ServiceBus.private\New-AzServiceBusPrivateEndpointConnection_CreateViaIdentity -InputObject $connection -Parameter $connection @targetParameters } } catch{ diff --git a/src/ServiceBus/ServiceBus.Autorest/custom/Deny-AzServiceBusPrivateEndpointConnection.ps1 b/src/ServiceBus/ServiceBus.Autorest/custom/Deny-AzServiceBusPrivateEndpointConnection.ps1 index 5185cfd5a66b..dbef3e27adf8 100644 --- a/src/ServiceBus/ServiceBus.Autorest/custom/Deny-AzServiceBusPrivateEndpointConnection.ps1 +++ b/src/ServiceBus/ServiceBus.Autorest/custom/Deny-AzServiceBusPrivateEndpointConnection.ps1 @@ -135,13 +135,14 @@ function Deny-AzServiceBusPrivateEndpointConnection{ } process{ try{ - $hasDescription = $PSBoundParameters.Remove('Description') - $hasAsJob = $PSBoundParameters.Remove('AsJob') - $null = $PSBoundParameters.Remove('WhatIf') - $null = $PSBoundParameters.Remove('Confirm') - - $connection = Get-AzServiceBusPrivateEndpointConnection @PSBoundParameters - + $targetParameters = @{} + $PSBoundParameters + $hasDescription = $targetParameters.Remove('Description') + $hasAsJob = $targetParameters.Remove('AsJob') + $null = $targetParameters.Remove('WhatIf') + $null = $targetParameters.Remove('Confirm') + + $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusPrivateEndpointConnection' -BoundParameters $targetParameters + $connection = Get-AzServiceBusPrivateEndpointConnection @readParameters $connection.ConnectionState = "Rejected" if($hasDescription){ @@ -152,14 +153,14 @@ function Deny-AzServiceBusPrivateEndpointConnection{ } # 2. PUT - $null = $PSBoundParameters.Remove('InputObject') - $null = $PSBoundParameters.Remove('ResourceGroupName') - $null = $PSBoundParameters.Remove('NamespaceName') - $null = $PSBoundParameters.Remove('Name') - $null = $PSBoundParameters.Remove('SubscriptionId') + $null = $targetParameters.Remove('InputObject') + $null = $targetParameters.Remove('ResourceGroupName') + $null = $targetParameters.Remove('NamespaceName') + $null = $targetParameters.Remove('Name') + $null = $targetParameters.Remove('SubscriptionId') if ($PSCmdlet.ShouldProcess("Approve ServiceBus Namespace PrivateEndpoint Connection $($Name)", "Create or update")) { - Az.ServiceBus.private\New-AzServiceBusPrivateEndpointConnection_CreateViaIdentity -InputObject $connection -Parameter $connection @PSBoundParameters + Az.ServiceBus.private\New-AzServiceBusPrivateEndpointConnection_CreateViaIdentity -InputObject $connection -Parameter $connection @targetParameters } } catch{ diff --git a/src/ServiceBus/ServiceBus.Autorest/custom/Get-AzServiceBusReadParameters.ps1 b/src/ServiceBus/ServiceBus.Autorest/custom/Get-AzServiceBusReadParameters.ps1 new file mode 100644 index 000000000000..c20e1b408096 --- /dev/null +++ b/src/ServiceBus/ServiceBus.Autorest/custom/Get-AzServiceBusReadParameters.ps1 @@ -0,0 +1,30 @@ +function Get-AzServiceBusReadParameters { + [Microsoft.Azure.PowerShell.Cmdlets.ServiceBus.DoNotExportAttribute()] + [CmdletBinding()] + param( + [Parameter(Mandatory)] + [System.String] + ${CommandName}, + + [Parameter(Mandatory)] + [System.Collections.IDictionary] + ${BoundParameters} + ) + + $command = @(Get-Command -Name $CommandName -ErrorAction Stop)[0] + while ($command.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { + $command = Get-Command -Name $command.ResolvedCommandName -ErrorAction Stop + } + + $parameterNames = @($command.Parameters.Keys) + $parameterNames += @($command.Parameters.Values | ForEach-Object { $_.Aliases }) + + $readParameters = @{} + foreach ($parameter in $BoundParameters.GetEnumerator()) { + if ($parameter.Key -in $parameterNames) { + $readParameters[$parameter.Key] = $parameter.Value + } + } + + return $readParameters +} diff --git a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusAuthorizationRule.ps1 b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusAuthorizationRule.ps1 index e1ac93e4b549..b193cabf661d 100644 --- a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusAuthorizationRule.ps1 +++ b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusAuthorizationRule.ps1 @@ -82,7 +82,7 @@ function Set-AzServiceBusAuthorizationRule{ [System.String[]] # The rights associated with the rule. ${Rights}, - + [Parameter(HelpMessage = "The credentials, account, tenant, and subscription used for communication with Azure.")] [Alias('AzureRMContext', 'AzureCredential')] [ValidateNotNull()] @@ -155,29 +155,33 @@ function Set-AzServiceBusAuthorizationRule{ } process{ try{ - $hasRights = $PSBoundParameters.Remove('Rights') - $hasAsJob = $PSBoundParameters.Remove('AsJob') - $null = $PSBoundParameters.Remove('WhatIf') - $null = $PSBoundParameters.Remove('Confirm') + $targetParameters = @{} + $PSBoundParameters + $hasRights = $targetParameters.Remove('Rights') + $hasAsJob = $targetParameters.Remove('AsJob') + $null = $targetParameters.Remove('WhatIf') + $null = $targetParameters.Remove('Confirm') if ($PSCmdlet.ParameterSetName -eq 'SetExpandedQueue'){ - $authRule = Az.ServiceBus.private\Get-AzServiceBusQueueAuthorizationRule_Get @PSBoundParameters + $readParameters = Get-AzServiceBusReadParameters -CommandName 'Az.ServiceBus.private\Get-AzServiceBusQueueAuthorizationRule_Get' -BoundParameters $targetParameters + $authRule = Az.ServiceBus.private\Get-AzServiceBusQueueAuthorizationRule_Get @readParameters } elseif ($PSCmdlet.ParameterSetName -eq 'SetExpandedTopic'){ - $authRule = Az.ServiceBus.private\Get-AzServiceBusTopicAuthorizationRule_Get @PSBoundParameters + $readParameters = Get-AzServiceBusReadParameters -CommandName 'Az.ServiceBus.private\Get-AzServiceBusTopicAuthorizationRule_Get' -BoundParameters $targetParameters + $authRule = Az.ServiceBus.private\Get-AzServiceBusTopicAuthorizationRule_Get @readParameters } elseif ($PSCmdlet.ParameterSetName -eq 'SetExpandedNamespace'){ - $authRule = Az.ServiceBus.private\Get-AzServiceBusNamespaceAuthorizationRule_Get @PSBoundParameters + $readParameters = Get-AzServiceBusReadParameters -CommandName 'Az.ServiceBus.private\Get-AzServiceBusNamespaceAuthorizationRule_Get' -BoundParameters $targetParameters + $authRule = Az.ServiceBus.private\Get-AzServiceBusNamespaceAuthorizationRule_Get @readParameters } if ($hasAsJob) { - $PSBoundParameters.Add('AsJob', $true) + $targetParameters.Add('AsJob', $true) } elseif ($PSCmdlet.ParameterSetName -eq 'SetViaIdentityExpanded'){ - + if($InputObject.Id -ne $null){ $ResourceHashTable = ParseResourceId -ResourceId $InputObject.Id } @@ -186,71 +190,74 @@ function Set-AzServiceBusAuthorizationRule{ } if ($ResourceHashTable['QueueName'] -ne $null){ - $authRule = Az.ServiceBus.private\Get-AzServiceBusQueueAuthorizationRule_GetViaIdentity @PSBoundParameters + $readParameters = Get-AzServiceBusReadParameters -CommandName 'Az.ServiceBus.private\Get-AzServiceBusQueueAuthorizationRule_GetViaIdentity' -BoundParameters $targetParameters + $authRule = Az.ServiceBus.private\Get-AzServiceBusQueueAuthorizationRule_GetViaIdentity @readParameters } elseif ($ResourceHashTable['TopicName'] -ne $null){ - $authRule = Az.ServiceBus.private\Get-AzServiceBusTopicAuthorizationRule_GetViaIdentity @PSBoundParameters + $readParameters = Get-AzServiceBusReadParameters -CommandName 'Az.ServiceBus.private\Get-AzServiceBusTopicAuthorizationRule_GetViaIdentity' -BoundParameters $targetParameters + $authRule = Az.ServiceBus.private\Get-AzServiceBusTopicAuthorizationRule_GetViaIdentity @readParameters } elseif ($ResourceHashTable['NamespaceName'] -ne $null){ - $authRule = Az.ServiceBus.private\Get-AzServiceBusNamespaceAuthorizationRule_GetViaIdentity @PSBoundParameters + $readParameters = Get-AzServiceBusReadParameters -CommandName 'Az.ServiceBus.private\Get-AzServiceBusNamespaceAuthorizationRule_GetViaIdentity' -BoundParameters $targetParameters + $authRule = Az.ServiceBus.private\Get-AzServiceBusNamespaceAuthorizationRule_GetViaIdentity @readParameters } else{ throw 'Invalid -InputObject. Please Check ResourceId' } } - + # 2. PUT - $null = $PSBoundParameters.Remove('InputObject') - $null = $PSBoundParameters.Remove('ResourceGroupName') - $null = $PSBoundParameters.Remove('NamespaceName') - $null = $PSBoundParameters.Remove('QueueName') - $null = $PSBoundParameters.Remove('TopicName') - $null = $PSBoundParameters.Remove('Name') - $null = $PSBoundParameters.Remove('SubscriptionId') + $null = $targetParameters.Remove('InputObject') + $null = $targetParameters.Remove('ResourceGroupName') + $null = $targetParameters.Remove('NamespaceName') + $null = $targetParameters.Remove('QueueName') + $null = $targetParameters.Remove('TopicName') + $null = $targetParameters.Remove('Name') + $null = $targetParameters.Remove('SubscriptionId') if ($hasRights) { $authRule.Rights = $Rights } if ($hasAsJob) { - $PSBoundParameters.Add('AsJob', $true) + $targetParameters.Add('AsJob', $true) } if ($PSCmdlet.ParameterSetName -eq 'SetExpandedNamespace'){ if ($PSCmdlet.ShouldProcess("ServiceBus Namespace Authorization Rule $($authRule.Name)", "Create or update")) { - Az.ServiceBus.private\New-AzServiceBusNamespaceAuthorizationRule_CreateViaIdentity -InputObject $authRule -Parameter $authRule @PSBoundParameters + Az.ServiceBus.private\New-AzServiceBusNamespaceAuthorizationRule_CreateViaIdentity -InputObject $authRule -Parameter $authRule @targetParameters } } elseif ($PSCmdlet.ParameterSetName -eq 'SetExpandedQueue'){ if ($PSCmdlet.ShouldProcess("ServiceBus Queue Authorization Rule $($authRule.Name)", "Create or update")) { - Az.ServiceBus.private\New-AzServiceBusQueueAuthorizationRule_CreateViaIdentity -InputObject $authRule -Parameter $authRule @PSBoundParameters + Az.ServiceBus.private\New-AzServiceBusQueueAuthorizationRule_CreateViaIdentity -InputObject $authRule -Parameter $authRule @targetParameters } } elseif ($PSCmdlet.ParameterSetName -eq 'SetExpandedTopic'){ if ($PSCmdlet.ShouldProcess("ServiceBus Topic Authorization Rule $($authRule.Name)", "Create or update")) { - Az.ServiceBus.private\New-AzServiceBusTopicAuthorizationRule_CreateViaIdentity -InputObject $authRule -Parameter $authRule @PSBoundParameters + Az.ServiceBus.private\New-AzServiceBusTopicAuthorizationRule_CreateViaIdentity -InputObject $authRule -Parameter $authRule @targetParameters } } elseif ($PSCmdlet.ParameterSetName -eq 'SetViaIdentityExpanded'){ - + if ($ResourceHashTable['QueueName'] -ne $null){ if ($PSCmdlet.ShouldProcess("ServiceBus Queue Authorization Rule $($ResourceHashTable['AuthorizationRuleName'])", "Create or update")) { - Az.ServiceBus.private\New-AzServiceBusQueueAuthorizationRule_CreateViaIdentity -InputObject $authRule -Parameter $authRule @PSBoundParameters + Az.ServiceBus.private\New-AzServiceBusQueueAuthorizationRule_CreateViaIdentity -InputObject $authRule -Parameter $authRule @targetParameters } } elseif ($ResourceHashTable['TopicName'] -ne $null){ if ($PSCmdlet.ShouldProcess("ServiceBus Topic Authorization Rule $($ResourceHashTable['AuthorizationRuleName'])", "Create or update")) { - Az.ServiceBus.private\New-AzServiceBusTopicAuthorizationRule_CreateViaIdentity -InputObject $authRule -Parameter $authRule @PSBoundParameters + Az.ServiceBus.private\New-AzServiceBusTopicAuthorizationRule_CreateViaIdentity -InputObject $authRule -Parameter $authRule @targetParameters } } elseif ($ResourceHashTable['NamespaceName'] -ne $null){ if ($PSCmdlet.ShouldProcess("ServiceBus Namespace Authorization Rule $($ResourceHashTable['AuthorizationRuleName'])", "Create or update")) { - Az.ServiceBus.private\New-AzServiceBusNamespaceAuthorizationRule_CreateViaIdentity -InputObject $authRule -Parameter $authRule @PSBoundParameters + Az.ServiceBus.private\New-AzServiceBusNamespaceAuthorizationRule_CreateViaIdentity -InputObject $authRule -Parameter $authRule @targetParameters } } diff --git a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusGeoDRConfigurationBreakPair.ps1 b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusGeoDRConfigurationBreakPair.ps1 index 1ad47e981f25..892092d96bd0 100644 --- a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusGeoDRConfigurationBreakPair.ps1 +++ b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusGeoDRConfigurationBreakPair.ps1 @@ -55,7 +55,7 @@ function Set-AzServiceBusGeoDRConfigurationBreakPair{ # Identity Parameter # To construct, see NOTES section for INPUTOBJECT properties and create a hash table. ${InputObject}, - + [Parameter(HelpMessage = "The credentials, account, tenant, and subscription used for communication with Azure.")] [Alias('AzureRMContext', 'AzureCredential')] [ValidateNotNull()] @@ -128,43 +128,44 @@ function Set-AzServiceBusGeoDRConfigurationBreakPair{ } process{ try{ - $hasAsJob = $PSBoundParameters.Remove('AsJob') - $null = $PSBoundParameters.Remove('WhatIf') - $null = $PSBoundParameters.Remove('Confirm') - - $drConfig = Get-AzServiceBusGeoDRConfiguration @PSBoundParameters + $targetParameters = @{} + $PSBoundParameters + $hasAsJob = $targetParameters.Remove('AsJob') + $null = $targetParameters.Remove('WhatIf') + $null = $targetParameters.Remove('Confirm') + $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusGeoDRConfiguration' -BoundParameters $targetParameters + $drConfig = Get-AzServiceBusGeoDRConfiguration @readParameters # 2. PUT - $null = $PSBoundParameters.Remove('InputObject') + $null = $targetParameters.Remove('InputObject') if ($hasAsJob) { - $PSBoundParameters.Add('AsJob', $true) + $targetParameters.Add('AsJob', $true) } if($PSCmdlet.ParameterSetName -eq 'Break'){ if ($PSCmdlet.ShouldProcess("ServiceBus Disaster Recovery Alias $($Name)", "Break Pair")) { - Az.ServiceBus.private\Invoke-AzServiceBusBreakDisasterRecoveryConfigPairing_Break @PSBoundParameters + Az.ServiceBus.private\Invoke-AzServiceBusBreakDisasterRecoveryConfigPairing_Break @targetParameters } } elseif($PSCmdlet.ParameterSetName -eq 'BreakViaIdentity'){ $EnvPSBoundParameters = @{} - if ($PSBoundParameters.ContainsKey('Debug')) { + if ($targetParameters.ContainsKey('Debug')) { $EnvPSBoundParameters['Debug'] = $Debug } - if ($PSBoundParameters.ContainsKey('HttpPipelineAppend')) { + if ($targetParameters.ContainsKey('HttpPipelineAppend')) { $EnvPSBoundParameters['HttpPipelineAppend'] = $HttpPipelineAppend } - if ($PSBoundParameters.ContainsKey('HttpPipelinePrepend')) { + if ($targetParameters.ContainsKey('HttpPipelinePrepend')) { $EnvPSBoundParameters['HttpPipelinePrepend'] = $HttpPipelinePrepend } - if ($PSBoundParameters.ContainsKey('Proxy')) { + if ($targetParameters.ContainsKey('Proxy')) { $EnvPSBoundParameters['Proxy'] = $Proxy } - if ($PSBoundParameters.ContainsKey('ProxyCredential')) { + if ($targetParameters.ContainsKey('ProxyCredential')) { $EnvPSBoundParameters['ProxyCredential'] = $ProxyCredential } - if ($PSBoundParameters.ContainsKey('ProxyUseDefaultCredentials')) { + if ($targetParameters.ContainsKey('ProxyUseDefaultCredentials')) { $EnvPSBoundParameters['ProxyUseDefaultCredentials'] = $ProxyUseDefaultCredentials } diff --git a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusGeoDRConfigurationFailOver.ps1 b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusGeoDRConfigurationFailOver.ps1 index d2fff87db5ea..50cc77b0bef6 100644 --- a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusGeoDRConfigurationFailOver.ps1 +++ b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusGeoDRConfigurationFailOver.ps1 @@ -55,7 +55,7 @@ function Set-AzServiceBusGeoDRConfigurationFailOver{ # Identity Parameter # To construct, see NOTES section for INPUTOBJECT properties and create a hash table. ${InputObject}, - + [Parameter(HelpMessage = "The credentials, account, tenant, and subscription used for communication with Azure.")] [Alias('AzureRMContext', 'AzureCredential')] [ValidateNotNull()] @@ -128,43 +128,44 @@ function Set-AzServiceBusGeoDRConfigurationFailOver{ } process{ try{ - $hasAsJob = $PSBoundParameters.Remove('AsJob') - $null = $PSBoundParameters.Remove('WhatIf') - $null = $PSBoundParameters.Remove('Confirm') - - $drConfig = Get-AzServiceBusGeoDRConfiguration @PSBoundParameters + $targetParameters = @{} + $PSBoundParameters + $hasAsJob = $targetParameters.Remove('AsJob') + $null = $targetParameters.Remove('WhatIf') + $null = $targetParameters.Remove('Confirm') + $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusGeoDRConfiguration' -BoundParameters $targetParameters + $drConfig = Get-AzServiceBusGeoDRConfiguration @readParameters # 2. PUT - $null = $PSBoundParameters.Remove('InputObject') + $null = $targetParameters.Remove('InputObject') if ($hasAsJob) { - $PSBoundParameters.Add('AsJob', $true) + $targetParameters.Add('AsJob', $true) } if($PSCmdlet.ParameterSetName -eq 'Fail'){ if ($PSCmdlet.ShouldProcess("ServiceBus Disaster Recovery Alias $($Name)", "Fail Over")) { - Az.ServiceBus.private\Invoke-AzServiceBusFailDisasterRecoveryConfigOver_FailExpanded @PSBoundParameters + Az.ServiceBus.private\Invoke-AzServiceBusFailDisasterRecoveryConfigOver_FailExpanded @targetParameters } } elseif($PSCmdlet.ParameterSetName -eq 'FailViaIdentity'){ $EnvPSBoundParameters = @{} - if ($PSBoundParameters.ContainsKey('Debug')) { + if ($targetParameters.ContainsKey('Debug')) { $EnvPSBoundParameters['Debug'] = $Debug } - if ($PSBoundParameters.ContainsKey('HttpPipelineAppend')) { + if ($targetParameters.ContainsKey('HttpPipelineAppend')) { $EnvPSBoundParameters['HttpPipelineAppend'] = $HttpPipelineAppend } - if ($PSBoundParameters.ContainsKey('HttpPipelinePrepend')) { + if ($targetParameters.ContainsKey('HttpPipelinePrepend')) { $EnvPSBoundParameters['HttpPipelinePrepend'] = $HttpPipelinePrepend } - if ($PSBoundParameters.ContainsKey('Proxy')) { + if ($targetParameters.ContainsKey('Proxy')) { $EnvPSBoundParameters['Proxy'] = $Proxy } - if ($PSBoundParameters.ContainsKey('ProxyCredential')) { + if ($targetParameters.ContainsKey('ProxyCredential')) { $EnvPSBoundParameters['ProxyCredential'] = $ProxyCredential } - if ($PSBoundParameters.ContainsKey('ProxyUseDefaultCredentials')) { + if ($targetParameters.ContainsKey('ProxyUseDefaultCredentials')) { $EnvPSBoundParameters['ProxyUseDefaultCredentials'] = $ProxyUseDefaultCredentials } diff --git a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusNamespace.ps1 b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusNamespace.ps1 index 099a480c5413..e290bb0f6368 100644 --- a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusNamespace.ps1 +++ b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusNamespace.ps1 @@ -52,12 +52,12 @@ function Set-AzServiceBusNamespace{ [Microsoft.Azure.PowerShell.Cmdlets.ServiceBus.Category('Body')] [System.String] ${AlternateName}, - + [Parameter(HelpMessage = "This property disables SAS authentication for the Service Bus namespace.")] [Microsoft.Azure.PowerShell.Cmdlets.ServiceBus.Category('Body')] [System.Management.Automation.SwitchParameter] ${DisableLocalAuth}, - + [Parameter(HelpMessage = "Properties of KeyVault")] [Microsoft.Azure.PowerShell.Cmdlets.ServiceBus.Category('Body')] [Microsoft.Azure.PowerShell.Cmdlets.ServiceBus.Models.IKeyVaultProperties[]] @@ -193,32 +193,33 @@ function Set-AzServiceBusNamespace{ } process{ try{ - $hasAlternateName = $PSBoundParameters.Remove('AlternateName') - $hasDisableLocalAuth = $PSBoundParameters.Remove('DisableLocalAuth') - $hasKeyVaultProperty = $PSBoundParameters.Remove('KeyVaultProperty') - $hasUserAssignedIdentityId = $PSBoundParameters.Remove('UserAssignedIdentityId') - $hasIdentityType = $PSBoundParameters.Remove('IdentityType') - $hasMinimumTlsVersion = $PSBoundParameters.Remove('MinimumTlsVersion') - $hasRequireInfrastructureEncryption = $PSBoundParameters.Remove('RequireInfrastructureEncryption') - $hasPublicNetworkAccess = $PSBoundParameters.Remove('PublicNetworkAccess') - $hasSkuCapacity = $PSBoundParameters.Remove('SkuCapacity') - $hasTag = $PSBoundParameters.Remove('Tag') - $hasGeoDataReplicationMaxReplicationLagDurationInSecond = $PSBoundParameters.Remove('GeoDataReplicationMaxReplicationLagDurationInSecond') - $hasGeoDataReplicationLocation = $PSBoundParameters.Remove('GeoDataReplicationLocation') - $hasIPAddressType = $PSBoundParameters.Remove('IPAddressType') - $hasDefaultProfile = $PSBoundParameters.Remove('DefaultProfile') - $hasAsJob = $PSBoundParameters.Remove('AsJob') - $hasNoWait = $PSBoundParameters.Remove('NoWait') - $null = $PSBoundParameters.Remove('WhatIf') - $null = $PSBoundParameters.Remove('Confirm') - $serviceBusNamespace = Get-AzServiceBusNamespace @PSBoundParameters - + $targetParameters = @{} + $PSBoundParameters + $hasAlternateName = $targetParameters.Remove('AlternateName') + $hasDisableLocalAuth = $targetParameters.Remove('DisableLocalAuth') + $hasKeyVaultProperty = $targetParameters.Remove('KeyVaultProperty') + $hasUserAssignedIdentityId = $targetParameters.Remove('UserAssignedIdentityId') + $hasIdentityType = $targetParameters.Remove('IdentityType') + $hasMinimumTlsVersion = $targetParameters.Remove('MinimumTlsVersion') + $hasRequireInfrastructureEncryption = $targetParameters.Remove('RequireInfrastructureEncryption') + $hasPublicNetworkAccess = $targetParameters.Remove('PublicNetworkAccess') + $hasSkuCapacity = $targetParameters.Remove('SkuCapacity') + $hasTag = $targetParameters.Remove('Tag') + $hasGeoDataReplicationMaxReplicationLagDurationInSecond = $targetParameters.Remove('GeoDataReplicationMaxReplicationLagDurationInSecond') + $hasGeoDataReplicationLocation = $targetParameters.Remove('GeoDataReplicationLocation') + $hasIPAddressType = $targetParameters.Remove('IPAddressType') + $hasDefaultProfile = $targetParameters.Remove('DefaultProfile') + $hasAsJob = $targetParameters.Remove('AsJob') + $hasNoWait = $targetParameters.Remove('NoWait') + $null = $targetParameters.Remove('WhatIf') + $null = $targetParameters.Remove('Confirm') + $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusNamespace' -BoundParameters $targetParameters + $serviceBusNamespace = Get-AzServiceBusNamespace @readParameters # 2. PUT - $null = $PSBoundParameters.Remove('InputObject') - $null = $PSBoundParameters.Remove('ResourceGroupName') - $null = $PSBoundParameters.Remove('NamespaceName') - $null = $PSBoundParameters.Remove('Name') - $null = $PSBoundParameters.Remove('SubscriptionId') + $null = $targetParameters.Remove('InputObject') + $null = $targetParameters.Remove('ResourceGroupName') + $null = $targetParameters.Remove('NamespaceName') + $null = $targetParameters.Remove('Name') + $null = $targetParameters.Remove('SubscriptionId') if ($hasAlternateName) { $serviceBusNamespace.AlternateName = $AlternateName @@ -238,11 +239,11 @@ function Set-AzServiceBusNamespace{ } if ($hasUserAssignedIdentityId) { $identityHashTable = @{} - + foreach ($resourceID in $UserAssignedIdentityId){ $identityHashTable.Add($resourceID, [Microsoft.Azure.PowerShell.Cmdlets.ServiceBus.Models.UserAssignedIdentity]::new()) } - + $serviceBusNamespace.UserAssignedIdentity = $identityHashTable } if ($hasMinimumTlsVersion) { @@ -267,15 +268,15 @@ function Set-AzServiceBusNamespace{ $serviceBusNamespace.IPAddressType = $IPAddressType } if ($hasAsJob) { - $PSBoundParameters.Add('AsJob', $true) + $targetParameters.Add('AsJob', $true) } if ($hasNoWait) { - $PSBoundParameters.Add('NoWait', $true) + $targetParameters.Add('NoWait', $true) } if ($PSCmdlet.ShouldProcess("ServiceBusNamespace $($serviceBusNamespace.Name)", "Create or update")) { - Az.ServiceBus.private\New-AzServiceBusNamespace_CreateViaIdentity -InputObject $serviceBusNamespace -Parameter $serviceBusNamespace @PSBoundParameters + Az.ServiceBus.private\New-AzServiceBusNamespace_CreateViaIdentity -InputObject $serviceBusNamespace -Parameter $serviceBusNamespace @targetParameters } } catch{ diff --git a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusNetworkRuleSet.ps1 b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusNetworkRuleSet.ps1 index d6149a80ee4b..5b115f1cec04 100644 --- a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusNetworkRuleSet.ps1 +++ b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusNetworkRuleSet.ps1 @@ -53,7 +53,7 @@ function Set-AzServiceBusNetworkRuleSet{ [Parameter(HelpMessage = "This determines if traffic is allowed over public network. By default it is enabled. If value is SecuredByPerimeter then Inbound and Outbound communication is controlled by the network security perimeter and profile's access rules. ")] [Microsoft.Azure.PowerShell.Cmdlets.ServiceBus.Category('Body')] [System.String] - # This determines if traffic is allowed over public network. By default it is enabled. If value is SecuredByPerimeter then Inbound and Outbound communication is controlled by the network security perimeter and profile's access rules. + # This determines if traffic is allowed over public network. By default it is enabled. If value is SecuredByPerimeter then Inbound and Outbound communication is controlled by the network security perimeter and profile's access rules. ${PublicNetworkAccess}, [Parameter(HelpMessage = "Value that indicates whether Trusted Service Access is Enabled or not.")] @@ -152,22 +152,23 @@ function Set-AzServiceBusNetworkRuleSet{ } process{ try{ - $hasPublicNetworkAccess = $PSBoundParameters.Remove('PublicNetworkAccess') - $hasTrustedServiceAccessEnabled = $PSBoundParameters.Remove('TrustedServiceAccessEnabled') - $hasDefaultAction = $PSBoundParameters.Remove('DefaultAction') - $hasIPRule = $PSBoundParameters.Remove('IPRule') - $hasVirtualNetworkRule = $PSBoundParameters.Remove('VirtualNetworkRule') - $hasAsJob = $PSBoundParameters.Remove('AsJob') - $null = $PSBoundParameters.Remove('WhatIf') - $null = $PSBoundParameters.Remove('Confirm') - - $networkRuleSet = Get-AzServiceBusNetworkRuleSet @PSBoundParameters - + $targetParameters = @{} + $PSBoundParameters + $hasPublicNetworkAccess = $targetParameters.Remove('PublicNetworkAccess') + $hasTrustedServiceAccessEnabled = $targetParameters.Remove('TrustedServiceAccessEnabled') + $hasDefaultAction = $targetParameters.Remove('DefaultAction') + $hasIPRule = $targetParameters.Remove('IPRule') + $hasVirtualNetworkRule = $targetParameters.Remove('VirtualNetworkRule') + $hasAsJob = $targetParameters.Remove('AsJob') + $null = $targetParameters.Remove('WhatIf') + $null = $targetParameters.Remove('Confirm') + + $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusNetworkRuleSet' -BoundParameters $targetParameters + $networkRuleSet = Get-AzServiceBusNetworkRuleSet @readParameters # 2. PUT - $null = $PSBoundParameters.Remove('InputObject') - $null = $PSBoundParameters.Remove('ResourceGroupName') - $null = $PSBoundParameters.Remove('NamespaceName') - $null = $PSBoundParameters.Remove('SubscriptionId') + $null = $targetParameters.Remove('InputObject') + $null = $targetParameters.Remove('ResourceGroupName') + $null = $targetParameters.Remove('NamespaceName') + $null = $targetParameters.Remove('SubscriptionId') $hasProperty = $false @@ -197,11 +198,11 @@ function Set-AzServiceBusNetworkRuleSet{ } if ($hasAsJob) { - $PSBoundParameters.Add('AsJob', $true) + $targetParameters.Add('AsJob', $true) } if ($PSCmdlet.ShouldProcess("ServiceBus Network Rule Set on namespace $($networkRuleSet.Name)", "Create or update")) { - Az.ServiceBus.private\New-AzServiceBusNetworkRuleSet_CreateViaIdentity -InputObject $networkRuleSet -Parameter $networkRuleSet @PSBoundParameters + Az.ServiceBus.private\New-AzServiceBusNetworkRuleSet_CreateViaIdentity -InputObject $networkRuleSet -Parameter $networkRuleSet @targetParameters } } catch{ diff --git a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusQueue.ps1 b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusQueue.ps1 index 5f272f40c85b..69de7d9fd02c 100644 --- a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusQueue.ps1 +++ b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusQueue.ps1 @@ -134,7 +134,7 @@ function Set-AzServiceBusQueue{ [System.String] ${Status}, - + [Parameter(HelpMessage = "The credentials, account, tenant, and subscription used for communication with Azure.")] [Alias('AzureRMContext', 'AzureCredential')] [ValidateNotNull()] @@ -213,31 +213,32 @@ function Set-AzServiceBusQueue{ process{ try{ - $hasAutoDeleteOnIdle = $PSBoundParameters.Remove('AutoDeleteOnIdle') - $hasDefaultMessageTimeToLive = $PSBoundParameters.Remove('DefaultMessageTimeToLive') - $hasDeadLetteringOnMessageExpiration = $PSBoundParameters.Remove('DeadLetteringOnMessageExpiration') - $hasDuplicateDetectionHistoryTimeWindow = $PSBoundParameters.Remove('DuplicateDetectionHistoryTimeWindow') - $hasLockDuration = $PSBoundParameters.Remove('LockDuration') - $hasEnableBatchedOperations = $PSBoundParameters.Remove('EnableBatchedOperations') - $hasEnableExpress = $PSBoundParameters.Remove('EnableExpress') - $hasForwardDeadLetteredMessagesTo = $PSBoundParameters.Remove('ForwardDeadLetteredMessagesTo') - $hasForwardTo = $PSBoundParameters.Remove('ForwardTo') - $hasMaxDeliveryCount = $PSBoundParameters.Remove('MaxDeliveryCount') - $hasMaxMessageSizeInKilobytes = $PSBoundParameters.Remove('MaxMessageSizeInKilobytes') - $hasMaxSizeInMegabytes = $PSBoundParameters.Remove('MaxSizeInMegabytes') - $hasStatus = $PSBoundParameters.Remove('Status') - $hasAsJob = $PSBoundParameters.Remove('AsJob') - $null = $PSBoundParameters.Remove('WhatIf') - $null = $PSBoundParameters.Remove('Confirm') - - $queue = Get-AzServiceBusQueue @PSBoundParameters - + $targetParameters = @{} + $PSBoundParameters + $hasAutoDeleteOnIdle = $targetParameters.Remove('AutoDeleteOnIdle') + $hasDefaultMessageTimeToLive = $targetParameters.Remove('DefaultMessageTimeToLive') + $hasDeadLetteringOnMessageExpiration = $targetParameters.Remove('DeadLetteringOnMessageExpiration') + $hasDuplicateDetectionHistoryTimeWindow = $targetParameters.Remove('DuplicateDetectionHistoryTimeWindow') + $hasLockDuration = $targetParameters.Remove('LockDuration') + $hasEnableBatchedOperations = $targetParameters.Remove('EnableBatchedOperations') + $hasEnableExpress = $targetParameters.Remove('EnableExpress') + $hasForwardDeadLetteredMessagesTo = $targetParameters.Remove('ForwardDeadLetteredMessagesTo') + $hasForwardTo = $targetParameters.Remove('ForwardTo') + $hasMaxDeliveryCount = $targetParameters.Remove('MaxDeliveryCount') + $hasMaxMessageSizeInKilobytes = $targetParameters.Remove('MaxMessageSizeInKilobytes') + $hasMaxSizeInMegabytes = $targetParameters.Remove('MaxSizeInMegabytes') + $hasStatus = $targetParameters.Remove('Status') + $hasAsJob = $targetParameters.Remove('AsJob') + $null = $targetParameters.Remove('WhatIf') + $null = $targetParameters.Remove('Confirm') + + $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusQueue' -BoundParameters $targetParameters + $queue = Get-AzServiceBusQueue @readParameters # 2. PUT - $null = $PSBoundParameters.Remove('InputObject') - $null = $PSBoundParameters.Remove('ResourceGroupName') - $null = $PSBoundParameters.Remove('NamespaceName') - $null = $PSBoundParameters.Remove('Name') - $null = $PSBoundParameters.Remove('SubscriptionId') + $null = $targetParameters.Remove('InputObject') + $null = $targetParameters.Remove('ResourceGroupName') + $null = $targetParameters.Remove('NamespaceName') + $null = $targetParameters.Remove('Name') + $null = $targetParameters.Remove('SubscriptionId') $hasProperty = $false @@ -299,11 +300,11 @@ function Set-AzServiceBusQueue{ } if ($hasAsJob) { - $PSBoundParameters.Add('AsJob', $true) + $targetParameters.Add('AsJob', $true) } if ($PSCmdlet.ShouldProcess("ServiceBus Queue $($queue.Name)", "Create or update")) { - Az.ServiceBus.private\New-AzServiceBusQueue_CreateViaIdentity -InputObject $queue -Parameter $queue @PSBoundParameters + Az.ServiceBus.private\New-AzServiceBusQueue_CreateViaIdentity -InputObject $queue -Parameter $queue @targetParameters } } catch{ diff --git a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusRule.ps1 b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusRule.ps1 index c49359ddcc31..d293c2132d22 100644 --- a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusRule.ps1 +++ b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusRule.ps1 @@ -150,7 +150,7 @@ function Set-AzServiceBusRule{ [Parameter(HelpMessage = "Value that indicates whether the rule action requires preprocessing.")] [Microsoft.Azure.PowerShell.Cmdlets.ServiceBus.Category('Body')] [System.Management.Automation.SwitchParameter] - # Value that indicates whether the rule action requires preprocessing. + # Value that indicates whether the rule action requires preprocessing. ${ActionRequiresPreprocessing}, [Parameter(HelpMessage = "SQL expression. e.g. MyProperty='ABC'")] @@ -231,32 +231,33 @@ function Set-AzServiceBusRule{ } process{ try{ - $hasSqlExpression = $PSBoundParameters.Remove('SqlExpression') - $hasSqlFilterRequiresPreprocessing = $PSBoundParameters.Remove('SqlFilterRequiresPreprocessing') - $hasContentType = $PSBoundParameters.Remove('ContentType') - $hasCorrelationId = $PSBoundParameters.Remove('CorrelationId') - $hasLabel = $PSBoundParameters.Remove('Label') - $hasMessageId = $PSBoundParameters.Remove('MessageId') - $hasCorrelationFilterProperty = $PSBoundParameters.Remove('CorrelationFilterProperty') - $hasReplyTo = $PSBoundParameters.Remove('ReplyTo') - $hasReplyToSessionId = $PSBoundParameters.Remove('ReplyToSessionId') - $hasCorrelationFilterRequiresPreprocessing = $PSBoundParameters.Remove('CorrelationFilterRequiresPreprocessing') - $hasSessionId = $PSBoundParameters.Remove('SessionId') - $hasTo = $PSBoundParameters.Remove('To') - $hasFilterType = $PSBoundParameters.Remove('FilterType') - $hasActionSqlExpression = $PSBoundParameters.Remove('ActionSqlExpression') - $hasActionRequiresPreprocessing = $PSBoundParameters.Remove('ActionRequiresPreprocessing') - - $rule = Get-AzServiceBusRule @PSBoundParameters - + $targetParameters = @{} + $PSBoundParameters + $hasSqlExpression = $targetParameters.Remove('SqlExpression') + $hasSqlFilterRequiresPreprocessing = $targetParameters.Remove('SqlFilterRequiresPreprocessing') + $hasContentType = $targetParameters.Remove('ContentType') + $hasCorrelationId = $targetParameters.Remove('CorrelationId') + $hasLabel = $targetParameters.Remove('Label') + $hasMessageId = $targetParameters.Remove('MessageId') + $hasCorrelationFilterProperty = $targetParameters.Remove('CorrelationFilterProperty') + $hasReplyTo = $targetParameters.Remove('ReplyTo') + $hasReplyToSessionId = $targetParameters.Remove('ReplyToSessionId') + $hasCorrelationFilterRequiresPreprocessing = $targetParameters.Remove('CorrelationFilterRequiresPreprocessing') + $hasSessionId = $targetParameters.Remove('SessionId') + $hasTo = $targetParameters.Remove('To') + $hasFilterType = $targetParameters.Remove('FilterType') + $hasActionSqlExpression = $targetParameters.Remove('ActionSqlExpression') + $hasActionRequiresPreprocessing = $targetParameters.Remove('ActionRequiresPreprocessing') + + $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusRule' -BoundParameters $targetParameters + $rule = Get-AzServiceBusRule @readParameters # 2. PUT - $null = $PSBoundParameters.Remove('InputObject') - $null = $PSBoundParameters.Remove('ResourceGroupName') - $null = $PSBoundParameters.Remove('NamespaceName') - $null = $PSBoundParameters.Remove('TopicName') - $null = $PSBoundParameters.Remove('SubscriptionName') - $null = $PSBoundParameters.Remove('Name') - $null = $PSBoundParameters.Remove('SubscriptionId') + $null = $targetParameters.Remove('InputObject') + $null = $targetParameters.Remove('ResourceGroupName') + $null = $targetParameters.Remove('NamespaceName') + $null = $targetParameters.Remove('TopicName') + $null = $targetParameters.Remove('SubscriptionName') + $null = $targetParameters.Remove('Name') + $null = $targetParameters.Remove('SubscriptionId') $hasProperty = $false @@ -326,11 +327,11 @@ function Set-AzServiceBusRule{ } if ($hasAsJob) { - $PSBoundParameters.Add('AsJob', $true) + $targetParameters.Add('AsJob', $true) } if ($PSCmdlet.ShouldProcess("ServiceBus Rule $($rule.Name)", "Create or update")) { - Az.ServiceBus.private\New-AzServiceBusRule_CreateViaIdentity -InputObject $rule -Parameter $rule @PSBoundParameters + Az.ServiceBus.private\New-AzServiceBusRule_CreateViaIdentity -InputObject $rule -Parameter $rule @targetParameters } } catch{ diff --git a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusSubscription.ps1 b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusSubscription.ps1 index 002b255c030b..0aa840643600 100644 --- a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusSubscription.ps1 +++ b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusSubscription.ps1 @@ -128,7 +128,7 @@ function Set-AzServiceBusSubscription{ [System.Management.Automation.SwitchParameter] # Value that indicates whether a subscription has dead letter support on filter evaluation exceptions. ${DeadLetteringOnMessageExpiration}, - + [Parameter(HelpMessage = "The credentials, account, tenant, and subscription used for communication with Azure.")] [Alias('AzureRMContext', 'AzureCredential')] [ValidateNotNull()] @@ -202,30 +202,31 @@ function Set-AzServiceBusSubscription{ } process{ try{ - $hasAutoDeleteOnIdle = $PSBoundParameters.Remove('AutoDeleteOnIdle') - $hasDefaultMessageTimeToLive = $PSBoundParameters.Remove('DefaultMessageTimeToLive') - $hasLockDuration = $PSBoundParameters.Remove('LockDuration') - $hasDuplicateDetectionHistoryTimeWindow = $PSBoundParameters.Remove('DuplicateDetectionHistoryTimeWindow') - $hasEnableBatchedOperations = $PSBoundParameters.Remove('EnableBatchedOperations') - $hasDeadLetteringOnFilterEvaluationException = $PSBoundParameters.Remove('DeadLetteringOnFilterEvaluationException') - $hasMaxDeliveryCount = $PSBoundParameters.Remove('MaxDeliveryCount') - $hasForwardTo = $PSBoundParameters.Remove('ForwardTo') - $hasForwardDeadLetteredMessagesTo = $PSBoundParameters.Remove('ForwardDeadLetteredMessagesTo') - $hasStatus = $PSBoundParameters.Remove('Status') - $hasDeadLetteringOnMessageExpiration = $PSBoundParameters.Remove('DeadLetteringOnMessageExpiration') - $hasAsJob = $PSBoundParameters.Remove('AsJob') - $null = $PSBoundParameters.Remove('WhatIf') - $null = $PSBoundParameters.Remove('Confirm') - - $subscription = Get-AzServiceBusSubscription @PSBoundParameters - + $targetParameters = @{} + $PSBoundParameters + $hasAutoDeleteOnIdle = $targetParameters.Remove('AutoDeleteOnIdle') + $hasDefaultMessageTimeToLive = $targetParameters.Remove('DefaultMessageTimeToLive') + $hasLockDuration = $targetParameters.Remove('LockDuration') + $hasDuplicateDetectionHistoryTimeWindow = $targetParameters.Remove('DuplicateDetectionHistoryTimeWindow') + $hasEnableBatchedOperations = $targetParameters.Remove('EnableBatchedOperations') + $hasDeadLetteringOnFilterEvaluationException = $targetParameters.Remove('DeadLetteringOnFilterEvaluationException') + $hasMaxDeliveryCount = $targetParameters.Remove('MaxDeliveryCount') + $hasForwardTo = $targetParameters.Remove('ForwardTo') + $hasForwardDeadLetteredMessagesTo = $targetParameters.Remove('ForwardDeadLetteredMessagesTo') + $hasStatus = $targetParameters.Remove('Status') + $hasDeadLetteringOnMessageExpiration = $targetParameters.Remove('DeadLetteringOnMessageExpiration') + $hasAsJob = $targetParameters.Remove('AsJob') + $null = $targetParameters.Remove('WhatIf') + $null = $targetParameters.Remove('Confirm') + + $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusSubscription' -BoundParameters $targetParameters + $subscription = Get-AzServiceBusSubscription @readParameters # 2. PUT - $null = $PSBoundParameters.Remove('InputObject') - $null = $PSBoundParameters.Remove('ResourceGroupName') - $null = $PSBoundParameters.Remove('NamespaceName') - $null = $PSBoundParameters.Remove('TopicName') - $null = $PSBoundParameters.Remove('Name') - $null = $PSBoundParameters.Remove('SubscriptionId') + $null = $targetParameters.Remove('InputObject') + $null = $targetParameters.Remove('ResourceGroupName') + $null = $targetParameters.Remove('NamespaceName') + $null = $targetParameters.Remove('TopicName') + $null = $targetParameters.Remove('Name') + $null = $targetParameters.Remove('SubscriptionId') $hasProperty = $false @@ -279,11 +280,11 @@ function Set-AzServiceBusSubscription{ } if ($hasAsJob) { - $PSBoundParameters.Add('AsJob', $true) + $targetParameters.Add('AsJob', $true) } if ($PSCmdlet.ShouldProcess("ServiceBus Subscription $($subscription.Name)", "Create or update")) { - Az.ServiceBus.private\New-AzServiceBusSubscription_CreateViaIdentity -InputObject $subscription -Parameter $subscription @PSBoundParameters + Az.ServiceBus.private\New-AzServiceBusSubscription_CreateViaIdentity -InputObject $subscription -Parameter $subscription @targetParameters } } catch{ diff --git a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusTopic.ps1 b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusTopic.ps1 index 9c55e7a90caf..69d96df36c4e 100644 --- a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusTopic.ps1 +++ b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusTopic.ps1 @@ -109,7 +109,7 @@ function Set-AzServiceBusTopic{ [Microsoft.Azure.PowerShell.Cmdlets.ServiceBus.Category('Body')] [System.String] ${Status}, - + [Parameter(HelpMessage = "The credentials, account, tenant, and subscription used for communication with Azure.")] [Alias('AzureRMContext', 'AzureCredential')] [ValidateNotNull()] @@ -188,28 +188,29 @@ function Set-AzServiceBusTopic{ process{ try{ - $hasAutoDeleteOnIdle = $PSBoundParameters.Remove('AutoDeleteOnIdle') - $hasDefaultMessageTimeToLive = $PSBoundParameters.Remove('DefaultMessageTimeToLive') - $hasDuplicateDetectionHistoryTimeWindow = $PSBoundParameters.Remove('DuplicateDetectionHistoryTimeWindow') - $hasEnableBatchedOperations = $PSBoundParameters.Remove('EnableBatchedOperations') - $hasEnableExpress = $PSBoundParameters.Remove('EnableExpress') - $hasMaxMessageSizeInKilobytes = $PSBoundParameters.Remove('MaxMessageSizeInKilobytes') - $hasMaxSizeInMegabytes = $PSBoundParameters.Remove('MaxSizeInMegabytes') - $hasRequiresDuplicateDetection = $PSBoundParameters.Remove('RequiresDuplicateDetection') - $hasSupportOrdering = $PSBoundParameters.Remove('SupportOrdering') - $hasStatus = $PSBoundParameters.Remove('Status') - $hasAsJob = $PSBoundParameters.Remove('AsJob') - $null = $PSBoundParameters.Remove('WhatIf') - $null = $PSBoundParameters.Remove('Confirm') - - $topic = Get-AzServiceBusTopic @PSBoundParameters - + $targetParameters = @{} + $PSBoundParameters + $hasAutoDeleteOnIdle = $targetParameters.Remove('AutoDeleteOnIdle') + $hasDefaultMessageTimeToLive = $targetParameters.Remove('DefaultMessageTimeToLive') + $hasDuplicateDetectionHistoryTimeWindow = $targetParameters.Remove('DuplicateDetectionHistoryTimeWindow') + $hasEnableBatchedOperations = $targetParameters.Remove('EnableBatchedOperations') + $hasEnableExpress = $targetParameters.Remove('EnableExpress') + $hasMaxMessageSizeInKilobytes = $targetParameters.Remove('MaxMessageSizeInKilobytes') + $hasMaxSizeInMegabytes = $targetParameters.Remove('MaxSizeInMegabytes') + $hasRequiresDuplicateDetection = $targetParameters.Remove('RequiresDuplicateDetection') + $hasSupportOrdering = $targetParameters.Remove('SupportOrdering') + $hasStatus = $targetParameters.Remove('Status') + $hasAsJob = $targetParameters.Remove('AsJob') + $null = $targetParameters.Remove('WhatIf') + $null = $targetParameters.Remove('Confirm') + + $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusTopic' -BoundParameters $targetParameters + $topic = Get-AzServiceBusTopic @readParameters # 2. PUT - $null = $PSBoundParameters.Remove('InputObject') - $null = $PSBoundParameters.Remove('ResourceGroupName') - $null = $PSBoundParameters.Remove('NamespaceName') - $null = $PSBoundParameters.Remove('Name') - $null = $PSBoundParameters.Remove('SubscriptionId') + $null = $targetParameters.Remove('InputObject') + $null = $targetParameters.Remove('ResourceGroupName') + $null = $targetParameters.Remove('NamespaceName') + $null = $targetParameters.Remove('Name') + $null = $targetParameters.Remove('SubscriptionId') $hasProperty = $false @@ -259,11 +260,11 @@ function Set-AzServiceBusTopic{ } if ($hasAsJob) { - $PSBoundParameters.Add('AsJob', $true) + $targetParameters.Add('AsJob', $true) } if ($PSCmdlet.ShouldProcess("ServiceBus Topic $($topic.Name)", "Create or update")) { - Az.ServiceBus.private\New-AzServiceBusTopic_CreateViaIdentity -InputObject $topic -Parameter $topic @PSBoundParameters + Az.ServiceBus.private\New-AzServiceBusTopic_CreateViaIdentity -InputObject $topic -Parameter $topic @targetParameters } } catch{ diff --git a/src/ServiceBus/ServiceBus.Autorest/generate-info.json b/src/ServiceBus/ServiceBus.Autorest/generate-info.json index 14c5740cefa9..73e72c635e25 100644 --- a/src/ServiceBus/ServiceBus.Autorest/generate-info.json +++ b/src/ServiceBus/ServiceBus.Autorest/generate-info.json @@ -1,3 +1,3 @@ { - "generate_Id": "d42664e3-3ae4-4daf-a410-fba6f9958c4e" + "generate_Id": "6f3a9805-5577-4f34-a04b-9650247850a6" } diff --git a/src/ServiceBus/ServiceBus.Autorest/test/ReadParameterForwarding.Tests.ps1 b/src/ServiceBus/ServiceBus.Autorest/test/ReadParameterForwarding.Tests.ps1 new file mode 100644 index 000000000000..d86382d6c0e7 --- /dev/null +++ b/src/ServiceBus/ServiceBus.Autorest/test/ReadParameterForwarding.Tests.ps1 @@ -0,0 +1,109 @@ +$helperPath = Join-Path $PSScriptRoot '..\custom\Get-AzServiceBusReadParameters.ps1' +$helperSource = Get-Content -Path $helperPath -Raw +$helperSource = $helperSource -replace '(?m)^\s*\[Microsoft\.Azure\.PowerShell\.Cmdlets\.ServiceBus\.DoNotExportAttribute\(\)\]\r?\n', '' +. ([scriptblock]::Create($helperSource)) + +function Get-AzServiceBusReadTestResource { + [CmdletBinding()] + param( + [Alias('ResourceName')] + [string] $Name, + [object] $DefaultProfile + ) + + $script:serviceBusReadParameters = @{} + $PSBoundParameters +} + +function Set-AzServiceBusReadTestResource { + [CmdletBinding()] + param( + [string] $Name, + [object] $DefaultProfile, + [switch] $AcquirePolicyToken, + [string] $ChangeReference, + [string] $SyntheticWriteOnly + ) + + $script:serviceBusWriteParameters = @{} + $PSBoundParameters +} + +Set-Alias -Name Get-AzServiceBusReadTestAlias -Value Get-AzServiceBusReadTestResource + +Describe 'ServiceBus read parameter forwarding' { + It 'filters write-only parameters using read command metadata without changing target parameters' { + $targetParameters = @{ + Name = 'queue' + DefaultProfile = 'profile' + ErrorAction = 'Stop' + AcquirePolicyToken = $true + ChangeReference = 'change-123' + SyntheticWriteOnly = 'future-value' + } + + $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusReadTestAlias' -BoundParameters $targetParameters + Get-AzServiceBusReadTestResource @readParameters + Set-AzServiceBusReadTestResource @targetParameters + + $script:serviceBusReadParameters.Name | Should Be 'queue' + $script:serviceBusReadParameters.DefaultProfile | Should Be 'profile' + $script:serviceBusReadParameters.ErrorAction | Should Be 'Stop' + $script:serviceBusReadParameters.ContainsKey('AcquirePolicyToken') | Should Be $false + $script:serviceBusReadParameters.ContainsKey('ChangeReference') | Should Be $false + $script:serviceBusReadParameters.ContainsKey('SyntheticWriteOnly') | Should Be $false + $script:serviceBusWriteParameters.AcquirePolicyToken | Should Be $true + $script:serviceBusWriteParameters.ChangeReference | Should Be 'change-123' + $script:serviceBusWriteParameters.SyntheticWriteOnly | Should Be 'future-value' + } + + It 'recognizes read parameter aliases' { + $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusReadTestResource' -BoundParameters @{ ResourceName = 'queue' } + + $readParameters.ResourceName | Should Be 'queue' + } + + It 'uses separate read and target parameter groups in every affected wrapper' { + $wrappers = @( + 'Approve-AzServiceBusPrivateEndpointConnection.ps1', + 'Deny-AzServiceBusPrivateEndpointConnection.ps1', + 'Set-AzServiceBusAuthorizationRule.ps1', + 'Set-AzServiceBusGeoDRConfigurationBreakPair.ps1', + 'Set-AzServiceBusGeoDRConfigurationFailOver.ps1', + 'Set-AzServiceBusNamespace.ps1', + 'Set-AzServiceBusNetworkRuleSet.ps1', + 'Set-AzServiceBusQueue.ps1', + 'Set-AzServiceBusRule.ps1', + 'Set-AzServiceBusSubscription.ps1', + 'Set-AzServiceBusTopic.ps1' + ) + + foreach ($wrapper in $wrappers) { + $source = Get-Content -Path (Join-Path $PSScriptRoot "..\custom\$wrapper") -Raw + $source | Should Match '\$targetParameters\s*=\s*@\{\}\s*\+\s*\$PSBoundParameters' + $source | Should Match 'Get-AzServiceBusReadParameters\s+-CommandName' + $source | Should Match '@readParameters' + $source | Should Match '@targetParameters' + } + } + + It 'keeps exact expanded and via-identity read variants for authorization rules' { + $source = Get-Content -Path (Join-Path $PSScriptRoot '..\custom\Set-AzServiceBusAuthorizationRule.ps1') -Raw + + $source | Should Match "CommandName 'Az\.ServiceBus\.private\\Get-AzServiceBusQueueAuthorizationRule_Get'" + $source | Should Match "CommandName 'Az\.ServiceBus\.private\\Get-AzServiceBusTopicAuthorizationRule_GetViaIdentity'" + $source | Should Match "CommandName 'Az\.ServiceBus\.private\\Get-AzServiceBusNamespaceAuthorizationRule_GetViaIdentity'" + } + + It 'packages the internal helper and triggers regeneration' { + $customPath = Join-Path $PSScriptRoot '..\custom' + $helperPath = Join-Path $customPath 'Get-AzServiceBusReadParameters.ps1' + $moduleSource = Get-Content -Path (Join-Path $customPath 'Az.ServiceBus.custom.psm1') -Raw + $helperSource = Get-Content -Path $helperPath -Raw + $generation = Get-Content -Path (Join-Path $PSScriptRoot '..\generate-info.json') -Raw | ConvertFrom-Json + + Test-Path -Path $helperPath | Should Be $true + $helperSource | Should Match '\[Microsoft\.Azure\.PowerShell\.Cmdlets\.ServiceBus\.DoNotExportAttribute\(\)\]' + $moduleSource | Should Match "Get-ChildItem\s+-Path\s+\`$PSScriptRoot\s+-Recurse\s+-Include\s+'\*\.ps1'" + { [guid]::Parse($generation.generate_Id) } | Should Not Throw + $generation.generate_Id | Should Not Be 'd42664e3-3ae4-4daf-a410-fba6f9958c4e' + } +} diff --git a/src/ServiceBus/ServiceBus/ChangeLog.md b/src/ServiceBus/ServiceBus/ChangeLog.md index e1c240079d4e..6ff04cfe0bc1 100644 --- a/src/ServiceBus/ServiceBus/ChangeLog.md +++ b/src/ServiceBus/ServiceBus/ChangeLog.md @@ -20,6 +20,7 @@ --> ## Upcoming Release * Added Change Safety support for additional cmdlets. +* Fixed Change Safety parameter forwarding in custom GET-before-write cmdlets. ## Version 4.3.0 * Added parameters 'GeoDataReplicationMaxReplicationLagDurationInSecond', 'GeoDataReplicationLocation', and 'IPAddressType' to cmdlets 'New-AzServiceBusNamespace' and 'Set-AzServiceBusNamespace' From 68447ebda6bf497e9d1e038947b8da9596f911de Mon Sep 17 00:00:00 2001 From: Yang An Date: Mon, 28 Sep 2026 14:46:51 +1000 Subject: [PATCH 02/12] Inline read parameter metadata filtering Remove the module-specific helper functions and filter read parameters directly at each preliminary read site while preserving the independent target parameter dictionary. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- ...ve-AzEventHubPrivateEndpointConnection.ps1 | 13 +- ...ny-AzEventHubPrivateEndpointConnection.ps1 | 13 +- .../custom/Get-AzEventHubReadParameters.ps1 | 30 ---- .../custom/Set-AzEventHub.ps1 | 13 +- .../custom/Set-AzEventHubApplicationGroup.ps1 | 13 +- .../Set-AzEventHubAuthorizationRule.ps1 | 96 +++++++++++- .../custom/Set-AzEventHubCluster.ps1 | 13 +- .../custom/Set-AzEventHubConsumerGroup.ps1 | 13 +- ...-AzEventHubGeoDRConfigurationBreakPair.ps1 | 13 +- ...t-AzEventHubGeoDRConfigurationFailOver.ps1 | 13 +- .../custom/Set-AzEventHubNamespace.ps1 | 13 +- .../custom/Set-AzEventHubNetworkRuleSet.ps1 | 13 +- .../test/ReadParameterForwarding.Tests.ps1 | 88 +++++++---- ...NetworkSecurityPerimeterReadParameters.ps1 | 30 ---- ...e-AzNetworkSecurityPerimeterAccessRule.ps1 | 24 ++- ...-AzNetworkSecurityPerimeterAssociation.ps1 | 13 +- .../Update-AzNetworkSecurityPerimeterLink.ps1 | 13 +- ...kSecurityPerimeterLoggingConfiguration.ps1 | 13 +- .../test/ReadParameterForwarding.Tests.ps1 | 82 +++++++--- ...-AzServiceBusPrivateEndpointConnection.ps1 | 13 +- ...-AzServiceBusPrivateEndpointConnection.ps1 | 13 +- .../custom/Get-AzServiceBusReadParameters.ps1 | 30 ---- .../Set-AzServiceBusAuthorizationRule.ps1 | 144 +++++++++++++++++- ...zServiceBusGeoDRConfigurationBreakPair.ps1 | 13 +- ...AzServiceBusGeoDRConfigurationFailOver.ps1 | 13 +- .../custom/Set-AzServiceBusNamespace.ps1 | 24 ++- .../custom/Set-AzServiceBusNetworkRuleSet.ps1 | 13 +- .../custom/Set-AzServiceBusQueue.ps1 | 13 +- .../custom/Set-AzServiceBusRule.ps1 | 13 +- .../custom/Set-AzServiceBusSubscription.ps1 | 13 +- .../custom/Set-AzServiceBusTopic.ps1 | 13 +- .../test/ReadParameterForwarding.Tests.ps1 | 88 +++++++---- 32 files changed, 717 insertions(+), 205 deletions(-) delete mode 100644 src/EventHub/EventHub.Autorest/custom/Get-AzEventHubReadParameters.ps1 delete mode 100644 src/Network/NetworkSecurityPerimeter.Autorest/custom/Get-AzNetworkSecurityPerimeterReadParameters.ps1 delete mode 100644 src/ServiceBus/ServiceBus.Autorest/custom/Get-AzServiceBusReadParameters.ps1 diff --git a/src/EventHub/EventHub.Autorest/custom/Approve-AzEventHubPrivateEndpointConnection.ps1 b/src/EventHub/EventHub.Autorest/custom/Approve-AzEventHubPrivateEndpointConnection.ps1 index d6d8afa302d4..31ba1b99c295 100644 --- a/src/EventHub/EventHub.Autorest/custom/Approve-AzEventHubPrivateEndpointConnection.ps1 +++ b/src/EventHub/EventHub.Autorest/custom/Approve-AzEventHubPrivateEndpointConnection.ps1 @@ -140,7 +140,18 @@ function Approve-AzEventHubPrivateEndpointConnection{ $null = $targetParameters.Remove('WhatIf') $null = $targetParameters.Remove('Confirm') - $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHubPrivateEndpointConnection' -BoundParameters $targetParameters + $readCommand = @(Get-Command -Name 'Get-AzEventHubPrivateEndpointConnection' -ErrorAction Stop)[0] + while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { + $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop + } + $readParameterNames = @($readCommand.Parameters.Keys) + $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) + $readParameters = @{} + foreach ($parameter in $targetParameters.GetEnumerator()) { + if ($parameter.Key -in $readParameterNames) { + $readParameters[$parameter.Key] = $parameter.Value + } + } $connection = Get-AzEventHubPrivateEndpointConnection @readParameters $connection.ConnectionState = "Approved" diff --git a/src/EventHub/EventHub.Autorest/custom/Deny-AzEventHubPrivateEndpointConnection.ps1 b/src/EventHub/EventHub.Autorest/custom/Deny-AzEventHubPrivateEndpointConnection.ps1 index 1c7f47e6a6b6..433b477fe68a 100644 --- a/src/EventHub/EventHub.Autorest/custom/Deny-AzEventHubPrivateEndpointConnection.ps1 +++ b/src/EventHub/EventHub.Autorest/custom/Deny-AzEventHubPrivateEndpointConnection.ps1 @@ -140,7 +140,18 @@ function Deny-AzEventHubPrivateEndpointConnection{ $null = $targetParameters.Remove('WhatIf') $null = $targetParameters.Remove('Confirm') - $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHubPrivateEndpointConnection' -BoundParameters $targetParameters + $readCommand = @(Get-Command -Name 'Get-AzEventHubPrivateEndpointConnection' -ErrorAction Stop)[0] + while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { + $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop + } + $readParameterNames = @($readCommand.Parameters.Keys) + $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) + $readParameters = @{} + foreach ($parameter in $targetParameters.GetEnumerator()) { + if ($parameter.Key -in $readParameterNames) { + $readParameters[$parameter.Key] = $parameter.Value + } + } $connection = Get-AzEventHubPrivateEndpointConnection @readParameters $connection.ConnectionState = "Rejected" diff --git a/src/EventHub/EventHub.Autorest/custom/Get-AzEventHubReadParameters.ps1 b/src/EventHub/EventHub.Autorest/custom/Get-AzEventHubReadParameters.ps1 deleted file mode 100644 index 9871b7a8b785..000000000000 --- a/src/EventHub/EventHub.Autorest/custom/Get-AzEventHubReadParameters.ps1 +++ /dev/null @@ -1,30 +0,0 @@ -function Get-AzEventHubReadParameters { - [Microsoft.Azure.PowerShell.Cmdlets.EventHub.DoNotExportAttribute()] - [CmdletBinding()] - param( - [Parameter(Mandatory)] - [System.String] - ${CommandName}, - - [Parameter(Mandatory)] - [System.Collections.IDictionary] - ${BoundParameters} - ) - - $command = @(Get-Command -Name $CommandName -ErrorAction Stop)[0] - while ($command.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { - $command = Get-Command -Name $command.ResolvedCommandName -ErrorAction Stop - } - - $parameterNames = @($command.Parameters.Keys) - $parameterNames += @($command.Parameters.Values | ForEach-Object { $_.Aliases }) - - $readParameters = @{} - foreach ($parameter in $BoundParameters.GetEnumerator()) { - if ($parameter.Key -in $parameterNames) { - $readParameters[$parameter.Key] = $parameter.Value - } - } - - return $readParameters -} diff --git a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHub.ps1 b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHub.ps1 index cc31843c25cf..1d45e65a130b 100644 --- a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHub.ps1 +++ b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHub.ps1 @@ -258,7 +258,18 @@ function Set-AzEventHub{ $null = $targetParameters.Remove('WhatIf') $null = $targetParameters.Remove('Confirm') - $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHub' -BoundParameters $targetParameters + $readCommand = @(Get-Command -Name 'Get-AzEventHub' -ErrorAction Stop)[0] + while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { + $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop + } + $readParameterNames = @($readCommand.Parameters.Keys) + $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) + $readParameters = @{} + foreach ($parameter in $targetParameters.GetEnumerator()) { + if ($parameter.Key -in $readParameterNames) { + $readParameters[$parameter.Key] = $parameter.Value + } + } $eventHub = Get-AzEventHub @readParameters # 2. PUT $null = $targetParameters.Remove('InputObject') diff --git a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubApplicationGroup.ps1 b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubApplicationGroup.ps1 index de959fec3051..15ff09c98f06 100644 --- a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubApplicationGroup.ps1 +++ b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubApplicationGroup.ps1 @@ -154,7 +154,18 @@ function Set-AzEventHubApplicationGroup{ $null = $targetParameters.Remove('WhatIf') $null = $targetParameters.Remove('Confirm') - $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHubApplicationGroup' -BoundParameters $targetParameters + $readCommand = @(Get-Command -Name 'Get-AzEventHubApplicationGroup' -ErrorAction Stop)[0] + while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { + $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop + } + $readParameterNames = @($readCommand.Parameters.Keys) + $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) + $readParameters = @{} + foreach ($parameter in $targetParameters.GetEnumerator()) { + if ($parameter.Key -in $readParameterNames) { + $readParameters[$parameter.Key] = $parameter.Value + } + } $appGroup = Get-AzEventHubApplicationGroup @readParameters # 2. PUT $null = $targetParameters.Remove('InputObject') diff --git a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubAuthorizationRule.ps1 b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubAuthorizationRule.ps1 index f92c0698cedb..7cbe165ad363 100644 --- a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubAuthorizationRule.ps1 +++ b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubAuthorizationRule.ps1 @@ -152,12 +152,56 @@ function Set-AzEventHubAuthorizationRule{ $null = $targetParameters.Remove('Confirm') if ($PSCmdlet.ParameterSetName -eq 'SetExpandedNamespace'){ - $readParameters = Get-AzEventHubReadParameters -CommandName 'Az.EventHub.private\Get-AzEventHubNamespaceAuthorizationRule_Get' -BoundParameters $targetParameters + $readCommand = @(Get-Command -Name 'Az.EventHub.private\Get-AzEventHubNamespaceAuthorizationRule_Get' -ErrorAction Stop)[0] + + while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { + + $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop + + } + + $readParameterNames = @($readCommand.Parameters.Keys) + + $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) + + $readParameters = @{} + + foreach ($parameter in $targetParameters.GetEnumerator()) { + + if ($parameter.Key -in $readParameterNames) { + + $readParameters[$parameter.Key] = $parameter.Value + + } + + } $authRule = Az.EventHub.private\Get-AzEventHubNamespaceAuthorizationRule_Get @readParameters } elseif($PSCmdlet.ParameterSetName -eq 'SetExpandedEntity'){ - $readParameters = Get-AzEventHubReadParameters -CommandName 'Az.EventHub.private\Get-AzEventHubAuthorizationRule_Get' -BoundParameters $targetParameters + $readCommand = @(Get-Command -Name 'Az.EventHub.private\Get-AzEventHubAuthorizationRule_Get' -ErrorAction Stop)[0] + + while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { + + $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop + + } + + $readParameterNames = @($readCommand.Parameters.Keys) + + $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) + + $readParameters = @{} + + foreach ($parameter in $targetParameters.GetEnumerator()) { + + if ($parameter.Key -in $readParameterNames) { + + $readParameters[$parameter.Key] = $parameter.Value + + } + + } $authRule = Az.EventHub.private\Get-AzEventHubAuthorizationRule_Get @readParameters } @@ -169,11 +213,55 @@ function Set-AzEventHubAuthorizationRule{ $ResourceHashTable = ParseResourceId -ResourceId $InputObject } if ($ResourceHashTable['EventHubName'] -ne $null){ - $readParameters = Get-AzEventHubReadParameters -CommandName 'Az.EventHub.private\Get-AzEventHubAuthorizationRule_GetViaIdentity' -BoundParameters $targetParameters + $readCommand = @(Get-Command -Name 'Az.EventHub.private\Get-AzEventHubAuthorizationRule_GetViaIdentity' -ErrorAction Stop)[0] + + while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { + + $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop + + } + + $readParameterNames = @($readCommand.Parameters.Keys) + + $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) + + $readParameters = @{} + + foreach ($parameter in $targetParameters.GetEnumerator()) { + + if ($parameter.Key -in $readParameterNames) { + + $readParameters[$parameter.Key] = $parameter.Value + + } + + } $authRule = Az.EventHub.private\Get-AzEventHubAuthorizationRule_GetViaIdentity @readParameters } elseif ($ResourceHashTable['NamespaceName'] -ne $null){ - $readParameters = Get-AzEventHubReadParameters -CommandName 'Az.EventHub.private\Get-AzEventHubNamespaceAuthorizationRule_GetViaIdentity' -BoundParameters $targetParameters + $readCommand = @(Get-Command -Name 'Az.EventHub.private\Get-AzEventHubNamespaceAuthorizationRule_GetViaIdentity' -ErrorAction Stop)[0] + + while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { + + $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop + + } + + $readParameterNames = @($readCommand.Parameters.Keys) + + $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) + + $readParameters = @{} + + foreach ($parameter in $targetParameters.GetEnumerator()) { + + if ($parameter.Key -in $readParameterNames) { + + $readParameters[$parameter.Key] = $parameter.Value + + } + + } $authRule = Az.EventHub.private\Get-AzEventHubNamespaceAuthorizationRule_GetViaIdentity @readParameters } else{ diff --git a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubCluster.ps1 b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubCluster.ps1 index 3b5969ddef0a..2edc7e582290 100644 --- a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubCluster.ps1 +++ b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubCluster.ps1 @@ -142,7 +142,18 @@ function Set-AzEventHubCluster{ $null = $targetParameters.Remove('WhatIf') $null = $targetParameters.Remove('Confirm') - $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHubCluster' -BoundParameters $targetParameters + $readCommand = @(Get-Command -Name 'Get-AzEventHubCluster' -ErrorAction Stop)[0] + while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { + $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop + } + $readParameterNames = @($readCommand.Parameters.Keys) + $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) + $readParameters = @{} + foreach ($parameter in $targetParameters.GetEnumerator()) { + if ($parameter.Key -in $readParameterNames) { + $readParameters[$parameter.Key] = $parameter.Value + } + } $cluster = Get-AzEventHubCluster @readParameters # 2. PUT $null = $targetParameters.Remove('InputObject') diff --git a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubConsumerGroup.ps1 b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubConsumerGroup.ps1 index a92141cbfd75..33136f2ba1bc 100644 --- a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubConsumerGroup.ps1 +++ b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubConsumerGroup.ps1 @@ -147,7 +147,18 @@ function Set-AzEventHubConsumerGroup{ $null = $targetParameters.Remove('WhatIf') $null = $targetParameters.Remove('Confirm') - $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHubConsumerGroup' -BoundParameters $targetParameters + $readCommand = @(Get-Command -Name 'Get-AzEventHubConsumerGroup' -ErrorAction Stop)[0] + while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { + $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop + } + $readParameterNames = @($readCommand.Parameters.Keys) + $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) + $readParameters = @{} + foreach ($parameter in $targetParameters.GetEnumerator()) { + if ($parameter.Key -in $readParameterNames) { + $readParameters[$parameter.Key] = $parameter.Value + } + } $consumerGroup = Get-AzEventHubConsumerGroup @readParameters # 2. PUT $null = $targetParameters.Remove('InputObject') diff --git a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubGeoDRConfigurationBreakPair.ps1 b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubGeoDRConfigurationBreakPair.ps1 index 6e9642409fa5..6579a0d3f9cb 100644 --- a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubGeoDRConfigurationBreakPair.ps1 +++ b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubGeoDRConfigurationBreakPair.ps1 @@ -132,7 +132,18 @@ function Set-AzEventHubGeoDRConfigurationBreakPair{ $null = $targetParameters.Remove('WhatIf') $null = $targetParameters.Remove('Confirm') - $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHubGeoDRConfiguration' -BoundParameters $targetParameters + $readCommand = @(Get-Command -Name 'Get-AzEventHubGeoDRConfiguration' -ErrorAction Stop)[0] + while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { + $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop + } + $readParameterNames = @($readCommand.Parameters.Keys) + $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) + $readParameters = @{} + foreach ($parameter in $targetParameters.GetEnumerator()) { + if ($parameter.Key -in $readParameterNames) { + $readParameters[$parameter.Key] = $parameter.Value + } + } $drConfig = Get-AzEventHubGeoDRConfiguration @readParameters # 2. PUT $null = $targetParameters.Remove('InputObject') diff --git a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubGeoDRConfigurationFailOver.ps1 b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubGeoDRConfigurationFailOver.ps1 index 22b3fc96b502..32b2c5cf493b 100644 --- a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubGeoDRConfigurationFailOver.ps1 +++ b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubGeoDRConfigurationFailOver.ps1 @@ -132,7 +132,18 @@ function Set-AzEventHubGeoDRConfigurationFailOver{ $null = $targetParameters.Remove('WhatIf') $null = $targetParameters.Remove('Confirm') - $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHubGeoDRConfiguration' -BoundParameters $targetParameters + $readCommand = @(Get-Command -Name 'Get-AzEventHubGeoDRConfiguration' -ErrorAction Stop)[0] + while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { + $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop + } + $readParameterNames = @($readCommand.Parameters.Keys) + $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) + $readParameters = @{} + foreach ($parameter in $targetParameters.GetEnumerator()) { + if ($parameter.Key -in $readParameterNames) { + $readParameters[$parameter.Key] = $parameter.Value + } + } $drConfig = Get-AzEventHubGeoDRConfiguration @readParameters # 2. PUT $null = $targetParameters.Remove('InputObject') diff --git a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubNamespace.ps1 b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubNamespace.ps1 index a50c38fd8236..fc4eba0cb07a 100644 --- a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubNamespace.ps1 +++ b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubNamespace.ps1 @@ -224,7 +224,18 @@ function Set-AzEventHubNamespace{ $null = $targetParameters.Remove('WhatIf') $null = $targetParameters.Remove('Confirm') - $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHubNamespace' -BoundParameters $targetParameters + $readCommand = @(Get-Command -Name 'Get-AzEventHubNamespace' -ErrorAction Stop)[0] + while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { + $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop + } + $readParameterNames = @($readCommand.Parameters.Keys) + $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) + $readParameters = @{} + foreach ($parameter in $targetParameters.GetEnumerator()) { + if ($parameter.Key -in $readParameterNames) { + $readParameters[$parameter.Key] = $parameter.Value + } + } $eventHubNamespace = Get-AzEventHubNamespace @readParameters # 2. PUT $null = $targetParameters.Remove('InputObject') diff --git a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubNetworkRuleSet.ps1 b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubNetworkRuleSet.ps1 index 1918a8564909..c6d399ad6e88 100644 --- a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubNetworkRuleSet.ps1 +++ b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubNetworkRuleSet.ps1 @@ -162,7 +162,18 @@ function Set-AzEventHubNetworkRuleSet{ $null = $targetParameters.Remove('WhatIf') $null = $targetParameters.Remove('Confirm') - $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHubNetworkRuleSet' -BoundParameters $targetParameters + $readCommand = @(Get-Command -Name 'Get-AzEventHubNetworkRuleSet' -ErrorAction Stop)[0] + while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { + $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop + } + $readParameterNames = @($readCommand.Parameters.Keys) + $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) + $readParameters = @{} + foreach ($parameter in $targetParameters.GetEnumerator()) { + if ($parameter.Key -in $readParameterNames) { + $readParameters[$parameter.Key] = $parameter.Value + } + } $networkRuleSet = Get-AzEventHubNetworkRuleSet @readParameters # 2. PUT $null = $targetParameters.Remove('InputObject') diff --git a/src/EventHub/EventHub.Autorest/test/ReadParameterForwarding.Tests.ps1 b/src/EventHub/EventHub.Autorest/test/ReadParameterForwarding.Tests.ps1 index 507292ab582e..ebbbeae41aa1 100644 --- a/src/EventHub/EventHub.Autorest/test/ReadParameterForwarding.Tests.ps1 +++ b/src/EventHub/EventHub.Autorest/test/ReadParameterForwarding.Tests.ps1 @@ -1,8 +1,3 @@ -$helperPath = Join-Path $PSScriptRoot '..\custom\Get-AzEventHubReadParameters.ps1' -$helperSource = Get-Content -Path $helperPath -Raw -$helperSource = $helperSource -replace '(?m)^\s*\[Microsoft\.Azure\.PowerShell\.Cmdlets\.EventHub\.DoNotExportAttribute\(\)\]\r?\n', '' -. ([scriptblock]::Create($helperSource)) - function Get-AzEventHubReadTestResource { [CmdletBinding()] param( @@ -27,10 +22,30 @@ function Set-AzEventHubReadTestResource { $script:eventHubWriteParameters = @{} + $PSBoundParameters } -Set-Alias -Name Get-AzEventHubReadTestAlias -Value Get-AzEventHubReadTestResource +function Assert-InlineReadCommandsInvoked { + param([string] $Source) + + $lookupPattern = "(?ms)\`$readCommand\s*=\s*@\(Get-Command -Name '([^']+)'[^\r\n]*\)\[0\](?.*?)(?=\`$readCommand\s*=\s*@\(Get-Command -Name|\z)" + $lookups = [regex]::Matches($Source, $lookupPattern) + if ($lookups.Count -eq 0) { + return $false + } + + foreach ($lookup in $lookups) { + $commandName = $lookup.Groups[1].Value + $invocationPattern = '(?m)^\s*(?:\$\w+\s*=\s*)?' + [regex]::Escape($commandName) + '\s+@readParameters\s*$' + if (-not [regex]::IsMatch($lookup.Groups['Block'].Value, $invocationPattern)) { + return $false + } + } + + return $true +} + +Set-Alias -Name Get-AzEventHubReadTestResourceAlias -Value Get-AzEventHubReadTestResource -Describe 'EventHub read parameter forwarding' { - It 'filters write-only parameters using read command metadata without changing target parameters' { +Describe 'EventHub inline read parameter forwarding' { + It 'filters write-only parameters using aliased read command metadata without changing target parameters' { $targetParameters = @{ Name = 'eventhub' DefaultProfile = 'profile' @@ -40,7 +55,20 @@ Describe 'EventHub read parameter forwarding' { SyntheticWriteOnly = 'future-value' } - $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHubReadTestAlias' -BoundParameters $targetParameters + $readCommand = @(Get-Command -Name 'Get-AzEventHubReadTestResourceAlias' -ErrorAction Stop)[0] + while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { + $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop + } + $readParameterNames = @($readCommand.Parameters.Keys) + $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) + $readParameters = @{} + foreach ($parameter in $targetParameters.GetEnumerator()) { + if ($parameter.Key -in $readParameterNames) { + $readParameters[$parameter.Key] = $parameter.Value + } + } + + ($readParameterNames -contains 'ResourceName') | Should Be $true Get-AzEventHubReadTestResource @readParameters Set-AzEventHubReadTestResource @targetParameters @@ -55,13 +83,7 @@ Describe 'EventHub read parameter forwarding' { $script:eventHubWriteParameters.SyntheticWriteOnly | Should Be 'future-value' } - It 'recognizes read parameter aliases' { - $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHubReadTestResource' -BoundParameters @{ ResourceName = 'eventhub' } - - $readParameters.ResourceName | Should Be 'eventhub' - } - - It 'uses separate read and target parameter groups in every affected wrapper' { + It 'inlines metadata filtering with separate read and target parameters in every affected wrapper' { $wrappers = @( 'Approve-AzEventHubPrivateEndpointConnection.ps1', 'Deny-AzEventHubPrivateEndpointConnection.ps1', @@ -79,30 +101,40 @@ Describe 'EventHub read parameter forwarding' { foreach ($wrapper in $wrappers) { $source = Get-Content -Path (Join-Path $PSScriptRoot "..\custom\$wrapper") -Raw $source | Should Match '\$targetParameters\s*=\s*@\{\}\s*\+\s*\$PSBoundParameters' - $source | Should Match 'Get-AzEventHubReadParameters\s+-CommandName' + $source | Should Match '\$readCommand\s*=\s*@\(Get-Command -Name' + $source | Should Match '\$readCommand\.CommandType.+CommandTypes\]::Alias' + $source | Should Match '\$readCommand\.Parameters\.Values.+\$_.Aliases' + $source | Should Match '\$readParameters\s*=\s*@\{\}' $source | Should Match '@readParameters' $source | Should Match '@targetParameters' + $source | Should Not Match 'Get-Az(?:EventHub|ServiceBus|NetworkSecurityPerimeter)ReadParameters' + (Assert-InlineReadCommandsInvoked -Source $source) | Should Be $true } } + It 'rejects a lookup followed by invocation of a different read command' { + $source = @' +$readCommand = @(Get-Command -Name 'Get-AzExpectedResource' -ErrorAction Stop)[0] +$readParameters = @{} +$resource = Get-AzDifferentResource @readParameters +'@ + + (Assert-InlineReadCommandsInvoked -Source $source) | Should Be $false + } + It 'keeps exact expanded and via-identity read variants for authorization rules' { $source = Get-Content -Path (Join-Path $PSScriptRoot '..\custom\Set-AzEventHubAuthorizationRule.ps1') -Raw - $source | Should Match "CommandName 'Az\.EventHub\.private\\Get-AzEventHubAuthorizationRule_Get'" - $source | Should Match "CommandName 'Az\.EventHub\.private\\Get-AzEventHubAuthorizationRule_GetViaIdentity'" - $source | Should Match "CommandName 'Az\.EventHub\.private\\Get-AzEventHubNamespaceAuthorizationRule_GetViaIdentity'" + $source | Should Match "Get-Command -Name 'Az.EventHub.private\\Get-AzEventHubAuthorizationRule_Get'" + $source | Should Match "Get-Command -Name 'Az.EventHub.private\\Get-AzEventHubAuthorizationRule_GetViaIdentity'" + $source | Should Match "Get-Command -Name 'Az.EventHub.private\\Get-AzEventHubNamespaceAuthorizationRule_GetViaIdentity'" } - It 'packages the internal helper and triggers regeneration' { - $customPath = Join-Path $PSScriptRoot '..\custom' - $helperPath = Join-Path $customPath 'Get-AzEventHubReadParameters.ps1' - $moduleSource = Get-Content -Path (Join-Path $customPath 'Az.EventHub.custom.psm1') -Raw - $helperSource = Get-Content -Path $helperPath -Raw + It 'has no helper source and retains the regeneration trigger' { + $helperPath = Join-Path $PSScriptRoot '..\custom\Get-AzEventHubReadParameters.ps1' $generation = Get-Content -Path (Join-Path $PSScriptRoot '..\generate-info.json') -Raw | ConvertFrom-Json - Test-Path -Path $helperPath | Should Be $true - $helperSource | Should Match '\[Microsoft\.Azure\.PowerShell\.Cmdlets\.EventHub\.DoNotExportAttribute\(\)\]' - $moduleSource | Should Match "Get-ChildItem\s+-Path\s+\`$PSScriptRoot\s+-Recurse\s+-Include\s+'\*\.ps1'" + Test-Path -Path $helperPath | Should Be $false { [guid]::Parse($generation.generate_Id) } | Should Not Throw $generation.generate_Id | Should Not Be '37e57dcc-9680-41ff-a019-ec549669f7b0' } diff --git a/src/Network/NetworkSecurityPerimeter.Autorest/custom/Get-AzNetworkSecurityPerimeterReadParameters.ps1 b/src/Network/NetworkSecurityPerimeter.Autorest/custom/Get-AzNetworkSecurityPerimeterReadParameters.ps1 deleted file mode 100644 index 0e72e74dbfb8..000000000000 --- a/src/Network/NetworkSecurityPerimeter.Autorest/custom/Get-AzNetworkSecurityPerimeterReadParameters.ps1 +++ /dev/null @@ -1,30 +0,0 @@ -function Get-AzNetworkSecurityPerimeterReadParameters { - [Microsoft.Azure.PowerShell.Cmdlets.NetworkSecurityPerimeter.DoNotExportAttribute()] - [CmdletBinding()] - param( - [Parameter(Mandatory)] - [System.String] - ${CommandName}, - - [Parameter(Mandatory)] - [System.Collections.IDictionary] - ${BoundParameters} - ) - - $command = @(Get-Command -Name $CommandName -ErrorAction Stop)[0] - while ($command.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { - $command = Get-Command -Name $command.ResolvedCommandName -ErrorAction Stop - } - - $parameterNames = @($command.Parameters.Keys) - $parameterNames += @($command.Parameters.Values | ForEach-Object { $_.Aliases }) - - $readParameters = @{} - foreach ($parameter in $BoundParameters.GetEnumerator()) { - if ($parameter.Key -in $parameterNames) { - $readParameters[$parameter.Key] = $parameter.Value - } - } - - return $readParameters -} diff --git a/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterAccessRule.ps1 b/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterAccessRule.ps1 index 93ee0ce91e49..f9da3f598172 100644 --- a/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterAccessRule.ps1 +++ b/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterAccessRule.ps1 @@ -215,7 +215,29 @@ function Update-AzNetworkSecurityPerimeterAccessRule { $null = $targetParameters.Remove('Confirm') - $readParameters = Get-AzNetworkSecurityPerimeterReadParameters -CommandName 'Get-AzNetworkSecurityPerimeterAccessRule' -BoundParameters $targetParameters + $readCommand = @(Get-Command -Name 'Get-AzNetworkSecurityPerimeterAccessRule' -ErrorAction Stop)[0] + + while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { + + $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop + + } + + $readParameterNames = @($readCommand.Parameters.Keys) + + $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) + + $readParameters = @{} + + foreach ($parameter in $targetParameters.GetEnumerator()) { + + if ($parameter.Key -in $readParameterNames) { + + $readParameters[$parameter.Key] = $parameter.Value + + } + + } $GETObject = Get-AzNetworkSecurityPerimeterAccessRule @readParameters # 2. PUT diff --git a/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterAssociation.ps1 b/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterAssociation.ps1 index e2d2bbbf02d4..119703f59269 100644 --- a/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterAssociation.ps1 +++ b/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterAssociation.ps1 @@ -183,7 +183,18 @@ function Update-AzNetworkSecurityPerimeterAssociation { $null = $targetParameters.Remove('WhatIf') $null = $targetParameters.Remove('Confirm') - $readParameters = Get-AzNetworkSecurityPerimeterReadParameters -CommandName 'Get-AzNetworkSecurityPerimeterAssociation' -BoundParameters $targetParameters + $readCommand = @(Get-Command -Name 'Get-AzNetworkSecurityPerimeterAssociation' -ErrorAction Stop)[0] + while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { + $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop + } + $readParameterNames = @($readCommand.Parameters.Keys) + $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) + $readParameters = @{} + foreach ($parameter in $targetParameters.GetEnumerator()) { + if ($parameter.Key -in $readParameterNames) { + $readParameters[$parameter.Key] = $parameter.Value + } + } $GETObject = Get-AzNetworkSecurityPerimeterAssociation @readParameters # 2. PUT diff --git a/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterLink.ps1 b/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterLink.ps1 index d9199705f158..6ed0fe410658 100644 --- a/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterLink.ps1 +++ b/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterLink.ps1 @@ -184,7 +184,18 @@ function Update-AzNetworkSecurityPerimeterLink { $null = $targetParameters.Remove('WhatIf') $null = $targetParameters.Remove('Confirm') - $readParameters = Get-AzNetworkSecurityPerimeterReadParameters -CommandName 'Get-AzNetworkSecurityPerimeterLink' -BoundParameters $targetParameters + $readCommand = @(Get-Command -Name 'Get-AzNetworkSecurityPerimeterLink' -ErrorAction Stop)[0] + while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { + $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop + } + $readParameterNames = @($readCommand.Parameters.Keys) + $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) + $readParameters = @{} + foreach ($parameter in $targetParameters.GetEnumerator()) { + if ($parameter.Key -in $readParameterNames) { + $readParameters[$parameter.Key] = $parameter.Value + } + } $GETObject = Get-AzNetworkSecurityPerimeterLink @readParameters # 2. PUT diff --git a/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterLoggingConfiguration.ps1 b/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterLoggingConfiguration.ps1 index 75c21bea806e..d98630d107d3 100644 --- a/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterLoggingConfiguration.ps1 +++ b/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterLoggingConfiguration.ps1 @@ -172,7 +172,18 @@ function Update-AzNetworkSecurityPerimeterLoggingConfiguration { $null = $targetParameters.Remove('WhatIf') $null = $targetParameters.Remove('Confirm') - $readParameters = Get-AzNetworkSecurityPerimeterReadParameters -CommandName 'Get-AzNetworkSecurityPerimeterLoggingConfiguration' -BoundParameters $targetParameters + $readCommand = @(Get-Command -Name 'Get-AzNetworkSecurityPerimeterLoggingConfiguration' -ErrorAction Stop)[0] + while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { + $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop + } + $readParameterNames = @($readCommand.Parameters.Keys) + $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) + $readParameters = @{} + foreach ($parameter in $targetParameters.GetEnumerator()) { + if ($parameter.Key -in $readParameterNames) { + $readParameters[$parameter.Key] = $parameter.Value + } + } $GETObject = Get-AzNetworkSecurityPerimeterLoggingConfiguration @readParameters # 2. PUT diff --git a/src/Network/NetworkSecurityPerimeter.Autorest/test/ReadParameterForwarding.Tests.ps1 b/src/Network/NetworkSecurityPerimeter.Autorest/test/ReadParameterForwarding.Tests.ps1 index 74b020b57a15..43657949417b 100644 --- a/src/Network/NetworkSecurityPerimeter.Autorest/test/ReadParameterForwarding.Tests.ps1 +++ b/src/Network/NetworkSecurityPerimeter.Autorest/test/ReadParameterForwarding.Tests.ps1 @@ -1,8 +1,3 @@ -$helperPath = Join-Path $PSScriptRoot '..\custom\Get-AzNetworkSecurityPerimeterReadParameters.ps1' -$helperSource = Get-Content -Path $helperPath -Raw -$helperSource = $helperSource -replace '(?m)^\s*\[Microsoft\.Azure\.PowerShell\.Cmdlets\.NetworkSecurityPerimeter\.DoNotExportAttribute\(\)\]\r?\n', '' -. ([scriptblock]::Create($helperSource)) - function Get-AzNetworkSecurityPerimeterReadTestResource { [CmdletBinding()] param( @@ -27,10 +22,30 @@ function Set-AzNetworkSecurityPerimeterReadTestResource { $script:nspWriteParameters = @{} + $PSBoundParameters } -Set-Alias -Name Get-AzNetworkSecurityPerimeterReadTestAlias -Value Get-AzNetworkSecurityPerimeterReadTestResource +function Assert-InlineReadCommandsInvoked { + param([string] $Source) + + $lookupPattern = "(?ms)\`$readCommand\s*=\s*@\(Get-Command -Name '([^']+)'[^\r\n]*\)\[0\](?.*?)(?=\`$readCommand\s*=\s*@\(Get-Command -Name|\z)" + $lookups = [regex]::Matches($Source, $lookupPattern) + if ($lookups.Count -eq 0) { + return $false + } + + foreach ($lookup in $lookups) { + $commandName = $lookup.Groups[1].Value + $invocationPattern = '(?m)^\s*(?:\$\w+\s*=\s*)?' + [regex]::Escape($commandName) + '\s+@readParameters\s*$' + if (-not [regex]::IsMatch($lookup.Groups['Block'].Value, $invocationPattern)) { + return $false + } + } + + return $true +} + +Set-Alias -Name Get-AzNetworkSecurityPerimeterReadTestResourceAlias -Value Get-AzNetworkSecurityPerimeterReadTestResource -Describe 'NetworkSecurityPerimeter read parameter forwarding' { - It 'filters write-only parameters using read command metadata without changing target parameters' { +Describe 'NetworkSecurityPerimeter inline read parameter forwarding' { + It 'filters write-only parameters using aliased read command metadata without changing target parameters' { $targetParameters = @{ Name = 'access-rule' DefaultProfile = 'profile' @@ -40,7 +55,20 @@ Describe 'NetworkSecurityPerimeter read parameter forwarding' { SyntheticWriteOnly = 'future-value' } - $readParameters = Get-AzNetworkSecurityPerimeterReadParameters -CommandName 'Get-AzNetworkSecurityPerimeterReadTestAlias' -BoundParameters $targetParameters + $readCommand = @(Get-Command -Name 'Get-AzNetworkSecurityPerimeterReadTestResourceAlias' -ErrorAction Stop)[0] + while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { + $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop + } + $readParameterNames = @($readCommand.Parameters.Keys) + $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) + $readParameters = @{} + foreach ($parameter in $targetParameters.GetEnumerator()) { + if ($parameter.Key -in $readParameterNames) { + $readParameters[$parameter.Key] = $parameter.Value + } + } + + ($readParameterNames -contains 'ResourceName') | Should Be $true Get-AzNetworkSecurityPerimeterReadTestResource @readParameters Set-AzNetworkSecurityPerimeterReadTestResource @targetParameters @@ -55,13 +83,7 @@ Describe 'NetworkSecurityPerimeter read parameter forwarding' { $script:nspWriteParameters.SyntheticWriteOnly | Should Be 'future-value' } - It 'recognizes read parameter aliases' { - $readParameters = Get-AzNetworkSecurityPerimeterReadParameters -CommandName 'Get-AzNetworkSecurityPerimeterReadTestResource' -BoundParameters @{ ResourceName = 'access-rule' } - - $readParameters.ResourceName | Should Be 'access-rule' - } - - It 'uses separate read and target parameter groups in every affected wrapper' { + It 'inlines metadata filtering with separate read and target parameters in every affected wrapper' { $wrappers = @( 'Update-AzNetworkSecurityPerimeterAccessRule.ps1', 'Update-AzNetworkSecurityPerimeterAssociation.ps1', @@ -72,22 +94,32 @@ Describe 'NetworkSecurityPerimeter read parameter forwarding' { foreach ($wrapper in $wrappers) { $source = Get-Content -Path (Join-Path $PSScriptRoot "..\custom\$wrapper") -Raw $source | Should Match '\$targetParameters\s*=\s*@\{\}\s*\+\s*\$PSBoundParameters' - $source | Should Match 'Get-AzNetworkSecurityPerimeterReadParameters\s+-CommandName' + $source | Should Match '\$readCommand\s*=\s*@\(Get-Command -Name' + $source | Should Match '\$readCommand\.CommandType.+CommandTypes\]::Alias' + $source | Should Match '\$readCommand\.Parameters\.Values.+\$_.Aliases' + $source | Should Match '\$readParameters\s*=\s*@\{\}' $source | Should Match '@readParameters' $source | Should Match '@targetParameters' + $source | Should Not Match 'Get-Az(?:EventHub|ServiceBus|NetworkSecurityPerimeter)ReadParameters' + (Assert-InlineReadCommandsInvoked -Source $source) | Should Be $true } } - It 'packages the internal helper and triggers regeneration' { - $customPath = Join-Path $PSScriptRoot '..\custom' - $helperPath = Join-Path $customPath 'Get-AzNetworkSecurityPerimeterReadParameters.ps1' - $moduleSource = Get-Content -Path (Join-Path $customPath 'Az.NetworkSecurityPerimeter.custom.psm1') -Raw - $helperSource = Get-Content -Path $helperPath -Raw + It 'rejects a lookup followed by invocation of a different read command' { + $source = @' +$readCommand = @(Get-Command -Name 'Get-AzExpectedResource' -ErrorAction Stop)[0] +$readParameters = @{} +$resource = Get-AzDifferentResource @readParameters +'@ + + (Assert-InlineReadCommandsInvoked -Source $source) | Should Be $false + } + + It 'has no helper source and retains the regeneration trigger' { + $helperPath = Join-Path $PSScriptRoot '..\custom\Get-AzNetworkSecurityPerimeterReadParameters.ps1' $generation = Get-Content -Path (Join-Path $PSScriptRoot '..\generate-info.json') -Raw | ConvertFrom-Json - Test-Path -Path $helperPath | Should Be $true - $helperSource | Should Match '\[Microsoft\.Azure\.PowerShell\.Cmdlets\.NetworkSecurityPerimeter\.DoNotExportAttribute\(\)\]' - $moduleSource | Should Match "Get-ChildItem\s+-Path\s+\`$PSScriptRoot\s+-Recurse\s+-Include\s+'\*\.ps1'" + Test-Path -Path $helperPath | Should Be $false { [guid]::Parse($generation.generate_Id) } | Should Not Throw $generation.generate_Id | Should Not Be '22876a3f-6f36-449b-a291-2b1c423db247' } diff --git a/src/ServiceBus/ServiceBus.Autorest/custom/Approve-AzServiceBusPrivateEndpointConnection.ps1 b/src/ServiceBus/ServiceBus.Autorest/custom/Approve-AzServiceBusPrivateEndpointConnection.ps1 index 3040099f93f8..aabb68a1ce4a 100644 --- a/src/ServiceBus/ServiceBus.Autorest/custom/Approve-AzServiceBusPrivateEndpointConnection.ps1 +++ b/src/ServiceBus/ServiceBus.Autorest/custom/Approve-AzServiceBusPrivateEndpointConnection.ps1 @@ -141,7 +141,18 @@ function Approve-AzServiceBusPrivateEndpointConnection{ $null = $targetParameters.Remove('WhatIf') $null = $targetParameters.Remove('Confirm') - $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusPrivateEndpointConnection' -BoundParameters $targetParameters + $readCommand = @(Get-Command -Name 'Get-AzServiceBusPrivateEndpointConnection' -ErrorAction Stop)[0] + while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { + $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop + } + $readParameterNames = @($readCommand.Parameters.Keys) + $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) + $readParameters = @{} + foreach ($parameter in $targetParameters.GetEnumerator()) { + if ($parameter.Key -in $readParameterNames) { + $readParameters[$parameter.Key] = $parameter.Value + } + } $connection = Get-AzServiceBusPrivateEndpointConnection @readParameters $connection.ConnectionState = "Approved" diff --git a/src/ServiceBus/ServiceBus.Autorest/custom/Deny-AzServiceBusPrivateEndpointConnection.ps1 b/src/ServiceBus/ServiceBus.Autorest/custom/Deny-AzServiceBusPrivateEndpointConnection.ps1 index dbef3e27adf8..2c361ee9a2a3 100644 --- a/src/ServiceBus/ServiceBus.Autorest/custom/Deny-AzServiceBusPrivateEndpointConnection.ps1 +++ b/src/ServiceBus/ServiceBus.Autorest/custom/Deny-AzServiceBusPrivateEndpointConnection.ps1 @@ -141,7 +141,18 @@ function Deny-AzServiceBusPrivateEndpointConnection{ $null = $targetParameters.Remove('WhatIf') $null = $targetParameters.Remove('Confirm') - $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusPrivateEndpointConnection' -BoundParameters $targetParameters + $readCommand = @(Get-Command -Name 'Get-AzServiceBusPrivateEndpointConnection' -ErrorAction Stop)[0] + while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { + $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop + } + $readParameterNames = @($readCommand.Parameters.Keys) + $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) + $readParameters = @{} + foreach ($parameter in $targetParameters.GetEnumerator()) { + if ($parameter.Key -in $readParameterNames) { + $readParameters[$parameter.Key] = $parameter.Value + } + } $connection = Get-AzServiceBusPrivateEndpointConnection @readParameters $connection.ConnectionState = "Rejected" diff --git a/src/ServiceBus/ServiceBus.Autorest/custom/Get-AzServiceBusReadParameters.ps1 b/src/ServiceBus/ServiceBus.Autorest/custom/Get-AzServiceBusReadParameters.ps1 deleted file mode 100644 index c20e1b408096..000000000000 --- a/src/ServiceBus/ServiceBus.Autorest/custom/Get-AzServiceBusReadParameters.ps1 +++ /dev/null @@ -1,30 +0,0 @@ -function Get-AzServiceBusReadParameters { - [Microsoft.Azure.PowerShell.Cmdlets.ServiceBus.DoNotExportAttribute()] - [CmdletBinding()] - param( - [Parameter(Mandatory)] - [System.String] - ${CommandName}, - - [Parameter(Mandatory)] - [System.Collections.IDictionary] - ${BoundParameters} - ) - - $command = @(Get-Command -Name $CommandName -ErrorAction Stop)[0] - while ($command.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { - $command = Get-Command -Name $command.ResolvedCommandName -ErrorAction Stop - } - - $parameterNames = @($command.Parameters.Keys) - $parameterNames += @($command.Parameters.Values | ForEach-Object { $_.Aliases }) - - $readParameters = @{} - foreach ($parameter in $BoundParameters.GetEnumerator()) { - if ($parameter.Key -in $parameterNames) { - $readParameters[$parameter.Key] = $parameter.Value - } - } - - return $readParameters -} diff --git a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusAuthorizationRule.ps1 b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusAuthorizationRule.ps1 index b193cabf661d..145270521b15 100644 --- a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusAuthorizationRule.ps1 +++ b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusAuthorizationRule.ps1 @@ -162,17 +162,83 @@ function Set-AzServiceBusAuthorizationRule{ $null = $targetParameters.Remove('Confirm') if ($PSCmdlet.ParameterSetName -eq 'SetExpandedQueue'){ - $readParameters = Get-AzServiceBusReadParameters -CommandName 'Az.ServiceBus.private\Get-AzServiceBusQueueAuthorizationRule_Get' -BoundParameters $targetParameters + $readCommand = @(Get-Command -Name 'Az.ServiceBus.private\Get-AzServiceBusQueueAuthorizationRule_Get' -ErrorAction Stop)[0] + + while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { + + $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop + + } + + $readParameterNames = @($readCommand.Parameters.Keys) + + $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) + + $readParameters = @{} + + foreach ($parameter in $targetParameters.GetEnumerator()) { + + if ($parameter.Key -in $readParameterNames) { + + $readParameters[$parameter.Key] = $parameter.Value + + } + + } $authRule = Az.ServiceBus.private\Get-AzServiceBusQueueAuthorizationRule_Get @readParameters } elseif ($PSCmdlet.ParameterSetName -eq 'SetExpandedTopic'){ - $readParameters = Get-AzServiceBusReadParameters -CommandName 'Az.ServiceBus.private\Get-AzServiceBusTopicAuthorizationRule_Get' -BoundParameters $targetParameters + $readCommand = @(Get-Command -Name 'Az.ServiceBus.private\Get-AzServiceBusTopicAuthorizationRule_Get' -ErrorAction Stop)[0] + + while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { + + $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop + + } + + $readParameterNames = @($readCommand.Parameters.Keys) + + $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) + + $readParameters = @{} + + foreach ($parameter in $targetParameters.GetEnumerator()) { + + if ($parameter.Key -in $readParameterNames) { + + $readParameters[$parameter.Key] = $parameter.Value + + } + + } $authRule = Az.ServiceBus.private\Get-AzServiceBusTopicAuthorizationRule_Get @readParameters } elseif ($PSCmdlet.ParameterSetName -eq 'SetExpandedNamespace'){ - $readParameters = Get-AzServiceBusReadParameters -CommandName 'Az.ServiceBus.private\Get-AzServiceBusNamespaceAuthorizationRule_Get' -BoundParameters $targetParameters + $readCommand = @(Get-Command -Name 'Az.ServiceBus.private\Get-AzServiceBusNamespaceAuthorizationRule_Get' -ErrorAction Stop)[0] + + while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { + + $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop + + } + + $readParameterNames = @($readCommand.Parameters.Keys) + + $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) + + $readParameters = @{} + + foreach ($parameter in $targetParameters.GetEnumerator()) { + + if ($parameter.Key -in $readParameterNames) { + + $readParameters[$parameter.Key] = $parameter.Value + + } + + } $authRule = Az.ServiceBus.private\Get-AzServiceBusNamespaceAuthorizationRule_Get @readParameters } @@ -190,15 +256,81 @@ function Set-AzServiceBusAuthorizationRule{ } if ($ResourceHashTable['QueueName'] -ne $null){ - $readParameters = Get-AzServiceBusReadParameters -CommandName 'Az.ServiceBus.private\Get-AzServiceBusQueueAuthorizationRule_GetViaIdentity' -BoundParameters $targetParameters + $readCommand = @(Get-Command -Name 'Az.ServiceBus.private\Get-AzServiceBusQueueAuthorizationRule_GetViaIdentity' -ErrorAction Stop)[0] + + while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { + + $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop + + } + + $readParameterNames = @($readCommand.Parameters.Keys) + + $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) + + $readParameters = @{} + + foreach ($parameter in $targetParameters.GetEnumerator()) { + + if ($parameter.Key -in $readParameterNames) { + + $readParameters[$parameter.Key] = $parameter.Value + + } + + } $authRule = Az.ServiceBus.private\Get-AzServiceBusQueueAuthorizationRule_GetViaIdentity @readParameters } elseif ($ResourceHashTable['TopicName'] -ne $null){ - $readParameters = Get-AzServiceBusReadParameters -CommandName 'Az.ServiceBus.private\Get-AzServiceBusTopicAuthorizationRule_GetViaIdentity' -BoundParameters $targetParameters + $readCommand = @(Get-Command -Name 'Az.ServiceBus.private\Get-AzServiceBusTopicAuthorizationRule_GetViaIdentity' -ErrorAction Stop)[0] + + while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { + + $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop + + } + + $readParameterNames = @($readCommand.Parameters.Keys) + + $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) + + $readParameters = @{} + + foreach ($parameter in $targetParameters.GetEnumerator()) { + + if ($parameter.Key -in $readParameterNames) { + + $readParameters[$parameter.Key] = $parameter.Value + + } + + } $authRule = Az.ServiceBus.private\Get-AzServiceBusTopicAuthorizationRule_GetViaIdentity @readParameters } elseif ($ResourceHashTable['NamespaceName'] -ne $null){ - $readParameters = Get-AzServiceBusReadParameters -CommandName 'Az.ServiceBus.private\Get-AzServiceBusNamespaceAuthorizationRule_GetViaIdentity' -BoundParameters $targetParameters + $readCommand = @(Get-Command -Name 'Az.ServiceBus.private\Get-AzServiceBusNamespaceAuthorizationRule_GetViaIdentity' -ErrorAction Stop)[0] + + while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { + + $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop + + } + + $readParameterNames = @($readCommand.Parameters.Keys) + + $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) + + $readParameters = @{} + + foreach ($parameter in $targetParameters.GetEnumerator()) { + + if ($parameter.Key -in $readParameterNames) { + + $readParameters[$parameter.Key] = $parameter.Value + + } + + } $authRule = Az.ServiceBus.private\Get-AzServiceBusNamespaceAuthorizationRule_GetViaIdentity @readParameters } else{ diff --git a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusGeoDRConfigurationBreakPair.ps1 b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusGeoDRConfigurationBreakPair.ps1 index 892092d96bd0..094fa27239f9 100644 --- a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusGeoDRConfigurationBreakPair.ps1 +++ b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusGeoDRConfigurationBreakPair.ps1 @@ -133,7 +133,18 @@ function Set-AzServiceBusGeoDRConfigurationBreakPair{ $null = $targetParameters.Remove('WhatIf') $null = $targetParameters.Remove('Confirm') - $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusGeoDRConfiguration' -BoundParameters $targetParameters + $readCommand = @(Get-Command -Name 'Get-AzServiceBusGeoDRConfiguration' -ErrorAction Stop)[0] + while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { + $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop + } + $readParameterNames = @($readCommand.Parameters.Keys) + $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) + $readParameters = @{} + foreach ($parameter in $targetParameters.GetEnumerator()) { + if ($parameter.Key -in $readParameterNames) { + $readParameters[$parameter.Key] = $parameter.Value + } + } $drConfig = Get-AzServiceBusGeoDRConfiguration @readParameters # 2. PUT $null = $targetParameters.Remove('InputObject') diff --git a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusGeoDRConfigurationFailOver.ps1 b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusGeoDRConfigurationFailOver.ps1 index 50cc77b0bef6..077adfcab88d 100644 --- a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusGeoDRConfigurationFailOver.ps1 +++ b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusGeoDRConfigurationFailOver.ps1 @@ -133,7 +133,18 @@ function Set-AzServiceBusGeoDRConfigurationFailOver{ $null = $targetParameters.Remove('WhatIf') $null = $targetParameters.Remove('Confirm') - $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusGeoDRConfiguration' -BoundParameters $targetParameters + $readCommand = @(Get-Command -Name 'Get-AzServiceBusGeoDRConfiguration' -ErrorAction Stop)[0] + while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { + $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop + } + $readParameterNames = @($readCommand.Parameters.Keys) + $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) + $readParameters = @{} + foreach ($parameter in $targetParameters.GetEnumerator()) { + if ($parameter.Key -in $readParameterNames) { + $readParameters[$parameter.Key] = $parameter.Value + } + } $drConfig = Get-AzServiceBusGeoDRConfiguration @readParameters # 2. PUT $null = $targetParameters.Remove('InputObject') diff --git a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusNamespace.ps1 b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusNamespace.ps1 index e290bb0f6368..fa104f94b50a 100644 --- a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusNamespace.ps1 +++ b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusNamespace.ps1 @@ -212,7 +212,29 @@ function Set-AzServiceBusNamespace{ $hasNoWait = $targetParameters.Remove('NoWait') $null = $targetParameters.Remove('WhatIf') $null = $targetParameters.Remove('Confirm') - $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusNamespace' -BoundParameters $targetParameters + $readCommand = @(Get-Command -Name 'Get-AzServiceBusNamespace' -ErrorAction Stop)[0] + + while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { + + $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop + + } + + $readParameterNames = @($readCommand.Parameters.Keys) + + $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) + + $readParameters = @{} + + foreach ($parameter in $targetParameters.GetEnumerator()) { + + if ($parameter.Key -in $readParameterNames) { + + $readParameters[$parameter.Key] = $parameter.Value + + } + + } $serviceBusNamespace = Get-AzServiceBusNamespace @readParameters # 2. PUT $null = $targetParameters.Remove('InputObject') diff --git a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusNetworkRuleSet.ps1 b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusNetworkRuleSet.ps1 index 5b115f1cec04..4325ba5731a5 100644 --- a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusNetworkRuleSet.ps1 +++ b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusNetworkRuleSet.ps1 @@ -162,7 +162,18 @@ function Set-AzServiceBusNetworkRuleSet{ $null = $targetParameters.Remove('WhatIf') $null = $targetParameters.Remove('Confirm') - $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusNetworkRuleSet' -BoundParameters $targetParameters + $readCommand = @(Get-Command -Name 'Get-AzServiceBusNetworkRuleSet' -ErrorAction Stop)[0] + while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { + $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop + } + $readParameterNames = @($readCommand.Parameters.Keys) + $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) + $readParameters = @{} + foreach ($parameter in $targetParameters.GetEnumerator()) { + if ($parameter.Key -in $readParameterNames) { + $readParameters[$parameter.Key] = $parameter.Value + } + } $networkRuleSet = Get-AzServiceBusNetworkRuleSet @readParameters # 2. PUT $null = $targetParameters.Remove('InputObject') diff --git a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusQueue.ps1 b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusQueue.ps1 index 69de7d9fd02c..f1f27f4b32d9 100644 --- a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusQueue.ps1 +++ b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusQueue.ps1 @@ -231,7 +231,18 @@ function Set-AzServiceBusQueue{ $null = $targetParameters.Remove('WhatIf') $null = $targetParameters.Remove('Confirm') - $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusQueue' -BoundParameters $targetParameters + $readCommand = @(Get-Command -Name 'Get-AzServiceBusQueue' -ErrorAction Stop)[0] + while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { + $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop + } + $readParameterNames = @($readCommand.Parameters.Keys) + $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) + $readParameters = @{} + foreach ($parameter in $targetParameters.GetEnumerator()) { + if ($parameter.Key -in $readParameterNames) { + $readParameters[$parameter.Key] = $parameter.Value + } + } $queue = Get-AzServiceBusQueue @readParameters # 2. PUT $null = $targetParameters.Remove('InputObject') diff --git a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusRule.ps1 b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusRule.ps1 index d293c2132d22..5ee70fbcb698 100644 --- a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusRule.ps1 +++ b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusRule.ps1 @@ -248,7 +248,18 @@ function Set-AzServiceBusRule{ $hasActionSqlExpression = $targetParameters.Remove('ActionSqlExpression') $hasActionRequiresPreprocessing = $targetParameters.Remove('ActionRequiresPreprocessing') - $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusRule' -BoundParameters $targetParameters + $readCommand = @(Get-Command -Name 'Get-AzServiceBusRule' -ErrorAction Stop)[0] + while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { + $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop + } + $readParameterNames = @($readCommand.Parameters.Keys) + $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) + $readParameters = @{} + foreach ($parameter in $targetParameters.GetEnumerator()) { + if ($parameter.Key -in $readParameterNames) { + $readParameters[$parameter.Key] = $parameter.Value + } + } $rule = Get-AzServiceBusRule @readParameters # 2. PUT $null = $targetParameters.Remove('InputObject') diff --git a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusSubscription.ps1 b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusSubscription.ps1 index 0aa840643600..81b39cdf727b 100644 --- a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusSubscription.ps1 +++ b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusSubscription.ps1 @@ -218,7 +218,18 @@ function Set-AzServiceBusSubscription{ $null = $targetParameters.Remove('WhatIf') $null = $targetParameters.Remove('Confirm') - $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusSubscription' -BoundParameters $targetParameters + $readCommand = @(Get-Command -Name 'Get-AzServiceBusSubscription' -ErrorAction Stop)[0] + while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { + $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop + } + $readParameterNames = @($readCommand.Parameters.Keys) + $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) + $readParameters = @{} + foreach ($parameter in $targetParameters.GetEnumerator()) { + if ($parameter.Key -in $readParameterNames) { + $readParameters[$parameter.Key] = $parameter.Value + } + } $subscription = Get-AzServiceBusSubscription @readParameters # 2. PUT $null = $targetParameters.Remove('InputObject') diff --git a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusTopic.ps1 b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusTopic.ps1 index 69d96df36c4e..d39eb289b577 100644 --- a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusTopic.ps1 +++ b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusTopic.ps1 @@ -203,7 +203,18 @@ function Set-AzServiceBusTopic{ $null = $targetParameters.Remove('WhatIf') $null = $targetParameters.Remove('Confirm') - $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusTopic' -BoundParameters $targetParameters + $readCommand = @(Get-Command -Name 'Get-AzServiceBusTopic' -ErrorAction Stop)[0] + while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { + $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop + } + $readParameterNames = @($readCommand.Parameters.Keys) + $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) + $readParameters = @{} + foreach ($parameter in $targetParameters.GetEnumerator()) { + if ($parameter.Key -in $readParameterNames) { + $readParameters[$parameter.Key] = $parameter.Value + } + } $topic = Get-AzServiceBusTopic @readParameters # 2. PUT $null = $targetParameters.Remove('InputObject') diff --git a/src/ServiceBus/ServiceBus.Autorest/test/ReadParameterForwarding.Tests.ps1 b/src/ServiceBus/ServiceBus.Autorest/test/ReadParameterForwarding.Tests.ps1 index d86382d6c0e7..bea24f683850 100644 --- a/src/ServiceBus/ServiceBus.Autorest/test/ReadParameterForwarding.Tests.ps1 +++ b/src/ServiceBus/ServiceBus.Autorest/test/ReadParameterForwarding.Tests.ps1 @@ -1,8 +1,3 @@ -$helperPath = Join-Path $PSScriptRoot '..\custom\Get-AzServiceBusReadParameters.ps1' -$helperSource = Get-Content -Path $helperPath -Raw -$helperSource = $helperSource -replace '(?m)^\s*\[Microsoft\.Azure\.PowerShell\.Cmdlets\.ServiceBus\.DoNotExportAttribute\(\)\]\r?\n', '' -. ([scriptblock]::Create($helperSource)) - function Get-AzServiceBusReadTestResource { [CmdletBinding()] param( @@ -27,10 +22,30 @@ function Set-AzServiceBusReadTestResource { $script:serviceBusWriteParameters = @{} + $PSBoundParameters } -Set-Alias -Name Get-AzServiceBusReadTestAlias -Value Get-AzServiceBusReadTestResource +function Assert-InlineReadCommandsInvoked { + param([string] $Source) + + $lookupPattern = "(?ms)\`$readCommand\s*=\s*@\(Get-Command -Name '([^']+)'[^\r\n]*\)\[0\](?.*?)(?=\`$readCommand\s*=\s*@\(Get-Command -Name|\z)" + $lookups = [regex]::Matches($Source, $lookupPattern) + if ($lookups.Count -eq 0) { + return $false + } + + foreach ($lookup in $lookups) { + $commandName = $lookup.Groups[1].Value + $invocationPattern = '(?m)^\s*(?:\$\w+\s*=\s*)?' + [regex]::Escape($commandName) + '\s+@readParameters\s*$' + if (-not [regex]::IsMatch($lookup.Groups['Block'].Value, $invocationPattern)) { + return $false + } + } + + return $true +} + +Set-Alias -Name Get-AzServiceBusReadTestResourceAlias -Value Get-AzServiceBusReadTestResource -Describe 'ServiceBus read parameter forwarding' { - It 'filters write-only parameters using read command metadata without changing target parameters' { +Describe 'ServiceBus inline read parameter forwarding' { + It 'filters write-only parameters using aliased read command metadata without changing target parameters' { $targetParameters = @{ Name = 'queue' DefaultProfile = 'profile' @@ -40,7 +55,20 @@ Describe 'ServiceBus read parameter forwarding' { SyntheticWriteOnly = 'future-value' } - $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusReadTestAlias' -BoundParameters $targetParameters + $readCommand = @(Get-Command -Name 'Get-AzServiceBusReadTestResourceAlias' -ErrorAction Stop)[0] + while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { + $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop + } + $readParameterNames = @($readCommand.Parameters.Keys) + $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) + $readParameters = @{} + foreach ($parameter in $targetParameters.GetEnumerator()) { + if ($parameter.Key -in $readParameterNames) { + $readParameters[$parameter.Key] = $parameter.Value + } + } + + ($readParameterNames -contains 'ResourceName') | Should Be $true Get-AzServiceBusReadTestResource @readParameters Set-AzServiceBusReadTestResource @targetParameters @@ -55,13 +83,7 @@ Describe 'ServiceBus read parameter forwarding' { $script:serviceBusWriteParameters.SyntheticWriteOnly | Should Be 'future-value' } - It 'recognizes read parameter aliases' { - $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusReadTestResource' -BoundParameters @{ ResourceName = 'queue' } - - $readParameters.ResourceName | Should Be 'queue' - } - - It 'uses separate read and target parameter groups in every affected wrapper' { + It 'inlines metadata filtering with separate read and target parameters in every affected wrapper' { $wrappers = @( 'Approve-AzServiceBusPrivateEndpointConnection.ps1', 'Deny-AzServiceBusPrivateEndpointConnection.ps1', @@ -79,30 +101,40 @@ Describe 'ServiceBus read parameter forwarding' { foreach ($wrapper in $wrappers) { $source = Get-Content -Path (Join-Path $PSScriptRoot "..\custom\$wrapper") -Raw $source | Should Match '\$targetParameters\s*=\s*@\{\}\s*\+\s*\$PSBoundParameters' - $source | Should Match 'Get-AzServiceBusReadParameters\s+-CommandName' + $source | Should Match '\$readCommand\s*=\s*@\(Get-Command -Name' + $source | Should Match '\$readCommand\.CommandType.+CommandTypes\]::Alias' + $source | Should Match '\$readCommand\.Parameters\.Values.+\$_.Aliases' + $source | Should Match '\$readParameters\s*=\s*@\{\}' $source | Should Match '@readParameters' $source | Should Match '@targetParameters' + $source | Should Not Match 'Get-Az(?:EventHub|ServiceBus|NetworkSecurityPerimeter)ReadParameters' + (Assert-InlineReadCommandsInvoked -Source $source) | Should Be $true } } + It 'rejects a lookup followed by invocation of a different read command' { + $source = @' +$readCommand = @(Get-Command -Name 'Get-AzExpectedResource' -ErrorAction Stop)[0] +$readParameters = @{} +$resource = Get-AzDifferentResource @readParameters +'@ + + (Assert-InlineReadCommandsInvoked -Source $source) | Should Be $false + } + It 'keeps exact expanded and via-identity read variants for authorization rules' { $source = Get-Content -Path (Join-Path $PSScriptRoot '..\custom\Set-AzServiceBusAuthorizationRule.ps1') -Raw - $source | Should Match "CommandName 'Az\.ServiceBus\.private\\Get-AzServiceBusQueueAuthorizationRule_Get'" - $source | Should Match "CommandName 'Az\.ServiceBus\.private\\Get-AzServiceBusTopicAuthorizationRule_GetViaIdentity'" - $source | Should Match "CommandName 'Az\.ServiceBus\.private\\Get-AzServiceBusNamespaceAuthorizationRule_GetViaIdentity'" + $source | Should Match "Get-Command -Name 'Az.ServiceBus.private\\Get-AzServiceBusQueueAuthorizationRule_Get'" + $source | Should Match "Get-Command -Name 'Az.ServiceBus.private\\Get-AzServiceBusTopicAuthorizationRule_GetViaIdentity'" + $source | Should Match "Get-Command -Name 'Az.ServiceBus.private\\Get-AzServiceBusNamespaceAuthorizationRule_GetViaIdentity'" } - It 'packages the internal helper and triggers regeneration' { - $customPath = Join-Path $PSScriptRoot '..\custom' - $helperPath = Join-Path $customPath 'Get-AzServiceBusReadParameters.ps1' - $moduleSource = Get-Content -Path (Join-Path $customPath 'Az.ServiceBus.custom.psm1') -Raw - $helperSource = Get-Content -Path $helperPath -Raw + It 'has no helper source and retains the regeneration trigger' { + $helperPath = Join-Path $PSScriptRoot '..\custom\Get-AzServiceBusReadParameters.ps1' $generation = Get-Content -Path (Join-Path $PSScriptRoot '..\generate-info.json') -Raw | ConvertFrom-Json - Test-Path -Path $helperPath | Should Be $true - $helperSource | Should Match '\[Microsoft\.Azure\.PowerShell\.Cmdlets\.ServiceBus\.DoNotExportAttribute\(\)\]' - $moduleSource | Should Match "Get-ChildItem\s+-Path\s+\`$PSScriptRoot\s+-Recurse\s+-Include\s+'\*\.ps1'" + Test-Path -Path $helperPath | Should Be $false { [guid]::Parse($generation.generate_Id) } | Should Not Throw $generation.generate_Id | Should Not Be 'd42664e3-3ae4-4daf-a410-fba6f9958c4e' } From c80d943f872198b795e171e954f7d9b0d880b1b9 Mon Sep 17 00:00:00 2001 From: Yang An Date: Mon, 28 Sep 2026 14:53:56 +1000 Subject: [PATCH 03/12] Restore shared read parameter helpers Centralize command-metadata filtering per module to avoid duplicating the same read-parameter intersection at every read-modify-write call site. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- ...ve-AzEventHubPrivateEndpointConnection.ps1 | 13 +- ...ny-AzEventHubPrivateEndpointConnection.ps1 | 13 +- .../custom/Get-AzEventHubReadParameters.ps1 | 30 ++++ .../custom/Set-AzEventHub.ps1 | 13 +- .../custom/Set-AzEventHubApplicationGroup.ps1 | 13 +- .../Set-AzEventHubAuthorizationRule.ps1 | 96 +----------- .../custom/Set-AzEventHubCluster.ps1 | 13 +- .../custom/Set-AzEventHubConsumerGroup.ps1 | 13 +- ...-AzEventHubGeoDRConfigurationBreakPair.ps1 | 13 +- ...t-AzEventHubGeoDRConfigurationFailOver.ps1 | 13 +- .../custom/Set-AzEventHubNamespace.ps1 | 13 +- .../custom/Set-AzEventHubNetworkRuleSet.ps1 | 13 +- .../test/ReadParameterForwarding.Tests.ps1 | 88 ++++------- ...NetworkSecurityPerimeterReadParameters.ps1 | 30 ++++ ...e-AzNetworkSecurityPerimeterAccessRule.ps1 | 24 +-- ...-AzNetworkSecurityPerimeterAssociation.ps1 | 13 +- .../Update-AzNetworkSecurityPerimeterLink.ps1 | 13 +- ...kSecurityPerimeterLoggingConfiguration.ps1 | 13 +- .../test/ReadParameterForwarding.Tests.ps1 | 82 +++------- ...-AzServiceBusPrivateEndpointConnection.ps1 | 13 +- ...-AzServiceBusPrivateEndpointConnection.ps1 | 13 +- .../custom/Get-AzServiceBusReadParameters.ps1 | 30 ++++ .../Set-AzServiceBusAuthorizationRule.ps1 | 144 +----------------- ...zServiceBusGeoDRConfigurationBreakPair.ps1 | 13 +- ...AzServiceBusGeoDRConfigurationFailOver.ps1 | 13 +- .../custom/Set-AzServiceBusNamespace.ps1 | 24 +-- .../custom/Set-AzServiceBusNetworkRuleSet.ps1 | 13 +- .../custom/Set-AzServiceBusQueue.ps1 | 13 +- .../custom/Set-AzServiceBusRule.ps1 | 13 +- .../custom/Set-AzServiceBusSubscription.ps1 | 13 +- .../custom/Set-AzServiceBusTopic.ps1 | 13 +- .../test/ReadParameterForwarding.Tests.ps1 | 88 ++++------- 32 files changed, 205 insertions(+), 717 deletions(-) create mode 100644 src/EventHub/EventHub.Autorest/custom/Get-AzEventHubReadParameters.ps1 create mode 100644 src/Network/NetworkSecurityPerimeter.Autorest/custom/Get-AzNetworkSecurityPerimeterReadParameters.ps1 create mode 100644 src/ServiceBus/ServiceBus.Autorest/custom/Get-AzServiceBusReadParameters.ps1 diff --git a/src/EventHub/EventHub.Autorest/custom/Approve-AzEventHubPrivateEndpointConnection.ps1 b/src/EventHub/EventHub.Autorest/custom/Approve-AzEventHubPrivateEndpointConnection.ps1 index 31ba1b99c295..d6d8afa302d4 100644 --- a/src/EventHub/EventHub.Autorest/custom/Approve-AzEventHubPrivateEndpointConnection.ps1 +++ b/src/EventHub/EventHub.Autorest/custom/Approve-AzEventHubPrivateEndpointConnection.ps1 @@ -140,18 +140,7 @@ function Approve-AzEventHubPrivateEndpointConnection{ $null = $targetParameters.Remove('WhatIf') $null = $targetParameters.Remove('Confirm') - $readCommand = @(Get-Command -Name 'Get-AzEventHubPrivateEndpointConnection' -ErrorAction Stop)[0] - while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { - $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop - } - $readParameterNames = @($readCommand.Parameters.Keys) - $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) - $readParameters = @{} - foreach ($parameter in $targetParameters.GetEnumerator()) { - if ($parameter.Key -in $readParameterNames) { - $readParameters[$parameter.Key] = $parameter.Value - } - } + $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHubPrivateEndpointConnection' -BoundParameters $targetParameters $connection = Get-AzEventHubPrivateEndpointConnection @readParameters $connection.ConnectionState = "Approved" diff --git a/src/EventHub/EventHub.Autorest/custom/Deny-AzEventHubPrivateEndpointConnection.ps1 b/src/EventHub/EventHub.Autorest/custom/Deny-AzEventHubPrivateEndpointConnection.ps1 index 433b477fe68a..1c7f47e6a6b6 100644 --- a/src/EventHub/EventHub.Autorest/custom/Deny-AzEventHubPrivateEndpointConnection.ps1 +++ b/src/EventHub/EventHub.Autorest/custom/Deny-AzEventHubPrivateEndpointConnection.ps1 @@ -140,18 +140,7 @@ function Deny-AzEventHubPrivateEndpointConnection{ $null = $targetParameters.Remove('WhatIf') $null = $targetParameters.Remove('Confirm') - $readCommand = @(Get-Command -Name 'Get-AzEventHubPrivateEndpointConnection' -ErrorAction Stop)[0] - while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { - $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop - } - $readParameterNames = @($readCommand.Parameters.Keys) - $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) - $readParameters = @{} - foreach ($parameter in $targetParameters.GetEnumerator()) { - if ($parameter.Key -in $readParameterNames) { - $readParameters[$parameter.Key] = $parameter.Value - } - } + $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHubPrivateEndpointConnection' -BoundParameters $targetParameters $connection = Get-AzEventHubPrivateEndpointConnection @readParameters $connection.ConnectionState = "Rejected" diff --git a/src/EventHub/EventHub.Autorest/custom/Get-AzEventHubReadParameters.ps1 b/src/EventHub/EventHub.Autorest/custom/Get-AzEventHubReadParameters.ps1 new file mode 100644 index 000000000000..9871b7a8b785 --- /dev/null +++ b/src/EventHub/EventHub.Autorest/custom/Get-AzEventHubReadParameters.ps1 @@ -0,0 +1,30 @@ +function Get-AzEventHubReadParameters { + [Microsoft.Azure.PowerShell.Cmdlets.EventHub.DoNotExportAttribute()] + [CmdletBinding()] + param( + [Parameter(Mandatory)] + [System.String] + ${CommandName}, + + [Parameter(Mandatory)] + [System.Collections.IDictionary] + ${BoundParameters} + ) + + $command = @(Get-Command -Name $CommandName -ErrorAction Stop)[0] + while ($command.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { + $command = Get-Command -Name $command.ResolvedCommandName -ErrorAction Stop + } + + $parameterNames = @($command.Parameters.Keys) + $parameterNames += @($command.Parameters.Values | ForEach-Object { $_.Aliases }) + + $readParameters = @{} + foreach ($parameter in $BoundParameters.GetEnumerator()) { + if ($parameter.Key -in $parameterNames) { + $readParameters[$parameter.Key] = $parameter.Value + } + } + + return $readParameters +} diff --git a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHub.ps1 b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHub.ps1 index 1d45e65a130b..cc31843c25cf 100644 --- a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHub.ps1 +++ b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHub.ps1 @@ -258,18 +258,7 @@ function Set-AzEventHub{ $null = $targetParameters.Remove('WhatIf') $null = $targetParameters.Remove('Confirm') - $readCommand = @(Get-Command -Name 'Get-AzEventHub' -ErrorAction Stop)[0] - while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { - $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop - } - $readParameterNames = @($readCommand.Parameters.Keys) - $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) - $readParameters = @{} - foreach ($parameter in $targetParameters.GetEnumerator()) { - if ($parameter.Key -in $readParameterNames) { - $readParameters[$parameter.Key] = $parameter.Value - } - } + $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHub' -BoundParameters $targetParameters $eventHub = Get-AzEventHub @readParameters # 2. PUT $null = $targetParameters.Remove('InputObject') diff --git a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubApplicationGroup.ps1 b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubApplicationGroup.ps1 index 15ff09c98f06..de959fec3051 100644 --- a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubApplicationGroup.ps1 +++ b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubApplicationGroup.ps1 @@ -154,18 +154,7 @@ function Set-AzEventHubApplicationGroup{ $null = $targetParameters.Remove('WhatIf') $null = $targetParameters.Remove('Confirm') - $readCommand = @(Get-Command -Name 'Get-AzEventHubApplicationGroup' -ErrorAction Stop)[0] - while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { - $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop - } - $readParameterNames = @($readCommand.Parameters.Keys) - $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) - $readParameters = @{} - foreach ($parameter in $targetParameters.GetEnumerator()) { - if ($parameter.Key -in $readParameterNames) { - $readParameters[$parameter.Key] = $parameter.Value - } - } + $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHubApplicationGroup' -BoundParameters $targetParameters $appGroup = Get-AzEventHubApplicationGroup @readParameters # 2. PUT $null = $targetParameters.Remove('InputObject') diff --git a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubAuthorizationRule.ps1 b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubAuthorizationRule.ps1 index 7cbe165ad363..f92c0698cedb 100644 --- a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubAuthorizationRule.ps1 +++ b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubAuthorizationRule.ps1 @@ -152,56 +152,12 @@ function Set-AzEventHubAuthorizationRule{ $null = $targetParameters.Remove('Confirm') if ($PSCmdlet.ParameterSetName -eq 'SetExpandedNamespace'){ - $readCommand = @(Get-Command -Name 'Az.EventHub.private\Get-AzEventHubNamespaceAuthorizationRule_Get' -ErrorAction Stop)[0] - - while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { - - $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop - - } - - $readParameterNames = @($readCommand.Parameters.Keys) - - $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) - - $readParameters = @{} - - foreach ($parameter in $targetParameters.GetEnumerator()) { - - if ($parameter.Key -in $readParameterNames) { - - $readParameters[$parameter.Key] = $parameter.Value - - } - - } + $readParameters = Get-AzEventHubReadParameters -CommandName 'Az.EventHub.private\Get-AzEventHubNamespaceAuthorizationRule_Get' -BoundParameters $targetParameters $authRule = Az.EventHub.private\Get-AzEventHubNamespaceAuthorizationRule_Get @readParameters } elseif($PSCmdlet.ParameterSetName -eq 'SetExpandedEntity'){ - $readCommand = @(Get-Command -Name 'Az.EventHub.private\Get-AzEventHubAuthorizationRule_Get' -ErrorAction Stop)[0] - - while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { - - $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop - - } - - $readParameterNames = @($readCommand.Parameters.Keys) - - $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) - - $readParameters = @{} - - foreach ($parameter in $targetParameters.GetEnumerator()) { - - if ($parameter.Key -in $readParameterNames) { - - $readParameters[$parameter.Key] = $parameter.Value - - } - - } + $readParameters = Get-AzEventHubReadParameters -CommandName 'Az.EventHub.private\Get-AzEventHubAuthorizationRule_Get' -BoundParameters $targetParameters $authRule = Az.EventHub.private\Get-AzEventHubAuthorizationRule_Get @readParameters } @@ -213,55 +169,11 @@ function Set-AzEventHubAuthorizationRule{ $ResourceHashTable = ParseResourceId -ResourceId $InputObject } if ($ResourceHashTable['EventHubName'] -ne $null){ - $readCommand = @(Get-Command -Name 'Az.EventHub.private\Get-AzEventHubAuthorizationRule_GetViaIdentity' -ErrorAction Stop)[0] - - while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { - - $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop - - } - - $readParameterNames = @($readCommand.Parameters.Keys) - - $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) - - $readParameters = @{} - - foreach ($parameter in $targetParameters.GetEnumerator()) { - - if ($parameter.Key -in $readParameterNames) { - - $readParameters[$parameter.Key] = $parameter.Value - - } - - } + $readParameters = Get-AzEventHubReadParameters -CommandName 'Az.EventHub.private\Get-AzEventHubAuthorizationRule_GetViaIdentity' -BoundParameters $targetParameters $authRule = Az.EventHub.private\Get-AzEventHubAuthorizationRule_GetViaIdentity @readParameters } elseif ($ResourceHashTable['NamespaceName'] -ne $null){ - $readCommand = @(Get-Command -Name 'Az.EventHub.private\Get-AzEventHubNamespaceAuthorizationRule_GetViaIdentity' -ErrorAction Stop)[0] - - while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { - - $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop - - } - - $readParameterNames = @($readCommand.Parameters.Keys) - - $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) - - $readParameters = @{} - - foreach ($parameter in $targetParameters.GetEnumerator()) { - - if ($parameter.Key -in $readParameterNames) { - - $readParameters[$parameter.Key] = $parameter.Value - - } - - } + $readParameters = Get-AzEventHubReadParameters -CommandName 'Az.EventHub.private\Get-AzEventHubNamespaceAuthorizationRule_GetViaIdentity' -BoundParameters $targetParameters $authRule = Az.EventHub.private\Get-AzEventHubNamespaceAuthorizationRule_GetViaIdentity @readParameters } else{ diff --git a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubCluster.ps1 b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubCluster.ps1 index 2edc7e582290..3b5969ddef0a 100644 --- a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubCluster.ps1 +++ b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubCluster.ps1 @@ -142,18 +142,7 @@ function Set-AzEventHubCluster{ $null = $targetParameters.Remove('WhatIf') $null = $targetParameters.Remove('Confirm') - $readCommand = @(Get-Command -Name 'Get-AzEventHubCluster' -ErrorAction Stop)[0] - while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { - $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop - } - $readParameterNames = @($readCommand.Parameters.Keys) - $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) - $readParameters = @{} - foreach ($parameter in $targetParameters.GetEnumerator()) { - if ($parameter.Key -in $readParameterNames) { - $readParameters[$parameter.Key] = $parameter.Value - } - } + $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHubCluster' -BoundParameters $targetParameters $cluster = Get-AzEventHubCluster @readParameters # 2. PUT $null = $targetParameters.Remove('InputObject') diff --git a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubConsumerGroup.ps1 b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubConsumerGroup.ps1 index 33136f2ba1bc..a92141cbfd75 100644 --- a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubConsumerGroup.ps1 +++ b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubConsumerGroup.ps1 @@ -147,18 +147,7 @@ function Set-AzEventHubConsumerGroup{ $null = $targetParameters.Remove('WhatIf') $null = $targetParameters.Remove('Confirm') - $readCommand = @(Get-Command -Name 'Get-AzEventHubConsumerGroup' -ErrorAction Stop)[0] - while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { - $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop - } - $readParameterNames = @($readCommand.Parameters.Keys) - $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) - $readParameters = @{} - foreach ($parameter in $targetParameters.GetEnumerator()) { - if ($parameter.Key -in $readParameterNames) { - $readParameters[$parameter.Key] = $parameter.Value - } - } + $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHubConsumerGroup' -BoundParameters $targetParameters $consumerGroup = Get-AzEventHubConsumerGroup @readParameters # 2. PUT $null = $targetParameters.Remove('InputObject') diff --git a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubGeoDRConfigurationBreakPair.ps1 b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubGeoDRConfigurationBreakPair.ps1 index 6579a0d3f9cb..6e9642409fa5 100644 --- a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubGeoDRConfigurationBreakPair.ps1 +++ b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubGeoDRConfigurationBreakPair.ps1 @@ -132,18 +132,7 @@ function Set-AzEventHubGeoDRConfigurationBreakPair{ $null = $targetParameters.Remove('WhatIf') $null = $targetParameters.Remove('Confirm') - $readCommand = @(Get-Command -Name 'Get-AzEventHubGeoDRConfiguration' -ErrorAction Stop)[0] - while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { - $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop - } - $readParameterNames = @($readCommand.Parameters.Keys) - $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) - $readParameters = @{} - foreach ($parameter in $targetParameters.GetEnumerator()) { - if ($parameter.Key -in $readParameterNames) { - $readParameters[$parameter.Key] = $parameter.Value - } - } + $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHubGeoDRConfiguration' -BoundParameters $targetParameters $drConfig = Get-AzEventHubGeoDRConfiguration @readParameters # 2. PUT $null = $targetParameters.Remove('InputObject') diff --git a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubGeoDRConfigurationFailOver.ps1 b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubGeoDRConfigurationFailOver.ps1 index 32b2c5cf493b..22b3fc96b502 100644 --- a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubGeoDRConfigurationFailOver.ps1 +++ b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubGeoDRConfigurationFailOver.ps1 @@ -132,18 +132,7 @@ function Set-AzEventHubGeoDRConfigurationFailOver{ $null = $targetParameters.Remove('WhatIf') $null = $targetParameters.Remove('Confirm') - $readCommand = @(Get-Command -Name 'Get-AzEventHubGeoDRConfiguration' -ErrorAction Stop)[0] - while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { - $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop - } - $readParameterNames = @($readCommand.Parameters.Keys) - $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) - $readParameters = @{} - foreach ($parameter in $targetParameters.GetEnumerator()) { - if ($parameter.Key -in $readParameterNames) { - $readParameters[$parameter.Key] = $parameter.Value - } - } + $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHubGeoDRConfiguration' -BoundParameters $targetParameters $drConfig = Get-AzEventHubGeoDRConfiguration @readParameters # 2. PUT $null = $targetParameters.Remove('InputObject') diff --git a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubNamespace.ps1 b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubNamespace.ps1 index fc4eba0cb07a..a50c38fd8236 100644 --- a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubNamespace.ps1 +++ b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubNamespace.ps1 @@ -224,18 +224,7 @@ function Set-AzEventHubNamespace{ $null = $targetParameters.Remove('WhatIf') $null = $targetParameters.Remove('Confirm') - $readCommand = @(Get-Command -Name 'Get-AzEventHubNamespace' -ErrorAction Stop)[0] - while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { - $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop - } - $readParameterNames = @($readCommand.Parameters.Keys) - $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) - $readParameters = @{} - foreach ($parameter in $targetParameters.GetEnumerator()) { - if ($parameter.Key -in $readParameterNames) { - $readParameters[$parameter.Key] = $parameter.Value - } - } + $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHubNamespace' -BoundParameters $targetParameters $eventHubNamespace = Get-AzEventHubNamespace @readParameters # 2. PUT $null = $targetParameters.Remove('InputObject') diff --git a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubNetworkRuleSet.ps1 b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubNetworkRuleSet.ps1 index c6d399ad6e88..1918a8564909 100644 --- a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubNetworkRuleSet.ps1 +++ b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubNetworkRuleSet.ps1 @@ -162,18 +162,7 @@ function Set-AzEventHubNetworkRuleSet{ $null = $targetParameters.Remove('WhatIf') $null = $targetParameters.Remove('Confirm') - $readCommand = @(Get-Command -Name 'Get-AzEventHubNetworkRuleSet' -ErrorAction Stop)[0] - while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { - $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop - } - $readParameterNames = @($readCommand.Parameters.Keys) - $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) - $readParameters = @{} - foreach ($parameter in $targetParameters.GetEnumerator()) { - if ($parameter.Key -in $readParameterNames) { - $readParameters[$parameter.Key] = $parameter.Value - } - } + $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHubNetworkRuleSet' -BoundParameters $targetParameters $networkRuleSet = Get-AzEventHubNetworkRuleSet @readParameters # 2. PUT $null = $targetParameters.Remove('InputObject') diff --git a/src/EventHub/EventHub.Autorest/test/ReadParameterForwarding.Tests.ps1 b/src/EventHub/EventHub.Autorest/test/ReadParameterForwarding.Tests.ps1 index ebbbeae41aa1..507292ab582e 100644 --- a/src/EventHub/EventHub.Autorest/test/ReadParameterForwarding.Tests.ps1 +++ b/src/EventHub/EventHub.Autorest/test/ReadParameterForwarding.Tests.ps1 @@ -1,3 +1,8 @@ +$helperPath = Join-Path $PSScriptRoot '..\custom\Get-AzEventHubReadParameters.ps1' +$helperSource = Get-Content -Path $helperPath -Raw +$helperSource = $helperSource -replace '(?m)^\s*\[Microsoft\.Azure\.PowerShell\.Cmdlets\.EventHub\.DoNotExportAttribute\(\)\]\r?\n', '' +. ([scriptblock]::Create($helperSource)) + function Get-AzEventHubReadTestResource { [CmdletBinding()] param( @@ -22,30 +27,10 @@ function Set-AzEventHubReadTestResource { $script:eventHubWriteParameters = @{} + $PSBoundParameters } -function Assert-InlineReadCommandsInvoked { - param([string] $Source) - - $lookupPattern = "(?ms)\`$readCommand\s*=\s*@\(Get-Command -Name '([^']+)'[^\r\n]*\)\[0\](?.*?)(?=\`$readCommand\s*=\s*@\(Get-Command -Name|\z)" - $lookups = [regex]::Matches($Source, $lookupPattern) - if ($lookups.Count -eq 0) { - return $false - } - - foreach ($lookup in $lookups) { - $commandName = $lookup.Groups[1].Value - $invocationPattern = '(?m)^\s*(?:\$\w+\s*=\s*)?' + [regex]::Escape($commandName) + '\s+@readParameters\s*$' - if (-not [regex]::IsMatch($lookup.Groups['Block'].Value, $invocationPattern)) { - return $false - } - } - - return $true -} - -Set-Alias -Name Get-AzEventHubReadTestResourceAlias -Value Get-AzEventHubReadTestResource +Set-Alias -Name Get-AzEventHubReadTestAlias -Value Get-AzEventHubReadTestResource -Describe 'EventHub inline read parameter forwarding' { - It 'filters write-only parameters using aliased read command metadata without changing target parameters' { +Describe 'EventHub read parameter forwarding' { + It 'filters write-only parameters using read command metadata without changing target parameters' { $targetParameters = @{ Name = 'eventhub' DefaultProfile = 'profile' @@ -55,20 +40,7 @@ Describe 'EventHub inline read parameter forwarding' { SyntheticWriteOnly = 'future-value' } - $readCommand = @(Get-Command -Name 'Get-AzEventHubReadTestResourceAlias' -ErrorAction Stop)[0] - while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { - $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop - } - $readParameterNames = @($readCommand.Parameters.Keys) - $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) - $readParameters = @{} - foreach ($parameter in $targetParameters.GetEnumerator()) { - if ($parameter.Key -in $readParameterNames) { - $readParameters[$parameter.Key] = $parameter.Value - } - } - - ($readParameterNames -contains 'ResourceName') | Should Be $true + $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHubReadTestAlias' -BoundParameters $targetParameters Get-AzEventHubReadTestResource @readParameters Set-AzEventHubReadTestResource @targetParameters @@ -83,7 +55,13 @@ Describe 'EventHub inline read parameter forwarding' { $script:eventHubWriteParameters.SyntheticWriteOnly | Should Be 'future-value' } - It 'inlines metadata filtering with separate read and target parameters in every affected wrapper' { + It 'recognizes read parameter aliases' { + $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHubReadTestResource' -BoundParameters @{ ResourceName = 'eventhub' } + + $readParameters.ResourceName | Should Be 'eventhub' + } + + It 'uses separate read and target parameter groups in every affected wrapper' { $wrappers = @( 'Approve-AzEventHubPrivateEndpointConnection.ps1', 'Deny-AzEventHubPrivateEndpointConnection.ps1', @@ -101,40 +79,30 @@ Describe 'EventHub inline read parameter forwarding' { foreach ($wrapper in $wrappers) { $source = Get-Content -Path (Join-Path $PSScriptRoot "..\custom\$wrapper") -Raw $source | Should Match '\$targetParameters\s*=\s*@\{\}\s*\+\s*\$PSBoundParameters' - $source | Should Match '\$readCommand\s*=\s*@\(Get-Command -Name' - $source | Should Match '\$readCommand\.CommandType.+CommandTypes\]::Alias' - $source | Should Match '\$readCommand\.Parameters\.Values.+\$_.Aliases' - $source | Should Match '\$readParameters\s*=\s*@\{\}' + $source | Should Match 'Get-AzEventHubReadParameters\s+-CommandName' $source | Should Match '@readParameters' $source | Should Match '@targetParameters' - $source | Should Not Match 'Get-Az(?:EventHub|ServiceBus|NetworkSecurityPerimeter)ReadParameters' - (Assert-InlineReadCommandsInvoked -Source $source) | Should Be $true } } - It 'rejects a lookup followed by invocation of a different read command' { - $source = @' -$readCommand = @(Get-Command -Name 'Get-AzExpectedResource' -ErrorAction Stop)[0] -$readParameters = @{} -$resource = Get-AzDifferentResource @readParameters -'@ - - (Assert-InlineReadCommandsInvoked -Source $source) | Should Be $false - } - It 'keeps exact expanded and via-identity read variants for authorization rules' { $source = Get-Content -Path (Join-Path $PSScriptRoot '..\custom\Set-AzEventHubAuthorizationRule.ps1') -Raw - $source | Should Match "Get-Command -Name 'Az.EventHub.private\\Get-AzEventHubAuthorizationRule_Get'" - $source | Should Match "Get-Command -Name 'Az.EventHub.private\\Get-AzEventHubAuthorizationRule_GetViaIdentity'" - $source | Should Match "Get-Command -Name 'Az.EventHub.private\\Get-AzEventHubNamespaceAuthorizationRule_GetViaIdentity'" + $source | Should Match "CommandName 'Az\.EventHub\.private\\Get-AzEventHubAuthorizationRule_Get'" + $source | Should Match "CommandName 'Az\.EventHub\.private\\Get-AzEventHubAuthorizationRule_GetViaIdentity'" + $source | Should Match "CommandName 'Az\.EventHub\.private\\Get-AzEventHubNamespaceAuthorizationRule_GetViaIdentity'" } - It 'has no helper source and retains the regeneration trigger' { - $helperPath = Join-Path $PSScriptRoot '..\custom\Get-AzEventHubReadParameters.ps1' + It 'packages the internal helper and triggers regeneration' { + $customPath = Join-Path $PSScriptRoot '..\custom' + $helperPath = Join-Path $customPath 'Get-AzEventHubReadParameters.ps1' + $moduleSource = Get-Content -Path (Join-Path $customPath 'Az.EventHub.custom.psm1') -Raw + $helperSource = Get-Content -Path $helperPath -Raw $generation = Get-Content -Path (Join-Path $PSScriptRoot '..\generate-info.json') -Raw | ConvertFrom-Json - Test-Path -Path $helperPath | Should Be $false + Test-Path -Path $helperPath | Should Be $true + $helperSource | Should Match '\[Microsoft\.Azure\.PowerShell\.Cmdlets\.EventHub\.DoNotExportAttribute\(\)\]' + $moduleSource | Should Match "Get-ChildItem\s+-Path\s+\`$PSScriptRoot\s+-Recurse\s+-Include\s+'\*\.ps1'" { [guid]::Parse($generation.generate_Id) } | Should Not Throw $generation.generate_Id | Should Not Be '37e57dcc-9680-41ff-a019-ec549669f7b0' } diff --git a/src/Network/NetworkSecurityPerimeter.Autorest/custom/Get-AzNetworkSecurityPerimeterReadParameters.ps1 b/src/Network/NetworkSecurityPerimeter.Autorest/custom/Get-AzNetworkSecurityPerimeterReadParameters.ps1 new file mode 100644 index 000000000000..0e72e74dbfb8 --- /dev/null +++ b/src/Network/NetworkSecurityPerimeter.Autorest/custom/Get-AzNetworkSecurityPerimeterReadParameters.ps1 @@ -0,0 +1,30 @@ +function Get-AzNetworkSecurityPerimeterReadParameters { + [Microsoft.Azure.PowerShell.Cmdlets.NetworkSecurityPerimeter.DoNotExportAttribute()] + [CmdletBinding()] + param( + [Parameter(Mandatory)] + [System.String] + ${CommandName}, + + [Parameter(Mandatory)] + [System.Collections.IDictionary] + ${BoundParameters} + ) + + $command = @(Get-Command -Name $CommandName -ErrorAction Stop)[0] + while ($command.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { + $command = Get-Command -Name $command.ResolvedCommandName -ErrorAction Stop + } + + $parameterNames = @($command.Parameters.Keys) + $parameterNames += @($command.Parameters.Values | ForEach-Object { $_.Aliases }) + + $readParameters = @{} + foreach ($parameter in $BoundParameters.GetEnumerator()) { + if ($parameter.Key -in $parameterNames) { + $readParameters[$parameter.Key] = $parameter.Value + } + } + + return $readParameters +} diff --git a/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterAccessRule.ps1 b/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterAccessRule.ps1 index f9da3f598172..93ee0ce91e49 100644 --- a/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterAccessRule.ps1 +++ b/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterAccessRule.ps1 @@ -215,29 +215,7 @@ function Update-AzNetworkSecurityPerimeterAccessRule { $null = $targetParameters.Remove('Confirm') - $readCommand = @(Get-Command -Name 'Get-AzNetworkSecurityPerimeterAccessRule' -ErrorAction Stop)[0] - - while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { - - $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop - - } - - $readParameterNames = @($readCommand.Parameters.Keys) - - $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) - - $readParameters = @{} - - foreach ($parameter in $targetParameters.GetEnumerator()) { - - if ($parameter.Key -in $readParameterNames) { - - $readParameters[$parameter.Key] = $parameter.Value - - } - - } + $readParameters = Get-AzNetworkSecurityPerimeterReadParameters -CommandName 'Get-AzNetworkSecurityPerimeterAccessRule' -BoundParameters $targetParameters $GETObject = Get-AzNetworkSecurityPerimeterAccessRule @readParameters # 2. PUT diff --git a/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterAssociation.ps1 b/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterAssociation.ps1 index 119703f59269..e2d2bbbf02d4 100644 --- a/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterAssociation.ps1 +++ b/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterAssociation.ps1 @@ -183,18 +183,7 @@ function Update-AzNetworkSecurityPerimeterAssociation { $null = $targetParameters.Remove('WhatIf') $null = $targetParameters.Remove('Confirm') - $readCommand = @(Get-Command -Name 'Get-AzNetworkSecurityPerimeterAssociation' -ErrorAction Stop)[0] - while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { - $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop - } - $readParameterNames = @($readCommand.Parameters.Keys) - $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) - $readParameters = @{} - foreach ($parameter in $targetParameters.GetEnumerator()) { - if ($parameter.Key -in $readParameterNames) { - $readParameters[$parameter.Key] = $parameter.Value - } - } + $readParameters = Get-AzNetworkSecurityPerimeterReadParameters -CommandName 'Get-AzNetworkSecurityPerimeterAssociation' -BoundParameters $targetParameters $GETObject = Get-AzNetworkSecurityPerimeterAssociation @readParameters # 2. PUT diff --git a/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterLink.ps1 b/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterLink.ps1 index 6ed0fe410658..d9199705f158 100644 --- a/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterLink.ps1 +++ b/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterLink.ps1 @@ -184,18 +184,7 @@ function Update-AzNetworkSecurityPerimeterLink { $null = $targetParameters.Remove('WhatIf') $null = $targetParameters.Remove('Confirm') - $readCommand = @(Get-Command -Name 'Get-AzNetworkSecurityPerimeterLink' -ErrorAction Stop)[0] - while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { - $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop - } - $readParameterNames = @($readCommand.Parameters.Keys) - $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) - $readParameters = @{} - foreach ($parameter in $targetParameters.GetEnumerator()) { - if ($parameter.Key -in $readParameterNames) { - $readParameters[$parameter.Key] = $parameter.Value - } - } + $readParameters = Get-AzNetworkSecurityPerimeterReadParameters -CommandName 'Get-AzNetworkSecurityPerimeterLink' -BoundParameters $targetParameters $GETObject = Get-AzNetworkSecurityPerimeterLink @readParameters # 2. PUT diff --git a/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterLoggingConfiguration.ps1 b/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterLoggingConfiguration.ps1 index d98630d107d3..75c21bea806e 100644 --- a/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterLoggingConfiguration.ps1 +++ b/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterLoggingConfiguration.ps1 @@ -172,18 +172,7 @@ function Update-AzNetworkSecurityPerimeterLoggingConfiguration { $null = $targetParameters.Remove('WhatIf') $null = $targetParameters.Remove('Confirm') - $readCommand = @(Get-Command -Name 'Get-AzNetworkSecurityPerimeterLoggingConfiguration' -ErrorAction Stop)[0] - while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { - $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop - } - $readParameterNames = @($readCommand.Parameters.Keys) - $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) - $readParameters = @{} - foreach ($parameter in $targetParameters.GetEnumerator()) { - if ($parameter.Key -in $readParameterNames) { - $readParameters[$parameter.Key] = $parameter.Value - } - } + $readParameters = Get-AzNetworkSecurityPerimeterReadParameters -CommandName 'Get-AzNetworkSecurityPerimeterLoggingConfiguration' -BoundParameters $targetParameters $GETObject = Get-AzNetworkSecurityPerimeterLoggingConfiguration @readParameters # 2. PUT diff --git a/src/Network/NetworkSecurityPerimeter.Autorest/test/ReadParameterForwarding.Tests.ps1 b/src/Network/NetworkSecurityPerimeter.Autorest/test/ReadParameterForwarding.Tests.ps1 index 43657949417b..74b020b57a15 100644 --- a/src/Network/NetworkSecurityPerimeter.Autorest/test/ReadParameterForwarding.Tests.ps1 +++ b/src/Network/NetworkSecurityPerimeter.Autorest/test/ReadParameterForwarding.Tests.ps1 @@ -1,3 +1,8 @@ +$helperPath = Join-Path $PSScriptRoot '..\custom\Get-AzNetworkSecurityPerimeterReadParameters.ps1' +$helperSource = Get-Content -Path $helperPath -Raw +$helperSource = $helperSource -replace '(?m)^\s*\[Microsoft\.Azure\.PowerShell\.Cmdlets\.NetworkSecurityPerimeter\.DoNotExportAttribute\(\)\]\r?\n', '' +. ([scriptblock]::Create($helperSource)) + function Get-AzNetworkSecurityPerimeterReadTestResource { [CmdletBinding()] param( @@ -22,30 +27,10 @@ function Set-AzNetworkSecurityPerimeterReadTestResource { $script:nspWriteParameters = @{} + $PSBoundParameters } -function Assert-InlineReadCommandsInvoked { - param([string] $Source) - - $lookupPattern = "(?ms)\`$readCommand\s*=\s*@\(Get-Command -Name '([^']+)'[^\r\n]*\)\[0\](?.*?)(?=\`$readCommand\s*=\s*@\(Get-Command -Name|\z)" - $lookups = [regex]::Matches($Source, $lookupPattern) - if ($lookups.Count -eq 0) { - return $false - } - - foreach ($lookup in $lookups) { - $commandName = $lookup.Groups[1].Value - $invocationPattern = '(?m)^\s*(?:\$\w+\s*=\s*)?' + [regex]::Escape($commandName) + '\s+@readParameters\s*$' - if (-not [regex]::IsMatch($lookup.Groups['Block'].Value, $invocationPattern)) { - return $false - } - } - - return $true -} - -Set-Alias -Name Get-AzNetworkSecurityPerimeterReadTestResourceAlias -Value Get-AzNetworkSecurityPerimeterReadTestResource +Set-Alias -Name Get-AzNetworkSecurityPerimeterReadTestAlias -Value Get-AzNetworkSecurityPerimeterReadTestResource -Describe 'NetworkSecurityPerimeter inline read parameter forwarding' { - It 'filters write-only parameters using aliased read command metadata without changing target parameters' { +Describe 'NetworkSecurityPerimeter read parameter forwarding' { + It 'filters write-only parameters using read command metadata without changing target parameters' { $targetParameters = @{ Name = 'access-rule' DefaultProfile = 'profile' @@ -55,20 +40,7 @@ Describe 'NetworkSecurityPerimeter inline read parameter forwarding' { SyntheticWriteOnly = 'future-value' } - $readCommand = @(Get-Command -Name 'Get-AzNetworkSecurityPerimeterReadTestResourceAlias' -ErrorAction Stop)[0] - while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { - $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop - } - $readParameterNames = @($readCommand.Parameters.Keys) - $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) - $readParameters = @{} - foreach ($parameter in $targetParameters.GetEnumerator()) { - if ($parameter.Key -in $readParameterNames) { - $readParameters[$parameter.Key] = $parameter.Value - } - } - - ($readParameterNames -contains 'ResourceName') | Should Be $true + $readParameters = Get-AzNetworkSecurityPerimeterReadParameters -CommandName 'Get-AzNetworkSecurityPerimeterReadTestAlias' -BoundParameters $targetParameters Get-AzNetworkSecurityPerimeterReadTestResource @readParameters Set-AzNetworkSecurityPerimeterReadTestResource @targetParameters @@ -83,7 +55,13 @@ Describe 'NetworkSecurityPerimeter inline read parameter forwarding' { $script:nspWriteParameters.SyntheticWriteOnly | Should Be 'future-value' } - It 'inlines metadata filtering with separate read and target parameters in every affected wrapper' { + It 'recognizes read parameter aliases' { + $readParameters = Get-AzNetworkSecurityPerimeterReadParameters -CommandName 'Get-AzNetworkSecurityPerimeterReadTestResource' -BoundParameters @{ ResourceName = 'access-rule' } + + $readParameters.ResourceName | Should Be 'access-rule' + } + + It 'uses separate read and target parameter groups in every affected wrapper' { $wrappers = @( 'Update-AzNetworkSecurityPerimeterAccessRule.ps1', 'Update-AzNetworkSecurityPerimeterAssociation.ps1', @@ -94,32 +72,22 @@ Describe 'NetworkSecurityPerimeter inline read parameter forwarding' { foreach ($wrapper in $wrappers) { $source = Get-Content -Path (Join-Path $PSScriptRoot "..\custom\$wrapper") -Raw $source | Should Match '\$targetParameters\s*=\s*@\{\}\s*\+\s*\$PSBoundParameters' - $source | Should Match '\$readCommand\s*=\s*@\(Get-Command -Name' - $source | Should Match '\$readCommand\.CommandType.+CommandTypes\]::Alias' - $source | Should Match '\$readCommand\.Parameters\.Values.+\$_.Aliases' - $source | Should Match '\$readParameters\s*=\s*@\{\}' + $source | Should Match 'Get-AzNetworkSecurityPerimeterReadParameters\s+-CommandName' $source | Should Match '@readParameters' $source | Should Match '@targetParameters' - $source | Should Not Match 'Get-Az(?:EventHub|ServiceBus|NetworkSecurityPerimeter)ReadParameters' - (Assert-InlineReadCommandsInvoked -Source $source) | Should Be $true } } - It 'rejects a lookup followed by invocation of a different read command' { - $source = @' -$readCommand = @(Get-Command -Name 'Get-AzExpectedResource' -ErrorAction Stop)[0] -$readParameters = @{} -$resource = Get-AzDifferentResource @readParameters -'@ - - (Assert-InlineReadCommandsInvoked -Source $source) | Should Be $false - } - - It 'has no helper source and retains the regeneration trigger' { - $helperPath = Join-Path $PSScriptRoot '..\custom\Get-AzNetworkSecurityPerimeterReadParameters.ps1' + It 'packages the internal helper and triggers regeneration' { + $customPath = Join-Path $PSScriptRoot '..\custom' + $helperPath = Join-Path $customPath 'Get-AzNetworkSecurityPerimeterReadParameters.ps1' + $moduleSource = Get-Content -Path (Join-Path $customPath 'Az.NetworkSecurityPerimeter.custom.psm1') -Raw + $helperSource = Get-Content -Path $helperPath -Raw $generation = Get-Content -Path (Join-Path $PSScriptRoot '..\generate-info.json') -Raw | ConvertFrom-Json - Test-Path -Path $helperPath | Should Be $false + Test-Path -Path $helperPath | Should Be $true + $helperSource | Should Match '\[Microsoft\.Azure\.PowerShell\.Cmdlets\.NetworkSecurityPerimeter\.DoNotExportAttribute\(\)\]' + $moduleSource | Should Match "Get-ChildItem\s+-Path\s+\`$PSScriptRoot\s+-Recurse\s+-Include\s+'\*\.ps1'" { [guid]::Parse($generation.generate_Id) } | Should Not Throw $generation.generate_Id | Should Not Be '22876a3f-6f36-449b-a291-2b1c423db247' } diff --git a/src/ServiceBus/ServiceBus.Autorest/custom/Approve-AzServiceBusPrivateEndpointConnection.ps1 b/src/ServiceBus/ServiceBus.Autorest/custom/Approve-AzServiceBusPrivateEndpointConnection.ps1 index aabb68a1ce4a..3040099f93f8 100644 --- a/src/ServiceBus/ServiceBus.Autorest/custom/Approve-AzServiceBusPrivateEndpointConnection.ps1 +++ b/src/ServiceBus/ServiceBus.Autorest/custom/Approve-AzServiceBusPrivateEndpointConnection.ps1 @@ -141,18 +141,7 @@ function Approve-AzServiceBusPrivateEndpointConnection{ $null = $targetParameters.Remove('WhatIf') $null = $targetParameters.Remove('Confirm') - $readCommand = @(Get-Command -Name 'Get-AzServiceBusPrivateEndpointConnection' -ErrorAction Stop)[0] - while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { - $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop - } - $readParameterNames = @($readCommand.Parameters.Keys) - $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) - $readParameters = @{} - foreach ($parameter in $targetParameters.GetEnumerator()) { - if ($parameter.Key -in $readParameterNames) { - $readParameters[$parameter.Key] = $parameter.Value - } - } + $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusPrivateEndpointConnection' -BoundParameters $targetParameters $connection = Get-AzServiceBusPrivateEndpointConnection @readParameters $connection.ConnectionState = "Approved" diff --git a/src/ServiceBus/ServiceBus.Autorest/custom/Deny-AzServiceBusPrivateEndpointConnection.ps1 b/src/ServiceBus/ServiceBus.Autorest/custom/Deny-AzServiceBusPrivateEndpointConnection.ps1 index 2c361ee9a2a3..dbef3e27adf8 100644 --- a/src/ServiceBus/ServiceBus.Autorest/custom/Deny-AzServiceBusPrivateEndpointConnection.ps1 +++ b/src/ServiceBus/ServiceBus.Autorest/custom/Deny-AzServiceBusPrivateEndpointConnection.ps1 @@ -141,18 +141,7 @@ function Deny-AzServiceBusPrivateEndpointConnection{ $null = $targetParameters.Remove('WhatIf') $null = $targetParameters.Remove('Confirm') - $readCommand = @(Get-Command -Name 'Get-AzServiceBusPrivateEndpointConnection' -ErrorAction Stop)[0] - while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { - $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop - } - $readParameterNames = @($readCommand.Parameters.Keys) - $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) - $readParameters = @{} - foreach ($parameter in $targetParameters.GetEnumerator()) { - if ($parameter.Key -in $readParameterNames) { - $readParameters[$parameter.Key] = $parameter.Value - } - } + $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusPrivateEndpointConnection' -BoundParameters $targetParameters $connection = Get-AzServiceBusPrivateEndpointConnection @readParameters $connection.ConnectionState = "Rejected" diff --git a/src/ServiceBus/ServiceBus.Autorest/custom/Get-AzServiceBusReadParameters.ps1 b/src/ServiceBus/ServiceBus.Autorest/custom/Get-AzServiceBusReadParameters.ps1 new file mode 100644 index 000000000000..c20e1b408096 --- /dev/null +++ b/src/ServiceBus/ServiceBus.Autorest/custom/Get-AzServiceBusReadParameters.ps1 @@ -0,0 +1,30 @@ +function Get-AzServiceBusReadParameters { + [Microsoft.Azure.PowerShell.Cmdlets.ServiceBus.DoNotExportAttribute()] + [CmdletBinding()] + param( + [Parameter(Mandatory)] + [System.String] + ${CommandName}, + + [Parameter(Mandatory)] + [System.Collections.IDictionary] + ${BoundParameters} + ) + + $command = @(Get-Command -Name $CommandName -ErrorAction Stop)[0] + while ($command.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { + $command = Get-Command -Name $command.ResolvedCommandName -ErrorAction Stop + } + + $parameterNames = @($command.Parameters.Keys) + $parameterNames += @($command.Parameters.Values | ForEach-Object { $_.Aliases }) + + $readParameters = @{} + foreach ($parameter in $BoundParameters.GetEnumerator()) { + if ($parameter.Key -in $parameterNames) { + $readParameters[$parameter.Key] = $parameter.Value + } + } + + return $readParameters +} diff --git a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusAuthorizationRule.ps1 b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusAuthorizationRule.ps1 index 145270521b15..b193cabf661d 100644 --- a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusAuthorizationRule.ps1 +++ b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusAuthorizationRule.ps1 @@ -162,83 +162,17 @@ function Set-AzServiceBusAuthorizationRule{ $null = $targetParameters.Remove('Confirm') if ($PSCmdlet.ParameterSetName -eq 'SetExpandedQueue'){ - $readCommand = @(Get-Command -Name 'Az.ServiceBus.private\Get-AzServiceBusQueueAuthorizationRule_Get' -ErrorAction Stop)[0] - - while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { - - $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop - - } - - $readParameterNames = @($readCommand.Parameters.Keys) - - $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) - - $readParameters = @{} - - foreach ($parameter in $targetParameters.GetEnumerator()) { - - if ($parameter.Key -in $readParameterNames) { - - $readParameters[$parameter.Key] = $parameter.Value - - } - - } + $readParameters = Get-AzServiceBusReadParameters -CommandName 'Az.ServiceBus.private\Get-AzServiceBusQueueAuthorizationRule_Get' -BoundParameters $targetParameters $authRule = Az.ServiceBus.private\Get-AzServiceBusQueueAuthorizationRule_Get @readParameters } elseif ($PSCmdlet.ParameterSetName -eq 'SetExpandedTopic'){ - $readCommand = @(Get-Command -Name 'Az.ServiceBus.private\Get-AzServiceBusTopicAuthorizationRule_Get' -ErrorAction Stop)[0] - - while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { - - $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop - - } - - $readParameterNames = @($readCommand.Parameters.Keys) - - $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) - - $readParameters = @{} - - foreach ($parameter in $targetParameters.GetEnumerator()) { - - if ($parameter.Key -in $readParameterNames) { - - $readParameters[$parameter.Key] = $parameter.Value - - } - - } + $readParameters = Get-AzServiceBusReadParameters -CommandName 'Az.ServiceBus.private\Get-AzServiceBusTopicAuthorizationRule_Get' -BoundParameters $targetParameters $authRule = Az.ServiceBus.private\Get-AzServiceBusTopicAuthorizationRule_Get @readParameters } elseif ($PSCmdlet.ParameterSetName -eq 'SetExpandedNamespace'){ - $readCommand = @(Get-Command -Name 'Az.ServiceBus.private\Get-AzServiceBusNamespaceAuthorizationRule_Get' -ErrorAction Stop)[0] - - while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { - - $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop - - } - - $readParameterNames = @($readCommand.Parameters.Keys) - - $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) - - $readParameters = @{} - - foreach ($parameter in $targetParameters.GetEnumerator()) { - - if ($parameter.Key -in $readParameterNames) { - - $readParameters[$parameter.Key] = $parameter.Value - - } - - } + $readParameters = Get-AzServiceBusReadParameters -CommandName 'Az.ServiceBus.private\Get-AzServiceBusNamespaceAuthorizationRule_Get' -BoundParameters $targetParameters $authRule = Az.ServiceBus.private\Get-AzServiceBusNamespaceAuthorizationRule_Get @readParameters } @@ -256,81 +190,15 @@ function Set-AzServiceBusAuthorizationRule{ } if ($ResourceHashTable['QueueName'] -ne $null){ - $readCommand = @(Get-Command -Name 'Az.ServiceBus.private\Get-AzServiceBusQueueAuthorizationRule_GetViaIdentity' -ErrorAction Stop)[0] - - while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { - - $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop - - } - - $readParameterNames = @($readCommand.Parameters.Keys) - - $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) - - $readParameters = @{} - - foreach ($parameter in $targetParameters.GetEnumerator()) { - - if ($parameter.Key -in $readParameterNames) { - - $readParameters[$parameter.Key] = $parameter.Value - - } - - } + $readParameters = Get-AzServiceBusReadParameters -CommandName 'Az.ServiceBus.private\Get-AzServiceBusQueueAuthorizationRule_GetViaIdentity' -BoundParameters $targetParameters $authRule = Az.ServiceBus.private\Get-AzServiceBusQueueAuthorizationRule_GetViaIdentity @readParameters } elseif ($ResourceHashTable['TopicName'] -ne $null){ - $readCommand = @(Get-Command -Name 'Az.ServiceBus.private\Get-AzServiceBusTopicAuthorizationRule_GetViaIdentity' -ErrorAction Stop)[0] - - while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { - - $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop - - } - - $readParameterNames = @($readCommand.Parameters.Keys) - - $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) - - $readParameters = @{} - - foreach ($parameter in $targetParameters.GetEnumerator()) { - - if ($parameter.Key -in $readParameterNames) { - - $readParameters[$parameter.Key] = $parameter.Value - - } - - } + $readParameters = Get-AzServiceBusReadParameters -CommandName 'Az.ServiceBus.private\Get-AzServiceBusTopicAuthorizationRule_GetViaIdentity' -BoundParameters $targetParameters $authRule = Az.ServiceBus.private\Get-AzServiceBusTopicAuthorizationRule_GetViaIdentity @readParameters } elseif ($ResourceHashTable['NamespaceName'] -ne $null){ - $readCommand = @(Get-Command -Name 'Az.ServiceBus.private\Get-AzServiceBusNamespaceAuthorizationRule_GetViaIdentity' -ErrorAction Stop)[0] - - while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { - - $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop - - } - - $readParameterNames = @($readCommand.Parameters.Keys) - - $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) - - $readParameters = @{} - - foreach ($parameter in $targetParameters.GetEnumerator()) { - - if ($parameter.Key -in $readParameterNames) { - - $readParameters[$parameter.Key] = $parameter.Value - - } - - } + $readParameters = Get-AzServiceBusReadParameters -CommandName 'Az.ServiceBus.private\Get-AzServiceBusNamespaceAuthorizationRule_GetViaIdentity' -BoundParameters $targetParameters $authRule = Az.ServiceBus.private\Get-AzServiceBusNamespaceAuthorizationRule_GetViaIdentity @readParameters } else{ diff --git a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusGeoDRConfigurationBreakPair.ps1 b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusGeoDRConfigurationBreakPair.ps1 index 094fa27239f9..892092d96bd0 100644 --- a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusGeoDRConfigurationBreakPair.ps1 +++ b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusGeoDRConfigurationBreakPair.ps1 @@ -133,18 +133,7 @@ function Set-AzServiceBusGeoDRConfigurationBreakPair{ $null = $targetParameters.Remove('WhatIf') $null = $targetParameters.Remove('Confirm') - $readCommand = @(Get-Command -Name 'Get-AzServiceBusGeoDRConfiguration' -ErrorAction Stop)[0] - while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { - $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop - } - $readParameterNames = @($readCommand.Parameters.Keys) - $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) - $readParameters = @{} - foreach ($parameter in $targetParameters.GetEnumerator()) { - if ($parameter.Key -in $readParameterNames) { - $readParameters[$parameter.Key] = $parameter.Value - } - } + $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusGeoDRConfiguration' -BoundParameters $targetParameters $drConfig = Get-AzServiceBusGeoDRConfiguration @readParameters # 2. PUT $null = $targetParameters.Remove('InputObject') diff --git a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusGeoDRConfigurationFailOver.ps1 b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusGeoDRConfigurationFailOver.ps1 index 077adfcab88d..50cc77b0bef6 100644 --- a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusGeoDRConfigurationFailOver.ps1 +++ b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusGeoDRConfigurationFailOver.ps1 @@ -133,18 +133,7 @@ function Set-AzServiceBusGeoDRConfigurationFailOver{ $null = $targetParameters.Remove('WhatIf') $null = $targetParameters.Remove('Confirm') - $readCommand = @(Get-Command -Name 'Get-AzServiceBusGeoDRConfiguration' -ErrorAction Stop)[0] - while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { - $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop - } - $readParameterNames = @($readCommand.Parameters.Keys) - $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) - $readParameters = @{} - foreach ($parameter in $targetParameters.GetEnumerator()) { - if ($parameter.Key -in $readParameterNames) { - $readParameters[$parameter.Key] = $parameter.Value - } - } + $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusGeoDRConfiguration' -BoundParameters $targetParameters $drConfig = Get-AzServiceBusGeoDRConfiguration @readParameters # 2. PUT $null = $targetParameters.Remove('InputObject') diff --git a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusNamespace.ps1 b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusNamespace.ps1 index fa104f94b50a..e290bb0f6368 100644 --- a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusNamespace.ps1 +++ b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusNamespace.ps1 @@ -212,29 +212,7 @@ function Set-AzServiceBusNamespace{ $hasNoWait = $targetParameters.Remove('NoWait') $null = $targetParameters.Remove('WhatIf') $null = $targetParameters.Remove('Confirm') - $readCommand = @(Get-Command -Name 'Get-AzServiceBusNamespace' -ErrorAction Stop)[0] - - while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { - - $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop - - } - - $readParameterNames = @($readCommand.Parameters.Keys) - - $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) - - $readParameters = @{} - - foreach ($parameter in $targetParameters.GetEnumerator()) { - - if ($parameter.Key -in $readParameterNames) { - - $readParameters[$parameter.Key] = $parameter.Value - - } - - } + $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusNamespace' -BoundParameters $targetParameters $serviceBusNamespace = Get-AzServiceBusNamespace @readParameters # 2. PUT $null = $targetParameters.Remove('InputObject') diff --git a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusNetworkRuleSet.ps1 b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusNetworkRuleSet.ps1 index 4325ba5731a5..5b115f1cec04 100644 --- a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusNetworkRuleSet.ps1 +++ b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusNetworkRuleSet.ps1 @@ -162,18 +162,7 @@ function Set-AzServiceBusNetworkRuleSet{ $null = $targetParameters.Remove('WhatIf') $null = $targetParameters.Remove('Confirm') - $readCommand = @(Get-Command -Name 'Get-AzServiceBusNetworkRuleSet' -ErrorAction Stop)[0] - while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { - $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop - } - $readParameterNames = @($readCommand.Parameters.Keys) - $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) - $readParameters = @{} - foreach ($parameter in $targetParameters.GetEnumerator()) { - if ($parameter.Key -in $readParameterNames) { - $readParameters[$parameter.Key] = $parameter.Value - } - } + $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusNetworkRuleSet' -BoundParameters $targetParameters $networkRuleSet = Get-AzServiceBusNetworkRuleSet @readParameters # 2. PUT $null = $targetParameters.Remove('InputObject') diff --git a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusQueue.ps1 b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusQueue.ps1 index f1f27f4b32d9..69de7d9fd02c 100644 --- a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusQueue.ps1 +++ b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusQueue.ps1 @@ -231,18 +231,7 @@ function Set-AzServiceBusQueue{ $null = $targetParameters.Remove('WhatIf') $null = $targetParameters.Remove('Confirm') - $readCommand = @(Get-Command -Name 'Get-AzServiceBusQueue' -ErrorAction Stop)[0] - while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { - $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop - } - $readParameterNames = @($readCommand.Parameters.Keys) - $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) - $readParameters = @{} - foreach ($parameter in $targetParameters.GetEnumerator()) { - if ($parameter.Key -in $readParameterNames) { - $readParameters[$parameter.Key] = $parameter.Value - } - } + $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusQueue' -BoundParameters $targetParameters $queue = Get-AzServiceBusQueue @readParameters # 2. PUT $null = $targetParameters.Remove('InputObject') diff --git a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusRule.ps1 b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusRule.ps1 index 5ee70fbcb698..d293c2132d22 100644 --- a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusRule.ps1 +++ b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusRule.ps1 @@ -248,18 +248,7 @@ function Set-AzServiceBusRule{ $hasActionSqlExpression = $targetParameters.Remove('ActionSqlExpression') $hasActionRequiresPreprocessing = $targetParameters.Remove('ActionRequiresPreprocessing') - $readCommand = @(Get-Command -Name 'Get-AzServiceBusRule' -ErrorAction Stop)[0] - while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { - $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop - } - $readParameterNames = @($readCommand.Parameters.Keys) - $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) - $readParameters = @{} - foreach ($parameter in $targetParameters.GetEnumerator()) { - if ($parameter.Key -in $readParameterNames) { - $readParameters[$parameter.Key] = $parameter.Value - } - } + $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusRule' -BoundParameters $targetParameters $rule = Get-AzServiceBusRule @readParameters # 2. PUT $null = $targetParameters.Remove('InputObject') diff --git a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusSubscription.ps1 b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusSubscription.ps1 index 81b39cdf727b..0aa840643600 100644 --- a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusSubscription.ps1 +++ b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusSubscription.ps1 @@ -218,18 +218,7 @@ function Set-AzServiceBusSubscription{ $null = $targetParameters.Remove('WhatIf') $null = $targetParameters.Remove('Confirm') - $readCommand = @(Get-Command -Name 'Get-AzServiceBusSubscription' -ErrorAction Stop)[0] - while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { - $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop - } - $readParameterNames = @($readCommand.Parameters.Keys) - $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) - $readParameters = @{} - foreach ($parameter in $targetParameters.GetEnumerator()) { - if ($parameter.Key -in $readParameterNames) { - $readParameters[$parameter.Key] = $parameter.Value - } - } + $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusSubscription' -BoundParameters $targetParameters $subscription = Get-AzServiceBusSubscription @readParameters # 2. PUT $null = $targetParameters.Remove('InputObject') diff --git a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusTopic.ps1 b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusTopic.ps1 index d39eb289b577..69d96df36c4e 100644 --- a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusTopic.ps1 +++ b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusTopic.ps1 @@ -203,18 +203,7 @@ function Set-AzServiceBusTopic{ $null = $targetParameters.Remove('WhatIf') $null = $targetParameters.Remove('Confirm') - $readCommand = @(Get-Command -Name 'Get-AzServiceBusTopic' -ErrorAction Stop)[0] - while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { - $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop - } - $readParameterNames = @($readCommand.Parameters.Keys) - $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) - $readParameters = @{} - foreach ($parameter in $targetParameters.GetEnumerator()) { - if ($parameter.Key -in $readParameterNames) { - $readParameters[$parameter.Key] = $parameter.Value - } - } + $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusTopic' -BoundParameters $targetParameters $topic = Get-AzServiceBusTopic @readParameters # 2. PUT $null = $targetParameters.Remove('InputObject') diff --git a/src/ServiceBus/ServiceBus.Autorest/test/ReadParameterForwarding.Tests.ps1 b/src/ServiceBus/ServiceBus.Autorest/test/ReadParameterForwarding.Tests.ps1 index bea24f683850..d86382d6c0e7 100644 --- a/src/ServiceBus/ServiceBus.Autorest/test/ReadParameterForwarding.Tests.ps1 +++ b/src/ServiceBus/ServiceBus.Autorest/test/ReadParameterForwarding.Tests.ps1 @@ -1,3 +1,8 @@ +$helperPath = Join-Path $PSScriptRoot '..\custom\Get-AzServiceBusReadParameters.ps1' +$helperSource = Get-Content -Path $helperPath -Raw +$helperSource = $helperSource -replace '(?m)^\s*\[Microsoft\.Azure\.PowerShell\.Cmdlets\.ServiceBus\.DoNotExportAttribute\(\)\]\r?\n', '' +. ([scriptblock]::Create($helperSource)) + function Get-AzServiceBusReadTestResource { [CmdletBinding()] param( @@ -22,30 +27,10 @@ function Set-AzServiceBusReadTestResource { $script:serviceBusWriteParameters = @{} + $PSBoundParameters } -function Assert-InlineReadCommandsInvoked { - param([string] $Source) - - $lookupPattern = "(?ms)\`$readCommand\s*=\s*@\(Get-Command -Name '([^']+)'[^\r\n]*\)\[0\](?.*?)(?=\`$readCommand\s*=\s*@\(Get-Command -Name|\z)" - $lookups = [regex]::Matches($Source, $lookupPattern) - if ($lookups.Count -eq 0) { - return $false - } - - foreach ($lookup in $lookups) { - $commandName = $lookup.Groups[1].Value - $invocationPattern = '(?m)^\s*(?:\$\w+\s*=\s*)?' + [regex]::Escape($commandName) + '\s+@readParameters\s*$' - if (-not [regex]::IsMatch($lookup.Groups['Block'].Value, $invocationPattern)) { - return $false - } - } - - return $true -} - -Set-Alias -Name Get-AzServiceBusReadTestResourceAlias -Value Get-AzServiceBusReadTestResource +Set-Alias -Name Get-AzServiceBusReadTestAlias -Value Get-AzServiceBusReadTestResource -Describe 'ServiceBus inline read parameter forwarding' { - It 'filters write-only parameters using aliased read command metadata without changing target parameters' { +Describe 'ServiceBus read parameter forwarding' { + It 'filters write-only parameters using read command metadata without changing target parameters' { $targetParameters = @{ Name = 'queue' DefaultProfile = 'profile' @@ -55,20 +40,7 @@ Describe 'ServiceBus inline read parameter forwarding' { SyntheticWriteOnly = 'future-value' } - $readCommand = @(Get-Command -Name 'Get-AzServiceBusReadTestResourceAlias' -ErrorAction Stop)[0] - while ($readCommand.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { - $readCommand = Get-Command -Name $readCommand.ResolvedCommandName -ErrorAction Stop - } - $readParameterNames = @($readCommand.Parameters.Keys) - $readParameterNames += @($readCommand.Parameters.Values | ForEach-Object { $_.Aliases }) - $readParameters = @{} - foreach ($parameter in $targetParameters.GetEnumerator()) { - if ($parameter.Key -in $readParameterNames) { - $readParameters[$parameter.Key] = $parameter.Value - } - } - - ($readParameterNames -contains 'ResourceName') | Should Be $true + $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusReadTestAlias' -BoundParameters $targetParameters Get-AzServiceBusReadTestResource @readParameters Set-AzServiceBusReadTestResource @targetParameters @@ -83,7 +55,13 @@ Describe 'ServiceBus inline read parameter forwarding' { $script:serviceBusWriteParameters.SyntheticWriteOnly | Should Be 'future-value' } - It 'inlines metadata filtering with separate read and target parameters in every affected wrapper' { + It 'recognizes read parameter aliases' { + $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusReadTestResource' -BoundParameters @{ ResourceName = 'queue' } + + $readParameters.ResourceName | Should Be 'queue' + } + + It 'uses separate read and target parameter groups in every affected wrapper' { $wrappers = @( 'Approve-AzServiceBusPrivateEndpointConnection.ps1', 'Deny-AzServiceBusPrivateEndpointConnection.ps1', @@ -101,40 +79,30 @@ Describe 'ServiceBus inline read parameter forwarding' { foreach ($wrapper in $wrappers) { $source = Get-Content -Path (Join-Path $PSScriptRoot "..\custom\$wrapper") -Raw $source | Should Match '\$targetParameters\s*=\s*@\{\}\s*\+\s*\$PSBoundParameters' - $source | Should Match '\$readCommand\s*=\s*@\(Get-Command -Name' - $source | Should Match '\$readCommand\.CommandType.+CommandTypes\]::Alias' - $source | Should Match '\$readCommand\.Parameters\.Values.+\$_.Aliases' - $source | Should Match '\$readParameters\s*=\s*@\{\}' + $source | Should Match 'Get-AzServiceBusReadParameters\s+-CommandName' $source | Should Match '@readParameters' $source | Should Match '@targetParameters' - $source | Should Not Match 'Get-Az(?:EventHub|ServiceBus|NetworkSecurityPerimeter)ReadParameters' - (Assert-InlineReadCommandsInvoked -Source $source) | Should Be $true } } - It 'rejects a lookup followed by invocation of a different read command' { - $source = @' -$readCommand = @(Get-Command -Name 'Get-AzExpectedResource' -ErrorAction Stop)[0] -$readParameters = @{} -$resource = Get-AzDifferentResource @readParameters -'@ - - (Assert-InlineReadCommandsInvoked -Source $source) | Should Be $false - } - It 'keeps exact expanded and via-identity read variants for authorization rules' { $source = Get-Content -Path (Join-Path $PSScriptRoot '..\custom\Set-AzServiceBusAuthorizationRule.ps1') -Raw - $source | Should Match "Get-Command -Name 'Az.ServiceBus.private\\Get-AzServiceBusQueueAuthorizationRule_Get'" - $source | Should Match "Get-Command -Name 'Az.ServiceBus.private\\Get-AzServiceBusTopicAuthorizationRule_GetViaIdentity'" - $source | Should Match "Get-Command -Name 'Az.ServiceBus.private\\Get-AzServiceBusNamespaceAuthorizationRule_GetViaIdentity'" + $source | Should Match "CommandName 'Az\.ServiceBus\.private\\Get-AzServiceBusQueueAuthorizationRule_Get'" + $source | Should Match "CommandName 'Az\.ServiceBus\.private\\Get-AzServiceBusTopicAuthorizationRule_GetViaIdentity'" + $source | Should Match "CommandName 'Az\.ServiceBus\.private\\Get-AzServiceBusNamespaceAuthorizationRule_GetViaIdentity'" } - It 'has no helper source and retains the regeneration trigger' { - $helperPath = Join-Path $PSScriptRoot '..\custom\Get-AzServiceBusReadParameters.ps1' + It 'packages the internal helper and triggers regeneration' { + $customPath = Join-Path $PSScriptRoot '..\custom' + $helperPath = Join-Path $customPath 'Get-AzServiceBusReadParameters.ps1' + $moduleSource = Get-Content -Path (Join-Path $customPath 'Az.ServiceBus.custom.psm1') -Raw + $helperSource = Get-Content -Path $helperPath -Raw $generation = Get-Content -Path (Join-Path $PSScriptRoot '..\generate-info.json') -Raw | ConvertFrom-Json - Test-Path -Path $helperPath | Should Be $false + Test-Path -Path $helperPath | Should Be $true + $helperSource | Should Match '\[Microsoft\.Azure\.PowerShell\.Cmdlets\.ServiceBus\.DoNotExportAttribute\(\)\]' + $moduleSource | Should Match "Get-ChildItem\s+-Path\s+\`$PSScriptRoot\s+-Recurse\s+-Include\s+'\*\.ps1'" { [guid]::Parse($generation.generate_Id) } | Should Not Throw $generation.generate_Id | Should Not Be 'd42664e3-3ae4-4daf-a410-fba6f9958c4e' } From 770b0b9cc7c5608bc3e0867ff7512e1dd5e18a2d Mon Sep 17 00:00:00 2001 From: Yang An Date: Mon, 28 Sep 2026 14:57:00 +1000 Subject: [PATCH 04/12] Remove redundant Change Safety changelog entries The forwarding fix will ship with the existing unreleased Change Safety enablement, so keep a single release note for the feature. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/EventHub/EventHub/ChangeLog.md | 1 - src/Network/Network/ChangeLog.md | 1 - src/ServiceBus/ServiceBus/ChangeLog.md | 1 - 3 files changed, 3 deletions(-) diff --git a/src/EventHub/EventHub/ChangeLog.md b/src/EventHub/EventHub/ChangeLog.md index 6cd93b4bf27f..ec175fff137f 100644 --- a/src/EventHub/EventHub/ChangeLog.md +++ b/src/EventHub/EventHub/ChangeLog.md @@ -19,7 +19,6 @@ --> ## Upcoming Release * Added Change Safety support for additional cmdlets. -* Fixed Change Safety parameter forwarding in custom GET-before-write cmdlets. ## Version 5.6.0 * Added parameter `IPAddressType` to cmdlets 'New-AzEventHubNamespace' and 'Set-AzEventHubNamespace' diff --git a/src/Network/Network/ChangeLog.md b/src/Network/Network/ChangeLog.md index 679b1c657c0e..bc6a264f877b 100644 --- a/src/Network/Network/ChangeLog.md +++ b/src/Network/Network/ChangeLog.md @@ -26,7 +26,6 @@ * Added support for the `CAPTCHA` action in Application Gateway WAF (Web Application Firewall) policies. - Added `CAPTCHA` as an allowed value for the `-Action` parameter of custom rules (`New-AzApplicationGatewayFirewallCustomRule`) and managed rule overrides (`New-AzApplicationGatewayFirewallPolicyManagedRuleOverride`). - Added the `-CaptchaExpirationInMins` parameter to `New-AzApplicationGatewayFirewallPolicySetting`. -* Fixed Change Safety parameter forwarding in Network Security Perimeter update cmdlets. ## Version 8.2.0 * Added `Get-AzExpressRouteLag`, `New-AzExpressRouteLag`, `Set-AzExpressRouteLag`, `Remove-AzExpressRouteLag`, `New-AzExpressRouteLagLOA`, `Get-AzExpressRouteLagLink`, and `Get-AzExpressRouteLagMember` for `ExpressRouteLag` resources (Microsoft.Network 2025-09-01 API). diff --git a/src/ServiceBus/ServiceBus/ChangeLog.md b/src/ServiceBus/ServiceBus/ChangeLog.md index 6ff04cfe0bc1..e1c240079d4e 100644 --- a/src/ServiceBus/ServiceBus/ChangeLog.md +++ b/src/ServiceBus/ServiceBus/ChangeLog.md @@ -20,7 +20,6 @@ --> ## Upcoming Release * Added Change Safety support for additional cmdlets. -* Fixed Change Safety parameter forwarding in custom GET-before-write cmdlets. ## Version 4.3.0 * Added parameters 'GeoDataReplicationMaxReplicationLagDurationInSecond', 'GeoDataReplicationLocation', and 'IPAddressType' to cmdlets 'New-AzServiceBusNamespace' and 'Set-AzServiceBusNamespace' From 7b4460fef9ea3d097d5f81605508a5763ed5d4ff Mon Sep 17 00:00:00 2001 From: Yang An Date: Mon, 28 Sep 2026 15:04:49 +1000 Subject: [PATCH 05/12] Preserve existing bound parameter flow Keep target writes on the original PSBoundParameters dictionary and introduce only helper-filtered read parameters for preliminary GET operations. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- ...ve-AzEventHubPrivateEndpointConnection.ps1 | 23 ++++--- ...ny-AzEventHubPrivateEndpointConnection.ps1 | 25 ++++---- .../custom/Set-AzEventHub.ps1 | 61 +++++++++---------- .../custom/Set-AzEventHubApplicationGroup.ps1 | 31 +++++----- .../Set-AzEventHubAuthorizationRule.ps1 | 39 ++++++------ .../custom/Set-AzEventHubCluster.ps1 | 27 ++++---- .../custom/Set-AzEventHubConsumerGroup.ps1 | 27 ++++---- ...-AzEventHubGeoDRConfigurationBreakPair.ps1 | 27 ++++---- ...t-AzEventHubGeoDRConfigurationFailOver.ps1 | 27 ++++---- .../custom/Set-AzEventHubNamespace.ps1 | 55 ++++++++--------- .../custom/Set-AzEventHubNetworkRuleSet.ps1 | 33 +++++----- .../test/ReadParameterForwarding.Tests.ps1 | 16 ++--- ...e-AzNetworkSecurityPerimeterAccessRule.ps1 | 13 ++-- ...-AzNetworkSecurityPerimeterAssociation.ps1 | 13 ++-- .../Update-AzNetworkSecurityPerimeterLink.ps1 | 13 ++-- ...kSecurityPerimeterLoggingConfiguration.ps1 | 13 ++-- .../test/ReadParameterForwarding.Tests.ps1 | 16 ++--- ...-AzServiceBusPrivateEndpointConnection.ps1 | 23 ++++--- ...-AzServiceBusPrivateEndpointConnection.ps1 | 23 ++++--- .../Set-AzServiceBusAuthorizationRule.ps1 | 51 ++++++++-------- ...zServiceBusGeoDRConfigurationBreakPair.ps1 | 27 ++++---- ...AzServiceBusGeoDRConfigurationFailOver.ps1 | 27 ++++---- .../custom/Set-AzServiceBusNamespace.ps1 | 55 ++++++++--------- .../custom/Set-AzServiceBusNetworkRuleSet.ps1 | 33 +++++----- .../custom/Set-AzServiceBusQueue.ps1 | 51 ++++++++-------- .../custom/Set-AzServiceBusRule.ps1 | 53 ++++++++-------- .../custom/Set-AzServiceBusSubscription.ps1 | 49 ++++++++------- .../custom/Set-AzServiceBusTopic.ps1 | 45 +++++++------- .../test/ReadParameterForwarding.Tests.ps1 | 16 ++--- 29 files changed, 443 insertions(+), 469 deletions(-) diff --git a/src/EventHub/EventHub.Autorest/custom/Approve-AzEventHubPrivateEndpointConnection.ps1 b/src/EventHub/EventHub.Autorest/custom/Approve-AzEventHubPrivateEndpointConnection.ps1 index d6d8afa302d4..022dfe62355e 100644 --- a/src/EventHub/EventHub.Autorest/custom/Approve-AzEventHubPrivateEndpointConnection.ps1 +++ b/src/EventHub/EventHub.Autorest/custom/Approve-AzEventHubPrivateEndpointConnection.ps1 @@ -134,13 +134,12 @@ function Approve-AzEventHubPrivateEndpointConnection{ } process{ try{ - $targetParameters = @{} + $PSBoundParameters - $hasDescription = $targetParameters.Remove('Description') - $hasAsJob = $targetParameters.Remove('AsJob') - $null = $targetParameters.Remove('WhatIf') - $null = $targetParameters.Remove('Confirm') + $hasDescription = $PSBoundParameters.Remove('Description') + $hasAsJob = $PSBoundParameters.Remove('AsJob') + $null = $PSBoundParameters.Remove('WhatIf') + $null = $PSBoundParameters.Remove('Confirm') - $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHubPrivateEndpointConnection' -BoundParameters $targetParameters + $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHubPrivateEndpointConnection' -BoundParameters $PSBoundParameters $connection = Get-AzEventHubPrivateEndpointConnection @readParameters $connection.ConnectionState = "Approved" @@ -152,14 +151,14 @@ function Approve-AzEventHubPrivateEndpointConnection{ } # 2. PUT - $null = $targetParameters.Remove('InputObject') - $null = $targetParameters.Remove('ResourceGroupName') - $null = $targetParameters.Remove('NamespaceName') - $null = $targetParameters.Remove('Name') - $null = $targetParameters.Remove('SubscriptionId') + $null = $PSBoundParameters.Remove('InputObject') + $null = $PSBoundParameters.Remove('ResourceGroupName') + $null = $PSBoundParameters.Remove('NamespaceName') + $null = $PSBoundParameters.Remove('Name') + $null = $PSBoundParameters.Remove('SubscriptionId') if ($PSCmdlet.ShouldProcess("Approve EventHub Namespace PrivateEndpoint Connection $($Name)", "Create or update")) { - Az.EventHub.private\New-AzEventHubPrivateEndpointConnection_CreateViaIdentity -InputObject $connection -Parameter $connection @targetParameters + Az.EventHub.private\New-AzEventHubPrivateEndpointConnection_CreateViaIdentity -InputObject $connection -Parameter $connection @PSBoundParameters } } catch{ diff --git a/src/EventHub/EventHub.Autorest/custom/Deny-AzEventHubPrivateEndpointConnection.ps1 b/src/EventHub/EventHub.Autorest/custom/Deny-AzEventHubPrivateEndpointConnection.ps1 index 1c7f47e6a6b6..96fe18e27846 100644 --- a/src/EventHub/EventHub.Autorest/custom/Deny-AzEventHubPrivateEndpointConnection.ps1 +++ b/src/EventHub/EventHub.Autorest/custom/Deny-AzEventHubPrivateEndpointConnection.ps1 @@ -134,13 +134,12 @@ function Deny-AzEventHubPrivateEndpointConnection{ } process{ try{ - $targetParameters = @{} + $PSBoundParameters - $hasDescription = $targetParameters.Remove('Description') - $hasAsJob = $targetParameters.Remove('AsJob') - $null = $targetParameters.Remove('WhatIf') - $null = $targetParameters.Remove('Confirm') + $hasDescription = $PSBoundParameters.Remove('Description') + $hasAsJob = $PSBoundParameters.Remove('AsJob') + $null = $PSBoundParameters.Remove('WhatIf') + $null = $PSBoundParameters.Remove('Confirm') - $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHubPrivateEndpointConnection' -BoundParameters $targetParameters + $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHubPrivateEndpointConnection' -BoundParameters $PSBoundParameters $connection = Get-AzEventHubPrivateEndpointConnection @readParameters $connection.ConnectionState = "Rejected" @@ -152,15 +151,15 @@ function Deny-AzEventHubPrivateEndpointConnection{ } # 2. PUT - $null = $targetParameters.Remove('InputObject') - $null = $targetParameters.Remove('ResourceGroupName') - $null = $targetParameters.Remove('NamespaceName') - $null = $targetParameters.Remove('EventHubName') - $null = $targetParameters.Remove('Name') - $null = $targetParameters.Remove('SubscriptionId') + $null = $PSBoundParameters.Remove('InputObject') + $null = $PSBoundParameters.Remove('ResourceGroupName') + $null = $PSBoundParameters.Remove('NamespaceName') + $null = $PSBoundParameters.Remove('EventHubName') + $null = $PSBoundParameters.Remove('Name') + $null = $PSBoundParameters.Remove('SubscriptionId') if ($PSCmdlet.ShouldProcess("Approve EventHub Namespace PrivateEndpoint Connection $($Name)", "Create or update")) { - Az.EventHub.private\New-AzEventHubPrivateEndpointConnection_CreateViaIdentity -InputObject $connection -Parameter $connection @targetParameters + Az.EventHub.private\New-AzEventHubPrivateEndpointConnection_CreateViaIdentity -InputObject $connection -Parameter $connection @PSBoundParameters } } catch{ diff --git a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHub.ps1 b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHub.ps1 index cc31843c25cf..72b06b85f880 100644 --- a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHub.ps1 +++ b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHub.ps1 @@ -235,37 +235,36 @@ function Set-AzEventHub{ } process{ try{ - $targetParameters = @{} + $PSBoundParameters - $hasCaptureEnabled = $targetParameters.Remove('CaptureEnabled') - $hasEncoding = $targetParameters.Remove('Encoding') - $hasIntervalInSeconds = $targetParameters.Remove('IntervalInSeconds') - $hasSizeLimitInBytes = $targetParameters.Remove('SizeLimitInBytes') - $hasSkipEmptyArchive = $targetParameters.Remove('SkipEmptyArchive') - $hasUserAssignedIdentityId = $targetParameters.Remove('UserAssignedIdentityId') - $hasIdentityType = $targetParameters.Remove('IdentityType') - $hasRetentionTimeInHour = $targetParameters.Remove('RetentionTimeInHour') - $hasTombstoneRetentionTimeInHour = $targetParameters.Remove('TombstoneRetentionTimeInHour') - $hasStatus = $targetParameters.Remove('Status') - $hasDestinationName = $targetParameters.Remove('DestinationName') - $hasStorageAccountResourceId = $targetParameters.Remove('StorageAccountResourceId') - $hasArchiveNameFormat = $targetParameters.Remove('ArchiveNameFormat') - $hasBlobContainer = $targetParameters.Remove('BlobContainer') - $hasAsJob = $targetParameters.Remove('AsJob') - $hasPartitionCount = $targetParameters.Remove('PartitionCount') - $hasUserMetadata = $targetParameters.Remove('UserMetadata') - $hasMinCompactionLagInMin = $targetParameters.Remove('MinCompactionLagInMin') - $hasTimestampType = $targetParameters.Remove('TimestampType') - $null = $targetParameters.Remove('WhatIf') - $null = $targetParameters.Remove('Confirm') - - $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHub' -BoundParameters $targetParameters + $hasCaptureEnabled = $PSBoundParameters.Remove('CaptureEnabled') + $hasEncoding = $PSBoundParameters.Remove('Encoding') + $hasIntervalInSeconds = $PSBoundParameters.Remove('IntervalInSeconds') + $hasSizeLimitInBytes = $PSBoundParameters.Remove('SizeLimitInBytes') + $hasSkipEmptyArchive = $PSBoundParameters.Remove('SkipEmptyArchive') + $hasUserAssignedIdentityId = $PSBoundParameters.Remove('UserAssignedIdentityId') + $hasIdentityType = $PSBoundParameters.Remove('IdentityType') + $hasRetentionTimeInHour = $PSBoundParameters.Remove('RetentionTimeInHour') + $hasTombstoneRetentionTimeInHour = $PSBoundParameters.Remove('TombstoneRetentionTimeInHour') + $hasStatus = $PSBoundParameters.Remove('Status') + $hasDestinationName = $PSBoundParameters.Remove('DestinationName') + $hasStorageAccountResourceId = $PSBoundParameters.Remove('StorageAccountResourceId') + $hasArchiveNameFormat = $PSBoundParameters.Remove('ArchiveNameFormat') + $hasBlobContainer = $PSBoundParameters.Remove('BlobContainer') + $hasAsJob = $PSBoundParameters.Remove('AsJob') + $hasPartitionCount = $PSBoundParameters.Remove('PartitionCount') + $hasUserMetadata = $PSBoundParameters.Remove('UserMetadata') + $hasMinCompactionLagInMin = $PSBoundParameters.Remove('MinCompactionLagInMin') + $hasTimestampType = $PSBoundParameters.Remove('TimestampType') + $null = $PSBoundParameters.Remove('WhatIf') + $null = $PSBoundParameters.Remove('Confirm') + + $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHub' -BoundParameters $PSBoundParameters $eventHub = Get-AzEventHub @readParameters # 2. PUT - $null = $targetParameters.Remove('InputObject') - $null = $targetParameters.Remove('ResourceGroupName') - $null = $targetParameters.Remove('NamespaceName') - $null = $targetParameters.Remove('Name') - $null = $targetParameters.Remove('SubscriptionId') + $null = $PSBoundParameters.Remove('InputObject') + $null = $PSBoundParameters.Remove('ResourceGroupName') + $null = $PSBoundParameters.Remove('NamespaceName') + $null = $PSBoundParameters.Remove('Name') + $null = $PSBoundParameters.Remove('SubscriptionId') $hasProperty = $false @@ -362,11 +361,11 @@ function Set-AzEventHub{ } if ($hasAsJob) { - $targetParameters.Add('AsJob', $true) + $PSBoundParameters.Add('AsJob', $true) } if ($PSCmdlet.ShouldProcess("EventHub Entity $($eventHub.Name)", "Create or update")) { - Az.EventHub.private\New-AzEventHub_CreateViaIdentity -InputObject $eventHub -Parameter $eventHub @targetParameters + Az.EventHub.private\New-AzEventHub_CreateViaIdentity -InputObject $eventHub -Parameter $eventHub @PSBoundParameters } } catch{ diff --git a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubApplicationGroup.ps1 b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubApplicationGroup.ps1 index de959fec3051..9babf3ed5ca3 100644 --- a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubApplicationGroup.ps1 +++ b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubApplicationGroup.ps1 @@ -146,22 +146,21 @@ function Set-AzEventHubApplicationGroup{ } process{ try{ - $targetParameters = @{} + $PSBoundParameters - $hasIsEnabled = $targetParameters.Remove('IsEnabled') - $hasPolicy = $targetParameters.Remove('Policy') - $hasClientAppGroupIdentifier = $targetParameters.Remove('ClientAppGroupIdentifier') - $hasAsJob = $targetParameters.Remove('AsJob') - $null = $targetParameters.Remove('WhatIf') - $null = $targetParameters.Remove('Confirm') - - $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHubApplicationGroup' -BoundParameters $targetParameters + $hasIsEnabled = $PSBoundParameters.Remove('IsEnabled') + $hasPolicy = $PSBoundParameters.Remove('Policy') + $hasClientAppGroupIdentifier = $PSBoundParameters.Remove('ClientAppGroupIdentifier') + $hasAsJob = $PSBoundParameters.Remove('AsJob') + $null = $PSBoundParameters.Remove('WhatIf') + $null = $PSBoundParameters.Remove('Confirm') + + $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHubApplicationGroup' -BoundParameters $PSBoundParameters $appGroup = Get-AzEventHubApplicationGroup @readParameters # 2. PUT - $null = $targetParameters.Remove('InputObject') - $null = $targetParameters.Remove('ResourceGroupName') - $null = $targetParameters.Remove('NamespaceName') - $null = $targetParameters.Remove('Name') - $null = $targetParameters.Remove('SubscriptionId') + $null = $PSBoundParameters.Remove('InputObject') + $null = $PSBoundParameters.Remove('ResourceGroupName') + $null = $PSBoundParameters.Remove('NamespaceName') + $null = $PSBoundParameters.Remove('Name') + $null = $PSBoundParameters.Remove('SubscriptionId') $hasProperty = $false @@ -183,12 +182,12 @@ function Set-AzEventHubApplicationGroup{ } if ($hasAsJob) { - $targetParameters.Add('AsJob', $true) + $PSBoundParameters.Add('AsJob', $true) } if ($PSCmdlet.ShouldProcess("EventHub Application Group $($appGroup.Name)", "Create or update")) { - Az.EventHub.private\New-AzEventHubApplicationGroup_CreateViaIdentity -InputObject $appGroup -Parameter $appGroup @targetParameters + Az.EventHub.private\New-AzEventHubApplicationGroup_CreateViaIdentity -InputObject $appGroup -Parameter $appGroup @PSBoundParameters } } catch{ diff --git a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubAuthorizationRule.ps1 b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubAuthorizationRule.ps1 index f92c0698cedb..6fe137c4c9fa 100644 --- a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubAuthorizationRule.ps1 +++ b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubAuthorizationRule.ps1 @@ -145,19 +145,18 @@ function Set-AzEventHubAuthorizationRule{ } process{ try{ - $targetParameters = @{} + $PSBoundParameters - $hasRights = $targetParameters.Remove('Rights') - $hasAsJob = $targetParameters.Remove('AsJob') - $null = $targetParameters.Remove('WhatIf') - $null = $targetParameters.Remove('Confirm') + $hasRights = $PSBoundParameters.Remove('Rights') + $hasAsJob = $PSBoundParameters.Remove('AsJob') + $null = $PSBoundParameters.Remove('WhatIf') + $null = $PSBoundParameters.Remove('Confirm') if ($PSCmdlet.ParameterSetName -eq 'SetExpandedNamespace'){ - $readParameters = Get-AzEventHubReadParameters -CommandName 'Az.EventHub.private\Get-AzEventHubNamespaceAuthorizationRule_Get' -BoundParameters $targetParameters + $readParameters = Get-AzEventHubReadParameters -CommandName 'Az.EventHub.private\Get-AzEventHubNamespaceAuthorizationRule_Get' -BoundParameters $PSBoundParameters $authRule = Az.EventHub.private\Get-AzEventHubNamespaceAuthorizationRule_Get @readParameters } elseif($PSCmdlet.ParameterSetName -eq 'SetExpandedEntity'){ - $readParameters = Get-AzEventHubReadParameters -CommandName 'Az.EventHub.private\Get-AzEventHubAuthorizationRule_Get' -BoundParameters $targetParameters + $readParameters = Get-AzEventHubReadParameters -CommandName 'Az.EventHub.private\Get-AzEventHubAuthorizationRule_Get' -BoundParameters $PSBoundParameters $authRule = Az.EventHub.private\Get-AzEventHubAuthorizationRule_Get @readParameters } @@ -169,11 +168,11 @@ function Set-AzEventHubAuthorizationRule{ $ResourceHashTable = ParseResourceId -ResourceId $InputObject } if ($ResourceHashTable['EventHubName'] -ne $null){ - $readParameters = Get-AzEventHubReadParameters -CommandName 'Az.EventHub.private\Get-AzEventHubAuthorizationRule_GetViaIdentity' -BoundParameters $targetParameters + $readParameters = Get-AzEventHubReadParameters -CommandName 'Az.EventHub.private\Get-AzEventHubAuthorizationRule_GetViaIdentity' -BoundParameters $PSBoundParameters $authRule = Az.EventHub.private\Get-AzEventHubAuthorizationRule_GetViaIdentity @readParameters } elseif ($ResourceHashTable['NamespaceName'] -ne $null){ - $readParameters = Get-AzEventHubReadParameters -CommandName 'Az.EventHub.private\Get-AzEventHubNamespaceAuthorizationRule_GetViaIdentity' -BoundParameters $targetParameters + $readParameters = Get-AzEventHubReadParameters -CommandName 'Az.EventHub.private\Get-AzEventHubNamespaceAuthorizationRule_GetViaIdentity' -BoundParameters $PSBoundParameters $authRule = Az.EventHub.private\Get-AzEventHubNamespaceAuthorizationRule_GetViaIdentity @readParameters } else{ @@ -182,29 +181,29 @@ function Set-AzEventHubAuthorizationRule{ } # 2. PUT - $null = $targetParameters.Remove('InputObject') - $null = $targetParameters.Remove('ResourceGroupName') - $null = $targetParameters.Remove('NamespaceName') - $null = $targetParameters.Remove('EventHubName') - $null = $targetParameters.Remove('Name') - $null = $targetParameters.Remove('SubscriptionId') + $null = $PSBoundParameters.Remove('InputObject') + $null = $PSBoundParameters.Remove('ResourceGroupName') + $null = $PSBoundParameters.Remove('NamespaceName') + $null = $PSBoundParameters.Remove('EventHubName') + $null = $PSBoundParameters.Remove('Name') + $null = $PSBoundParameters.Remove('SubscriptionId') if ($hasRights) { $authRule.Rights = $Rights } if ($hasAsJob) { - $targetParameters.Add('AsJob', $true) + $PSBoundParameters.Add('AsJob', $true) } if ($PSCmdlet.ParameterSetName -eq 'SetExpandedNamespace'){ if ($PSCmdlet.ShouldProcess("EventHub Namespace Authorization Rule $($authRule.Name)", "Create or update")) { - Az.EventHub.private\New-AzEventHubNamespaceAuthorizationRule_CreateViaIdentity -InputObject $authRule -Parameter $authRule @targetParameters + Az.EventHub.private\New-AzEventHubNamespaceAuthorizationRule_CreateViaIdentity -InputObject $authRule -Parameter $authRule @PSBoundParameters } } elseif ($PSCmdlet.ParameterSetName -eq 'SetExpandedEntity'){ if ($PSCmdlet.ShouldProcess("EventHub Entity Authorization Rule $($authRule.Name)", "Create or update")) { - Az.EventHub.private\New-AzEventHubAuthorizationRule_CreateViaIdentity -InputObject $authRule -Parameter $authRule @targetParameters + Az.EventHub.private\New-AzEventHubAuthorizationRule_CreateViaIdentity -InputObject $authRule -Parameter $authRule @PSBoundParameters } } @@ -213,12 +212,12 @@ function Set-AzEventHubAuthorizationRule{ if ($ResourceHashTable['EventHubName'] -ne $null){ if ($PSCmdlet.ShouldProcess("EventHub Entity Authorization Rule $($ResourceHashTable['AuthorizationRuleName'])", "Create or update")) { - Az.EventHub.private\New-AzEventHubAuthorizationRule_CreateViaIdentity -InputObject $authRule -Parameter $authRule @targetParameters + Az.EventHub.private\New-AzEventHubAuthorizationRule_CreateViaIdentity -InputObject $authRule -Parameter $authRule @PSBoundParameters } } elseif ($ResourceHashTable['NamespaceName'] -ne $null){ if ($PSCmdlet.ShouldProcess("EventHub Namespace Authorization Rule $($ResourceHashTable['AuthorizationRuleName'])", "Create or update")) { - Az.EventHub.private\New-AzEventHubNamespaceAuthorizationRule_CreateViaIdentity -InputObject $authRule -Parameter $authRule @targetParameters + Az.EventHub.private\New-AzEventHubNamespaceAuthorizationRule_CreateViaIdentity -InputObject $authRule -Parameter $authRule @PSBoundParameters } } else{ diff --git a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubCluster.ps1 b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubCluster.ps1 index 3b5969ddef0a..d3c5adb5312e 100644 --- a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubCluster.ps1 +++ b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubCluster.ps1 @@ -135,20 +135,19 @@ function Set-AzEventHubCluster{ } process{ try{ - $targetParameters = @{} + $PSBoundParameters - $hasCapacity = $targetParameters.Remove('Capacity') - $hasTag = $targetParameters.Remove('Tag') - $hasAsJob = $targetParameters.Remove('AsJob') - $null = $targetParameters.Remove('WhatIf') - $null = $targetParameters.Remove('Confirm') - - $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHubCluster' -BoundParameters $targetParameters + $hasCapacity = $PSBoundParameters.Remove('Capacity') + $hasTag = $PSBoundParameters.Remove('Tag') + $hasAsJob = $PSBoundParameters.Remove('AsJob') + $null = $PSBoundParameters.Remove('WhatIf') + $null = $PSBoundParameters.Remove('Confirm') + + $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHubCluster' -BoundParameters $PSBoundParameters $cluster = Get-AzEventHubCluster @readParameters # 2. PUT - $null = $targetParameters.Remove('InputObject') - $null = $targetParameters.Remove('ResourceGroupName') - $null = $targetParameters.Remove('Name') - $null = $targetParameters.Remove('SubscriptionId') + $null = $PSBoundParameters.Remove('InputObject') + $null = $PSBoundParameters.Remove('ResourceGroupName') + $null = $PSBoundParameters.Remove('Name') + $null = $PSBoundParameters.Remove('SubscriptionId') $hasProperty = $false @@ -166,11 +165,11 @@ function Set-AzEventHubCluster{ } if ($hasAsJob) { - $targetParameters.Add('AsJob', $true) + $PSBoundParameters.Add('AsJob', $true) } if ($PSCmdlet.ShouldProcess("EventHub Cluster $($cluster.Name)", "Create or update")) { - Az.EventHub.private\New-AzEventHubCluster_CreateViaIdentity -InputObject $cluster -Parameter $cluster @targetParameters + Az.EventHub.private\New-AzEventHubCluster_CreateViaIdentity -InputObject $cluster -Parameter $cluster @PSBoundParameters } } catch{ diff --git a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubConsumerGroup.ps1 b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubConsumerGroup.ps1 index a92141cbfd75..26debabdbe05 100644 --- a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubConsumerGroup.ps1 +++ b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubConsumerGroup.ps1 @@ -141,30 +141,29 @@ function Set-AzEventHubConsumerGroup{ } process{ try{ - $targetParameters = @{} + $PSBoundParameters - $hasUserMetadata = $targetParameters.Remove('UserMetadata') - $hasAsJob = $targetParameters.Remove('AsJob') - $null = $targetParameters.Remove('WhatIf') - $null = $targetParameters.Remove('Confirm') + $hasUserMetadata = $PSBoundParameters.Remove('UserMetadata') + $hasAsJob = $PSBoundParameters.Remove('AsJob') + $null = $PSBoundParameters.Remove('WhatIf') + $null = $PSBoundParameters.Remove('Confirm') - $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHubConsumerGroup' -BoundParameters $targetParameters + $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHubConsumerGroup' -BoundParameters $PSBoundParameters $consumerGroup = Get-AzEventHubConsumerGroup @readParameters # 2. PUT - $null = $targetParameters.Remove('InputObject') - $null = $targetParameters.Remove('ResourceGroupName') - $null = $targetParameters.Remove('NamespaceName') - $null = $targetParameters.Remove('EventHubName') - $null = $targetParameters.Remove('Name') - $null = $targetParameters.Remove('SubscriptionId') + $null = $PSBoundParameters.Remove('InputObject') + $null = $PSBoundParameters.Remove('ResourceGroupName') + $null = $PSBoundParameters.Remove('NamespaceName') + $null = $PSBoundParameters.Remove('EventHubName') + $null = $PSBoundParameters.Remove('Name') + $null = $PSBoundParameters.Remove('SubscriptionId') if ($hasUserMetadata) { $consumerGroup.UserMetadata = $UserMetadata } if ($hasAsJob) { - $targetParameters.Add('AsJob', $true) + $PSBoundParameters.Add('AsJob', $true) } if ($PSCmdlet.ShouldProcess("EventHub Consumer Group $($consumerGroup.Name)", "Create or update")) { - Az.EventHub.private\New-AzEventHubConsumerGroup_CreateViaIdentity -InputObject $consumerGroup -Parameter $consumerGroup @targetParameters + Az.EventHub.private\New-AzEventHubConsumerGroup_CreateViaIdentity -InputObject $consumerGroup -Parameter $consumerGroup @PSBoundParameters } } catch{ diff --git a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubGeoDRConfigurationBreakPair.ps1 b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubGeoDRConfigurationBreakPair.ps1 index 6e9642409fa5..0690e9f819ca 100644 --- a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubGeoDRConfigurationBreakPair.ps1 +++ b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubGeoDRConfigurationBreakPair.ps1 @@ -127,44 +127,43 @@ function Set-AzEventHubGeoDRConfigurationBreakPair{ } process{ try{ - $targetParameters = @{} + $PSBoundParameters - $hasAsJob = $targetParameters.Remove('AsJob') - $null = $targetParameters.Remove('WhatIf') - $null = $targetParameters.Remove('Confirm') + $hasAsJob = $PSBoundParameters.Remove('AsJob') + $null = $PSBoundParameters.Remove('WhatIf') + $null = $PSBoundParameters.Remove('Confirm') - $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHubGeoDRConfiguration' -BoundParameters $targetParameters + $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHubGeoDRConfiguration' -BoundParameters $PSBoundParameters $drConfig = Get-AzEventHubGeoDRConfiguration @readParameters # 2. PUT - $null = $targetParameters.Remove('InputObject') + $null = $PSBoundParameters.Remove('InputObject') if ($hasAsJob) { - $targetParameters.Add('AsJob', $true) + $PSBoundParameters.Add('AsJob', $true) } if($PSCmdlet.ParameterSetName -eq 'Break'){ if ($PSCmdlet.ShouldProcess("EventHub Disaster Recovery Alias $($Name)", "Break Pair")) { - Az.EventHub.private\Invoke-AzEventHubBreakDisasterRecoveryConfigPairing_Break @targetParameters + Az.EventHub.private\Invoke-AzEventHubBreakDisasterRecoveryConfigPairing_Break @PSBoundParameters } } elseif($PSCmdlet.ParameterSetName -eq 'BreakViaIdentity'){ $EnvPSBoundParameters = @{} - if ($targetParameters.ContainsKey('Debug')) { + if ($PSBoundParameters.ContainsKey('Debug')) { $EnvPSBoundParameters['Debug'] = $Debug } - if ($targetParameters.ContainsKey('HttpPipelineAppend')) { + if ($PSBoundParameters.ContainsKey('HttpPipelineAppend')) { $EnvPSBoundParameters['HttpPipelineAppend'] = $HttpPipelineAppend } - if ($targetParameters.ContainsKey('HttpPipelinePrepend')) { + if ($PSBoundParameters.ContainsKey('HttpPipelinePrepend')) { $EnvPSBoundParameters['HttpPipelinePrepend'] = $HttpPipelinePrepend } - if ($targetParameters.ContainsKey('Proxy')) { + if ($PSBoundParameters.ContainsKey('Proxy')) { $EnvPSBoundParameters['Proxy'] = $Proxy } - if ($targetParameters.ContainsKey('ProxyCredential')) { + if ($PSBoundParameters.ContainsKey('ProxyCredential')) { $EnvPSBoundParameters['ProxyCredential'] = $ProxyCredential } - if ($targetParameters.ContainsKey('ProxyUseDefaultCredentials')) { + if ($PSBoundParameters.ContainsKey('ProxyUseDefaultCredentials')) { $EnvPSBoundParameters['ProxyUseDefaultCredentials'] = $ProxyUseDefaultCredentials } diff --git a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubGeoDRConfigurationFailOver.ps1 b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubGeoDRConfigurationFailOver.ps1 index 22b3fc96b502..fcc032fc5807 100644 --- a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubGeoDRConfigurationFailOver.ps1 +++ b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubGeoDRConfigurationFailOver.ps1 @@ -127,44 +127,43 @@ function Set-AzEventHubGeoDRConfigurationFailOver{ } process{ try{ - $targetParameters = @{} + $PSBoundParameters - $hasAsJob = $targetParameters.Remove('AsJob') - $null = $targetParameters.Remove('WhatIf') - $null = $targetParameters.Remove('Confirm') + $hasAsJob = $PSBoundParameters.Remove('AsJob') + $null = $PSBoundParameters.Remove('WhatIf') + $null = $PSBoundParameters.Remove('Confirm') - $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHubGeoDRConfiguration' -BoundParameters $targetParameters + $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHubGeoDRConfiguration' -BoundParameters $PSBoundParameters $drConfig = Get-AzEventHubGeoDRConfiguration @readParameters # 2. PUT - $null = $targetParameters.Remove('InputObject') + $null = $PSBoundParameters.Remove('InputObject') if ($hasAsJob) { - $targetParameters.Add('AsJob', $true) + $PSBoundParameters.Add('AsJob', $true) } if($PSCmdlet.ParameterSetName -eq 'Fail'){ if ($PSCmdlet.ShouldProcess("EventHub Disaster Recovery Alias $($Name)", "Fail Over")) { - Az.EventHub.private\Invoke-AzEventHubFailDisasterRecoveryConfigOver_Fail @targetParameters + Az.EventHub.private\Invoke-AzEventHubFailDisasterRecoveryConfigOver_Fail @PSBoundParameters } } elseif($PSCmdlet.ParameterSetName -eq 'FailViaIdentity'){ $EnvPSBoundParameters = @{} - if ($targetParameters.ContainsKey('Debug')) { + if ($PSBoundParameters.ContainsKey('Debug')) { $EnvPSBoundParameters['Debug'] = $Debug } - if ($targetParameters.ContainsKey('HttpPipelineAppend')) { + if ($PSBoundParameters.ContainsKey('HttpPipelineAppend')) { $EnvPSBoundParameters['HttpPipelineAppend'] = $HttpPipelineAppend } - if ($targetParameters.ContainsKey('HttpPipelinePrepend')) { + if ($PSBoundParameters.ContainsKey('HttpPipelinePrepend')) { $EnvPSBoundParameters['HttpPipelinePrepend'] = $HttpPipelinePrepend } - if ($targetParameters.ContainsKey('Proxy')) { + if ($PSBoundParameters.ContainsKey('Proxy')) { $EnvPSBoundParameters['Proxy'] = $Proxy } - if ($targetParameters.ContainsKey('ProxyCredential')) { + if ($PSBoundParameters.ContainsKey('ProxyCredential')) { $EnvPSBoundParameters['ProxyCredential'] = $ProxyCredential } - if ($targetParameters.ContainsKey('ProxyUseDefaultCredentials')) { + if ($PSBoundParameters.ContainsKey('ProxyUseDefaultCredentials')) { $EnvPSBoundParameters['ProxyUseDefaultCredentials'] = $ProxyUseDefaultCredentials } diff --git a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubNamespace.ps1 b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubNamespace.ps1 index a50c38fd8236..c0e71432c3ca 100644 --- a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubNamespace.ps1 +++ b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubNamespace.ps1 @@ -204,34 +204,33 @@ function Set-AzEventHubNamespace{ } process{ try{ - $targetParameters = @{} + $PSBoundParameters - $hasAlternateName = $targetParameters.Remove('AlternateName') - $hasDisableLocalAuth = $targetParameters.Remove('DisableLocalAuth') - $hasKeyVaultProperty = $targetParameters.Remove('KeyVaultProperty') - $hasUserAssignedIdentityId = $targetParameters.Remove('UserAssignedIdentityId') - $hasIdentityType = $targetParameters.Remove('IdentityType') - $hasEnableAutoInflate = $targetParameters.Remove('EnableAutoInflate') - $hasMaximumThroughputUnit = $targetParameters.Remove('MaximumThroughputUnit') - $hasMinimumTlsVersion = $targetParameters.Remove('MinimumTlsVersion') - $hasRequireInfrastructureEncryption = $targetParameters.Remove('RequireInfrastructureEncryption') - $hasPublicNetworkAccess = $targetParameters.Remove('PublicNetworkAccess') - $hasSkuCapacity = $targetParameters.Remove('SkuCapacity') - $hasTag = $targetParameters.Remove('Tag') - $hasAsJob = $targetParameters.Remove('AsJob') - $hasIPAddressType = $targetParameters.Remove('IPAddressType') - $hasGeoDataReplicationLocation = $targetParameters.Remove('GeoDataReplicationLocation') - $hasGeoDataReplicationMaxReplicationLagDurationInSecond = $targetParameters.Remove('GeoDataReplicationMaxReplicationLagDurationInSecond') - $null = $targetParameters.Remove('WhatIf') - $null = $targetParameters.Remove('Confirm') - - $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHubNamespace' -BoundParameters $targetParameters + $hasAlternateName = $PSBoundParameters.Remove('AlternateName') + $hasDisableLocalAuth = $PSBoundParameters.Remove('DisableLocalAuth') + $hasKeyVaultProperty = $PSBoundParameters.Remove('KeyVaultProperty') + $hasUserAssignedIdentityId = $PSBoundParameters.Remove('UserAssignedIdentityId') + $hasIdentityType = $PSBoundParameters.Remove('IdentityType') + $hasEnableAutoInflate = $PSBoundParameters.Remove('EnableAutoInflate') + $hasMaximumThroughputUnit = $PSBoundParameters.Remove('MaximumThroughputUnit') + $hasMinimumTlsVersion = $PSBoundParameters.Remove('MinimumTlsVersion') + $hasRequireInfrastructureEncryption = $PSBoundParameters.Remove('RequireInfrastructureEncryption') + $hasPublicNetworkAccess = $PSBoundParameters.Remove('PublicNetworkAccess') + $hasSkuCapacity = $PSBoundParameters.Remove('SkuCapacity') + $hasTag = $PSBoundParameters.Remove('Tag') + $hasAsJob = $PSBoundParameters.Remove('AsJob') + $hasIPAddressType = $PSBoundParameters.Remove('IPAddressType') + $hasGeoDataReplicationLocation = $PSBoundParameters.Remove('GeoDataReplicationLocation') + $hasGeoDataReplicationMaxReplicationLagDurationInSecond = $PSBoundParameters.Remove('GeoDataReplicationMaxReplicationLagDurationInSecond') + $null = $PSBoundParameters.Remove('WhatIf') + $null = $PSBoundParameters.Remove('Confirm') + + $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHubNamespace' -BoundParameters $PSBoundParameters $eventHubNamespace = Get-AzEventHubNamespace @readParameters # 2. PUT - $null = $targetParameters.Remove('InputObject') - $null = $targetParameters.Remove('ResourceGroupName') - $null = $targetParameters.Remove('NamespaceName') - $null = $targetParameters.Remove('Name') - $null = $targetParameters.Remove('SubscriptionId') + $null = $PSBoundParameters.Remove('InputObject') + $null = $PSBoundParameters.Remove('ResourceGroupName') + $null = $PSBoundParameters.Remove('NamespaceName') + $null = $PSBoundParameters.Remove('Name') + $null = $PSBoundParameters.Remove('SubscriptionId') if ($hasAlternateName) { $eventHubNamespace.AlternateName = $AlternateName @@ -286,11 +285,11 @@ function Set-AzEventHubNamespace{ $eventHubNamespace.Tag = $Tag } if ($hasAsJob) { - $targetParameters.Add('AsJob', $true) + $PSBoundParameters.Add('AsJob', $true) } if ($PSCmdlet.ShouldProcess("EventHubNamespace $($eventHubNamespace.Name)", "Create or update")) { - Az.EventHub.private\New-AzEventHubNamespace_CreateViaIdentity -InputObject $eventHubNamespace -Parameter $eventHubNamespace @targetParameters + Az.EventHub.private\New-AzEventHubNamespace_CreateViaIdentity -InputObject $eventHubNamespace -Parameter $eventHubNamespace @PSBoundParameters } } catch{ diff --git a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubNetworkRuleSet.ps1 b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubNetworkRuleSet.ps1 index 1918a8564909..4aafff9b633d 100644 --- a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubNetworkRuleSet.ps1 +++ b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubNetworkRuleSet.ps1 @@ -152,23 +152,22 @@ function Set-AzEventHubNetworkRuleSet{ } process{ try{ - $targetParameters = @{} + $PSBoundParameters - $hasPublicNetworkAccess = $targetParameters.Remove('PublicNetworkAccess') - $hasTrustedServiceAccessEnabled = $targetParameters.Remove('TrustedServiceAccessEnabled') - $hasDefaultAction = $targetParameters.Remove('DefaultAction') - $hasIPRule = $targetParameters.Remove('IPRule') - $hasVirtualNetworkRule = $targetParameters.Remove('VirtualNetworkRule') - $hasAsJob = $targetParameters.Remove('AsJob') - $null = $targetParameters.Remove('WhatIf') - $null = $targetParameters.Remove('Confirm') - - $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHubNetworkRuleSet' -BoundParameters $targetParameters + $hasPublicNetworkAccess = $PSBoundParameters.Remove('PublicNetworkAccess') + $hasTrustedServiceAccessEnabled = $PSBoundParameters.Remove('TrustedServiceAccessEnabled') + $hasDefaultAction = $PSBoundParameters.Remove('DefaultAction') + $hasIPRule = $PSBoundParameters.Remove('IPRule') + $hasVirtualNetworkRule = $PSBoundParameters.Remove('VirtualNetworkRule') + $hasAsJob = $PSBoundParameters.Remove('AsJob') + $null = $PSBoundParameters.Remove('WhatIf') + $null = $PSBoundParameters.Remove('Confirm') + + $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHubNetworkRuleSet' -BoundParameters $PSBoundParameters $networkRuleSet = Get-AzEventHubNetworkRuleSet @readParameters # 2. PUT - $null = $targetParameters.Remove('InputObject') - $null = $targetParameters.Remove('ResourceGroupName') - $null = $targetParameters.Remove('NamespaceName') - $null = $targetParameters.Remove('SubscriptionId') + $null = $PSBoundParameters.Remove('InputObject') + $null = $PSBoundParameters.Remove('ResourceGroupName') + $null = $PSBoundParameters.Remove('NamespaceName') + $null = $PSBoundParameters.Remove('SubscriptionId') $hasProperty = $false @@ -198,11 +197,11 @@ function Set-AzEventHubNetworkRuleSet{ } if ($hasAsJob) { - $targetParameters.Add('AsJob', $true) + $PSBoundParameters.Add('AsJob', $true) } if ($PSCmdlet.ShouldProcess("EventHub Network Rule Set on namespace $($networkRuleSet.Name)", "Create or update")) { - Az.EventHub.private\New-AzEventHubNetworkRuleSet_CreateViaIdentity -InputObject $networkRuleSet -Parameter $networkRuleSet @targetParameters + Az.EventHub.private\New-AzEventHubNetworkRuleSet_CreateViaIdentity -InputObject $networkRuleSet -Parameter $networkRuleSet @PSBoundParameters } } catch{ diff --git a/src/EventHub/EventHub.Autorest/test/ReadParameterForwarding.Tests.ps1 b/src/EventHub/EventHub.Autorest/test/ReadParameterForwarding.Tests.ps1 index 507292ab582e..932345a56e85 100644 --- a/src/EventHub/EventHub.Autorest/test/ReadParameterForwarding.Tests.ps1 +++ b/src/EventHub/EventHub.Autorest/test/ReadParameterForwarding.Tests.ps1 @@ -30,8 +30,8 @@ function Set-AzEventHubReadTestResource { Set-Alias -Name Get-AzEventHubReadTestAlias -Value Get-AzEventHubReadTestResource Describe 'EventHub read parameter forwarding' { - It 'filters write-only parameters using read command metadata without changing target parameters' { - $targetParameters = @{ + It 'filters write-only parameters using read command metadata without changing write parameters' { + $writeParameters = @{ Name = 'eventhub' DefaultProfile = 'profile' ErrorAction = 'Stop' @@ -40,9 +40,9 @@ Describe 'EventHub read parameter forwarding' { SyntheticWriteOnly = 'future-value' } - $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHubReadTestAlias' -BoundParameters $targetParameters + $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHubReadTestAlias' -BoundParameters $writeParameters Get-AzEventHubReadTestResource @readParameters - Set-AzEventHubReadTestResource @targetParameters + Set-AzEventHubReadTestResource @writeParameters $script:eventHubReadParameters.Name | Should Be 'eventhub' $script:eventHubReadParameters.DefaultProfile | Should Be 'profile' @@ -61,7 +61,7 @@ Describe 'EventHub read parameter forwarding' { $readParameters.ResourceName | Should Be 'eventhub' } - It 'uses separate read and target parameter groups in every affected wrapper' { + It 'uses read parameters without replacing the original bound parameters in every affected wrapper' { $wrappers = @( 'Approve-AzEventHubPrivateEndpointConnection.ps1', 'Deny-AzEventHubPrivateEndpointConnection.ps1', @@ -78,10 +78,10 @@ Describe 'EventHub read parameter forwarding' { foreach ($wrapper in $wrappers) { $source = Get-Content -Path (Join-Path $PSScriptRoot "..\custom\$wrapper") -Raw - $source | Should Match '\$targetParameters\s*=\s*@\{\}\s*\+\s*\$PSBoundParameters' - $source | Should Match 'Get-AzEventHubReadParameters\s+-CommandName' + $source | Should Not Match '\$targetParameters' + $source | Should Match 'Get-AzEventHubReadParameters\s+-CommandName\s+''[^'']+''\s+-BoundParameters\s+\$PSBoundParameters' $source | Should Match '@readParameters' - $source | Should Match '@targetParameters' + $source | Should Match '@PSBoundParameters' } } diff --git a/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterAccessRule.ps1 b/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterAccessRule.ps1 index 93ee0ce91e49..5318461046b5 100644 --- a/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterAccessRule.ps1 +++ b/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterAccessRule.ps1 @@ -199,7 +199,6 @@ function Update-AzNetworkSecurityPerimeterAccessRule { process { try { - $targetParameters = @{} + $PSBoundParameters # 1. GET # body params and AsJob @@ -208,21 +207,21 @@ function Update-AzNetworkSecurityPerimeterAccessRule { $bodyParamsMap = @{} ForEach($bodyParam in $bodyParams){ - $bodyParamsMap[$bodyParam] = $targetParameters.Remove($bodyParam) + $bodyParamsMap[$bodyParam] = $PSBoundParameters.Remove($bodyParam) } - $null = $targetParameters.Remove('WhatIf') - $null = $targetParameters.Remove('Confirm') + $null = $PSBoundParameters.Remove('WhatIf') + $null = $PSBoundParameters.Remove('Confirm') - $readParameters = Get-AzNetworkSecurityPerimeterReadParameters -CommandName 'Get-AzNetworkSecurityPerimeterAccessRule' -BoundParameters $targetParameters + $readParameters = Get-AzNetworkSecurityPerimeterReadParameters -CommandName 'Get-AzNetworkSecurityPerimeterAccessRule' -BoundParameters $PSBoundParameters $GETObject = Get-AzNetworkSecurityPerimeterAccessRule @readParameters # 2. PUT $pathParams = 'InputObject', 'ResourceGroupName', 'Name', 'SubscriptionId', 'SecurityPerimeterName', 'ProfileName' ForEach($pathParam in $pathParams){ - $null = $targetParameters.Remove($pathParam) + $null = $PSBoundParameters.Remove($pathParam) } foreach ($item in $bodyParamsMap.GetEnumerator() ) @@ -237,7 +236,7 @@ function Update-AzNetworkSecurityPerimeterAccessRule { } # Call PUT method - New-AzNetworkSecurityPerimeterAccessRule_CreateViaIdentity -InputObject $GETObject -Parameter $GETObject @targetParameters + New-AzNetworkSecurityPerimeterAccessRule_CreateViaIdentity -InputObject $GETObject -Parameter $GETObject @PSBoundParameters } diff --git a/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterAssociation.ps1 b/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterAssociation.ps1 index e2d2bbbf02d4..435dbc8626a4 100644 --- a/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterAssociation.ps1 +++ b/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterAssociation.ps1 @@ -168,7 +168,6 @@ function Update-AzNetworkSecurityPerimeterAssociation { process { try { - $targetParameters = @{} + $PSBoundParameters # 1. GET # body params and AsJob @@ -177,20 +176,20 @@ function Update-AzNetworkSecurityPerimeterAssociation { $bodyParamsMap = @{} ForEach($bodyParam in $bodyParams){ - $bodyParamsMap[$bodyParam] = $targetParameters.Remove($bodyParam) + $bodyParamsMap[$bodyParam] = $PSBoundParameters.Remove($bodyParam) } - $null = $targetParameters.Remove('WhatIf') - $null = $targetParameters.Remove('Confirm') + $null = $PSBoundParameters.Remove('WhatIf') + $null = $PSBoundParameters.Remove('Confirm') - $readParameters = Get-AzNetworkSecurityPerimeterReadParameters -CommandName 'Get-AzNetworkSecurityPerimeterAssociation' -BoundParameters $targetParameters + $readParameters = Get-AzNetworkSecurityPerimeterReadParameters -CommandName 'Get-AzNetworkSecurityPerimeterAssociation' -BoundParameters $PSBoundParameters $GETObject = Get-AzNetworkSecurityPerimeterAssociation @readParameters # 2. PUT $pathParams = 'InputObject', 'ResourceGroupName', 'Name', 'SubscriptionId', 'SecurityPerimeterName' ForEach($pathParam in $pathParams){ - $null = $targetParameters.Remove($pathParam) + $null = $PSBoundParameters.Remove($pathParam) } foreach ($item in $bodyParamsMap.GetEnumerator() ) @@ -206,7 +205,7 @@ function Update-AzNetworkSecurityPerimeterAssociation { # Call PUT method - Az.NetworkSecurityPerimeter.private\New-AzNetworkSecurityPerimeterAssociation_CreateViaIdentity -InputObject $GETObject -Parameter $GETObject @targetParameters + Az.NetworkSecurityPerimeter.private\New-AzNetworkSecurityPerimeterAssociation_CreateViaIdentity -InputObject $GETObject -Parameter $GETObject @PSBoundParameters } catch { diff --git a/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterLink.ps1 b/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterLink.ps1 index d9199705f158..ff4dd68370c9 100644 --- a/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterLink.ps1 +++ b/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterLink.ps1 @@ -169,7 +169,6 @@ function Update-AzNetworkSecurityPerimeterLink { process { try { - $targetParameters = @{} + $PSBoundParameters # 1. GET # body params and AsJob @@ -178,20 +177,20 @@ function Update-AzNetworkSecurityPerimeterLink { $bodyParamsMap = @{} ForEach($bodyParam in $bodyParams){ - $bodyParamsMap[$bodyParam] = $targetParameters.Remove($bodyParam) + $bodyParamsMap[$bodyParam] = $PSBoundParameters.Remove($bodyParam) } - $null = $targetParameters.Remove('WhatIf') - $null = $targetParameters.Remove('Confirm') + $null = $PSBoundParameters.Remove('WhatIf') + $null = $PSBoundParameters.Remove('Confirm') - $readParameters = Get-AzNetworkSecurityPerimeterReadParameters -CommandName 'Get-AzNetworkSecurityPerimeterLink' -BoundParameters $targetParameters + $readParameters = Get-AzNetworkSecurityPerimeterReadParameters -CommandName 'Get-AzNetworkSecurityPerimeterLink' -BoundParameters $PSBoundParameters $GETObject = Get-AzNetworkSecurityPerimeterLink @readParameters # 2. PUT $pathParams = 'InputObject', 'ResourceGroupName', 'Name', 'SubscriptionId', 'SecurityPerimeterName' ForEach($pathParam in $pathParams){ - $null = $targetParameters.Remove($pathParam) + $null = $PSBoundParameters.Remove($pathParam) } foreach ($item in $bodyParamsMap.GetEnumerator() ) @@ -207,7 +206,7 @@ function Update-AzNetworkSecurityPerimeterLink { # Call PUT method - Az.NetworkSecurityPerimeter.private\New-AzNetworkSecurityPerimeterLink_CreateViaIdentity -InputObject $GETObject -Parameter $GETObject @targetParameters + Az.NetworkSecurityPerimeter.private\New-AzNetworkSecurityPerimeterLink_CreateViaIdentity -InputObject $GETObject -Parameter $GETObject @PSBoundParameters } catch { diff --git a/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterLoggingConfiguration.ps1 b/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterLoggingConfiguration.ps1 index 75c21bea806e..58df42f1eaf3 100644 --- a/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterLoggingConfiguration.ps1 +++ b/src/Network/NetworkSecurityPerimeter.Autorest/custom/Update-AzNetworkSecurityPerimeterLoggingConfiguration.ps1 @@ -157,7 +157,6 @@ function Update-AzNetworkSecurityPerimeterLoggingConfiguration { process { try { - $targetParameters = @{} + $PSBoundParameters # 1. GET # body params and AsJob @@ -166,20 +165,20 @@ function Update-AzNetworkSecurityPerimeterLoggingConfiguration { $bodyParamsMap = @{} ForEach($bodyParam in $bodyParams){ - $bodyParamsMap[$bodyParam] = $targetParameters.Remove($bodyParam) + $bodyParamsMap[$bodyParam] = $PSBoundParameters.Remove($bodyParam) } - $null = $targetParameters.Remove('WhatIf') - $null = $targetParameters.Remove('Confirm') + $null = $PSBoundParameters.Remove('WhatIf') + $null = $PSBoundParameters.Remove('Confirm') - $readParameters = Get-AzNetworkSecurityPerimeterReadParameters -CommandName 'Get-AzNetworkSecurityPerimeterLoggingConfiguration' -BoundParameters $targetParameters + $readParameters = Get-AzNetworkSecurityPerimeterReadParameters -CommandName 'Get-AzNetworkSecurityPerimeterLoggingConfiguration' -BoundParameters $PSBoundParameters $GETObject = Get-AzNetworkSecurityPerimeterLoggingConfiguration @readParameters # 2. PUT $pathParams = 'InputObject', 'ResourceGroupName', 'Name', 'SubscriptionId', 'SecurityPerimeterName' ForEach($pathParam in $pathParams){ - $null = $targetParameters.Remove($pathParam) + $null = $PSBoundParameters.Remove($pathParam) } foreach ($item in $bodyParamsMap.GetEnumerator() ) @@ -195,7 +194,7 @@ function Update-AzNetworkSecurityPerimeterLoggingConfiguration { # Call PUT method - New-AzNetworkSecurityPerimeterLoggingConfiguration_CreateViaIdentity -InputObject $GETObject -Parameter $GETObject @targetParameters + New-AzNetworkSecurityPerimeterLoggingConfiguration_CreateViaIdentity -InputObject $GETObject -Parameter $GETObject @PSBoundParameters } catch { diff --git a/src/Network/NetworkSecurityPerimeter.Autorest/test/ReadParameterForwarding.Tests.ps1 b/src/Network/NetworkSecurityPerimeter.Autorest/test/ReadParameterForwarding.Tests.ps1 index 74b020b57a15..729f972d722d 100644 --- a/src/Network/NetworkSecurityPerimeter.Autorest/test/ReadParameterForwarding.Tests.ps1 +++ b/src/Network/NetworkSecurityPerimeter.Autorest/test/ReadParameterForwarding.Tests.ps1 @@ -30,8 +30,8 @@ function Set-AzNetworkSecurityPerimeterReadTestResource { Set-Alias -Name Get-AzNetworkSecurityPerimeterReadTestAlias -Value Get-AzNetworkSecurityPerimeterReadTestResource Describe 'NetworkSecurityPerimeter read parameter forwarding' { - It 'filters write-only parameters using read command metadata without changing target parameters' { - $targetParameters = @{ + It 'filters write-only parameters using read command metadata without changing write parameters' { + $writeParameters = @{ Name = 'access-rule' DefaultProfile = 'profile' ErrorAction = 'Stop' @@ -40,9 +40,9 @@ Describe 'NetworkSecurityPerimeter read parameter forwarding' { SyntheticWriteOnly = 'future-value' } - $readParameters = Get-AzNetworkSecurityPerimeterReadParameters -CommandName 'Get-AzNetworkSecurityPerimeterReadTestAlias' -BoundParameters $targetParameters + $readParameters = Get-AzNetworkSecurityPerimeterReadParameters -CommandName 'Get-AzNetworkSecurityPerimeterReadTestAlias' -BoundParameters $writeParameters Get-AzNetworkSecurityPerimeterReadTestResource @readParameters - Set-AzNetworkSecurityPerimeterReadTestResource @targetParameters + Set-AzNetworkSecurityPerimeterReadTestResource @writeParameters $script:nspReadParameters.Name | Should Be 'access-rule' $script:nspReadParameters.DefaultProfile | Should Be 'profile' @@ -61,7 +61,7 @@ Describe 'NetworkSecurityPerimeter read parameter forwarding' { $readParameters.ResourceName | Should Be 'access-rule' } - It 'uses separate read and target parameter groups in every affected wrapper' { + It 'uses read parameters without replacing the original bound parameters in every affected wrapper' { $wrappers = @( 'Update-AzNetworkSecurityPerimeterAccessRule.ps1', 'Update-AzNetworkSecurityPerimeterAssociation.ps1', @@ -71,10 +71,10 @@ Describe 'NetworkSecurityPerimeter read parameter forwarding' { foreach ($wrapper in $wrappers) { $source = Get-Content -Path (Join-Path $PSScriptRoot "..\custom\$wrapper") -Raw - $source | Should Match '\$targetParameters\s*=\s*@\{\}\s*\+\s*\$PSBoundParameters' - $source | Should Match 'Get-AzNetworkSecurityPerimeterReadParameters\s+-CommandName' + $source | Should Not Match '\$targetParameters' + $source | Should Match 'Get-AzNetworkSecurityPerimeterReadParameters\s+-CommandName\s+''[^'']+''\s+-BoundParameters\s+\$PSBoundParameters' $source | Should Match '@readParameters' - $source | Should Match '@targetParameters' + $source | Should Match '@PSBoundParameters' } } diff --git a/src/ServiceBus/ServiceBus.Autorest/custom/Approve-AzServiceBusPrivateEndpointConnection.ps1 b/src/ServiceBus/ServiceBus.Autorest/custom/Approve-AzServiceBusPrivateEndpointConnection.ps1 index 3040099f93f8..2c55e483ecba 100644 --- a/src/ServiceBus/ServiceBus.Autorest/custom/Approve-AzServiceBusPrivateEndpointConnection.ps1 +++ b/src/ServiceBus/ServiceBus.Autorest/custom/Approve-AzServiceBusPrivateEndpointConnection.ps1 @@ -135,13 +135,12 @@ function Approve-AzServiceBusPrivateEndpointConnection{ } process{ try{ - $targetParameters = @{} + $PSBoundParameters - $hasDescription = $targetParameters.Remove('Description') - $hasAsJob = $targetParameters.Remove('AsJob') - $null = $targetParameters.Remove('WhatIf') - $null = $targetParameters.Remove('Confirm') + $hasDescription = $PSBoundParameters.Remove('Description') + $hasAsJob = $PSBoundParameters.Remove('AsJob') + $null = $PSBoundParameters.Remove('WhatIf') + $null = $PSBoundParameters.Remove('Confirm') - $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusPrivateEndpointConnection' -BoundParameters $targetParameters + $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusPrivateEndpointConnection' -BoundParameters $PSBoundParameters $connection = Get-AzServiceBusPrivateEndpointConnection @readParameters $connection.ConnectionState = "Approved" @@ -153,14 +152,14 @@ function Approve-AzServiceBusPrivateEndpointConnection{ } # 2. PUT - $null = $targetParameters.Remove('InputObject') - $null = $targetParameters.Remove('ResourceGroupName') - $null = $targetParameters.Remove('NamespaceName') - $null = $targetParameters.Remove('Name') - $null = $targetParameters.Remove('SubscriptionId') + $null = $PSBoundParameters.Remove('InputObject') + $null = $PSBoundParameters.Remove('ResourceGroupName') + $null = $PSBoundParameters.Remove('NamespaceName') + $null = $PSBoundParameters.Remove('Name') + $null = $PSBoundParameters.Remove('SubscriptionId') if ($PSCmdlet.ShouldProcess("Approve ServiceBus Namespace PrivateEndpoint Connection $($Name)", "Create or update")) { - Az.ServiceBus.private\New-AzServiceBusPrivateEndpointConnection_CreateViaIdentity -InputObject $connection -Parameter $connection @targetParameters + Az.ServiceBus.private\New-AzServiceBusPrivateEndpointConnection_CreateViaIdentity -InputObject $connection -Parameter $connection @PSBoundParameters } } catch{ diff --git a/src/ServiceBus/ServiceBus.Autorest/custom/Deny-AzServiceBusPrivateEndpointConnection.ps1 b/src/ServiceBus/ServiceBus.Autorest/custom/Deny-AzServiceBusPrivateEndpointConnection.ps1 index dbef3e27adf8..aecd45326fe6 100644 --- a/src/ServiceBus/ServiceBus.Autorest/custom/Deny-AzServiceBusPrivateEndpointConnection.ps1 +++ b/src/ServiceBus/ServiceBus.Autorest/custom/Deny-AzServiceBusPrivateEndpointConnection.ps1 @@ -135,13 +135,12 @@ function Deny-AzServiceBusPrivateEndpointConnection{ } process{ try{ - $targetParameters = @{} + $PSBoundParameters - $hasDescription = $targetParameters.Remove('Description') - $hasAsJob = $targetParameters.Remove('AsJob') - $null = $targetParameters.Remove('WhatIf') - $null = $targetParameters.Remove('Confirm') + $hasDescription = $PSBoundParameters.Remove('Description') + $hasAsJob = $PSBoundParameters.Remove('AsJob') + $null = $PSBoundParameters.Remove('WhatIf') + $null = $PSBoundParameters.Remove('Confirm') - $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusPrivateEndpointConnection' -BoundParameters $targetParameters + $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusPrivateEndpointConnection' -BoundParameters $PSBoundParameters $connection = Get-AzServiceBusPrivateEndpointConnection @readParameters $connection.ConnectionState = "Rejected" @@ -153,14 +152,14 @@ function Deny-AzServiceBusPrivateEndpointConnection{ } # 2. PUT - $null = $targetParameters.Remove('InputObject') - $null = $targetParameters.Remove('ResourceGroupName') - $null = $targetParameters.Remove('NamespaceName') - $null = $targetParameters.Remove('Name') - $null = $targetParameters.Remove('SubscriptionId') + $null = $PSBoundParameters.Remove('InputObject') + $null = $PSBoundParameters.Remove('ResourceGroupName') + $null = $PSBoundParameters.Remove('NamespaceName') + $null = $PSBoundParameters.Remove('Name') + $null = $PSBoundParameters.Remove('SubscriptionId') if ($PSCmdlet.ShouldProcess("Approve ServiceBus Namespace PrivateEndpoint Connection $($Name)", "Create or update")) { - Az.ServiceBus.private\New-AzServiceBusPrivateEndpointConnection_CreateViaIdentity -InputObject $connection -Parameter $connection @targetParameters + Az.ServiceBus.private\New-AzServiceBusPrivateEndpointConnection_CreateViaIdentity -InputObject $connection -Parameter $connection @PSBoundParameters } } catch{ diff --git a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusAuthorizationRule.ps1 b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusAuthorizationRule.ps1 index b193cabf661d..2002da26ccd8 100644 --- a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusAuthorizationRule.ps1 +++ b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusAuthorizationRule.ps1 @@ -155,29 +155,28 @@ function Set-AzServiceBusAuthorizationRule{ } process{ try{ - $targetParameters = @{} + $PSBoundParameters - $hasRights = $targetParameters.Remove('Rights') - $hasAsJob = $targetParameters.Remove('AsJob') - $null = $targetParameters.Remove('WhatIf') - $null = $targetParameters.Remove('Confirm') + $hasRights = $PSBoundParameters.Remove('Rights') + $hasAsJob = $PSBoundParameters.Remove('AsJob') + $null = $PSBoundParameters.Remove('WhatIf') + $null = $PSBoundParameters.Remove('Confirm') if ($PSCmdlet.ParameterSetName -eq 'SetExpandedQueue'){ - $readParameters = Get-AzServiceBusReadParameters -CommandName 'Az.ServiceBus.private\Get-AzServiceBusQueueAuthorizationRule_Get' -BoundParameters $targetParameters + $readParameters = Get-AzServiceBusReadParameters -CommandName 'Az.ServiceBus.private\Get-AzServiceBusQueueAuthorizationRule_Get' -BoundParameters $PSBoundParameters $authRule = Az.ServiceBus.private\Get-AzServiceBusQueueAuthorizationRule_Get @readParameters } elseif ($PSCmdlet.ParameterSetName -eq 'SetExpandedTopic'){ - $readParameters = Get-AzServiceBusReadParameters -CommandName 'Az.ServiceBus.private\Get-AzServiceBusTopicAuthorizationRule_Get' -BoundParameters $targetParameters + $readParameters = Get-AzServiceBusReadParameters -CommandName 'Az.ServiceBus.private\Get-AzServiceBusTopicAuthorizationRule_Get' -BoundParameters $PSBoundParameters $authRule = Az.ServiceBus.private\Get-AzServiceBusTopicAuthorizationRule_Get @readParameters } elseif ($PSCmdlet.ParameterSetName -eq 'SetExpandedNamespace'){ - $readParameters = Get-AzServiceBusReadParameters -CommandName 'Az.ServiceBus.private\Get-AzServiceBusNamespaceAuthorizationRule_Get' -BoundParameters $targetParameters + $readParameters = Get-AzServiceBusReadParameters -CommandName 'Az.ServiceBus.private\Get-AzServiceBusNamespaceAuthorizationRule_Get' -BoundParameters $PSBoundParameters $authRule = Az.ServiceBus.private\Get-AzServiceBusNamespaceAuthorizationRule_Get @readParameters } if ($hasAsJob) { - $targetParameters.Add('AsJob', $true) + $PSBoundParameters.Add('AsJob', $true) } elseif ($PSCmdlet.ParameterSetName -eq 'SetViaIdentityExpanded'){ @@ -190,15 +189,15 @@ function Set-AzServiceBusAuthorizationRule{ } if ($ResourceHashTable['QueueName'] -ne $null){ - $readParameters = Get-AzServiceBusReadParameters -CommandName 'Az.ServiceBus.private\Get-AzServiceBusQueueAuthorizationRule_GetViaIdentity' -BoundParameters $targetParameters + $readParameters = Get-AzServiceBusReadParameters -CommandName 'Az.ServiceBus.private\Get-AzServiceBusQueueAuthorizationRule_GetViaIdentity' -BoundParameters $PSBoundParameters $authRule = Az.ServiceBus.private\Get-AzServiceBusQueueAuthorizationRule_GetViaIdentity @readParameters } elseif ($ResourceHashTable['TopicName'] -ne $null){ - $readParameters = Get-AzServiceBusReadParameters -CommandName 'Az.ServiceBus.private\Get-AzServiceBusTopicAuthorizationRule_GetViaIdentity' -BoundParameters $targetParameters + $readParameters = Get-AzServiceBusReadParameters -CommandName 'Az.ServiceBus.private\Get-AzServiceBusTopicAuthorizationRule_GetViaIdentity' -BoundParameters $PSBoundParameters $authRule = Az.ServiceBus.private\Get-AzServiceBusTopicAuthorizationRule_GetViaIdentity @readParameters } elseif ($ResourceHashTable['NamespaceName'] -ne $null){ - $readParameters = Get-AzServiceBusReadParameters -CommandName 'Az.ServiceBus.private\Get-AzServiceBusNamespaceAuthorizationRule_GetViaIdentity' -BoundParameters $targetParameters + $readParameters = Get-AzServiceBusReadParameters -CommandName 'Az.ServiceBus.private\Get-AzServiceBusNamespaceAuthorizationRule_GetViaIdentity' -BoundParameters $PSBoundParameters $authRule = Az.ServiceBus.private\Get-AzServiceBusNamespaceAuthorizationRule_GetViaIdentity @readParameters } else{ @@ -208,36 +207,36 @@ function Set-AzServiceBusAuthorizationRule{ } # 2. PUT - $null = $targetParameters.Remove('InputObject') - $null = $targetParameters.Remove('ResourceGroupName') - $null = $targetParameters.Remove('NamespaceName') - $null = $targetParameters.Remove('QueueName') - $null = $targetParameters.Remove('TopicName') - $null = $targetParameters.Remove('Name') - $null = $targetParameters.Remove('SubscriptionId') + $null = $PSBoundParameters.Remove('InputObject') + $null = $PSBoundParameters.Remove('ResourceGroupName') + $null = $PSBoundParameters.Remove('NamespaceName') + $null = $PSBoundParameters.Remove('QueueName') + $null = $PSBoundParameters.Remove('TopicName') + $null = $PSBoundParameters.Remove('Name') + $null = $PSBoundParameters.Remove('SubscriptionId') if ($hasRights) { $authRule.Rights = $Rights } if ($hasAsJob) { - $targetParameters.Add('AsJob', $true) + $PSBoundParameters.Add('AsJob', $true) } if ($PSCmdlet.ParameterSetName -eq 'SetExpandedNamespace'){ if ($PSCmdlet.ShouldProcess("ServiceBus Namespace Authorization Rule $($authRule.Name)", "Create or update")) { - Az.ServiceBus.private\New-AzServiceBusNamespaceAuthorizationRule_CreateViaIdentity -InputObject $authRule -Parameter $authRule @targetParameters + Az.ServiceBus.private\New-AzServiceBusNamespaceAuthorizationRule_CreateViaIdentity -InputObject $authRule -Parameter $authRule @PSBoundParameters } } elseif ($PSCmdlet.ParameterSetName -eq 'SetExpandedQueue'){ if ($PSCmdlet.ShouldProcess("ServiceBus Queue Authorization Rule $($authRule.Name)", "Create or update")) { - Az.ServiceBus.private\New-AzServiceBusQueueAuthorizationRule_CreateViaIdentity -InputObject $authRule -Parameter $authRule @targetParameters + Az.ServiceBus.private\New-AzServiceBusQueueAuthorizationRule_CreateViaIdentity -InputObject $authRule -Parameter $authRule @PSBoundParameters } } elseif ($PSCmdlet.ParameterSetName -eq 'SetExpandedTopic'){ if ($PSCmdlet.ShouldProcess("ServiceBus Topic Authorization Rule $($authRule.Name)", "Create or update")) { - Az.ServiceBus.private\New-AzServiceBusTopicAuthorizationRule_CreateViaIdentity -InputObject $authRule -Parameter $authRule @targetParameters + Az.ServiceBus.private\New-AzServiceBusTopicAuthorizationRule_CreateViaIdentity -InputObject $authRule -Parameter $authRule @PSBoundParameters } } @@ -245,19 +244,19 @@ function Set-AzServiceBusAuthorizationRule{ if ($ResourceHashTable['QueueName'] -ne $null){ if ($PSCmdlet.ShouldProcess("ServiceBus Queue Authorization Rule $($ResourceHashTable['AuthorizationRuleName'])", "Create or update")) { - Az.ServiceBus.private\New-AzServiceBusQueueAuthorizationRule_CreateViaIdentity -InputObject $authRule -Parameter $authRule @targetParameters + Az.ServiceBus.private\New-AzServiceBusQueueAuthorizationRule_CreateViaIdentity -InputObject $authRule -Parameter $authRule @PSBoundParameters } } elseif ($ResourceHashTable['TopicName'] -ne $null){ if ($PSCmdlet.ShouldProcess("ServiceBus Topic Authorization Rule $($ResourceHashTable['AuthorizationRuleName'])", "Create or update")) { - Az.ServiceBus.private\New-AzServiceBusTopicAuthorizationRule_CreateViaIdentity -InputObject $authRule -Parameter $authRule @targetParameters + Az.ServiceBus.private\New-AzServiceBusTopicAuthorizationRule_CreateViaIdentity -InputObject $authRule -Parameter $authRule @PSBoundParameters } } elseif ($ResourceHashTable['NamespaceName'] -ne $null){ if ($PSCmdlet.ShouldProcess("ServiceBus Namespace Authorization Rule $($ResourceHashTable['AuthorizationRuleName'])", "Create or update")) { - Az.ServiceBus.private\New-AzServiceBusNamespaceAuthorizationRule_CreateViaIdentity -InputObject $authRule -Parameter $authRule @targetParameters + Az.ServiceBus.private\New-AzServiceBusNamespaceAuthorizationRule_CreateViaIdentity -InputObject $authRule -Parameter $authRule @PSBoundParameters } } diff --git a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusGeoDRConfigurationBreakPair.ps1 b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusGeoDRConfigurationBreakPair.ps1 index 892092d96bd0..75115c8a0543 100644 --- a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusGeoDRConfigurationBreakPair.ps1 +++ b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusGeoDRConfigurationBreakPair.ps1 @@ -128,44 +128,43 @@ function Set-AzServiceBusGeoDRConfigurationBreakPair{ } process{ try{ - $targetParameters = @{} + $PSBoundParameters - $hasAsJob = $targetParameters.Remove('AsJob') - $null = $targetParameters.Remove('WhatIf') - $null = $targetParameters.Remove('Confirm') + $hasAsJob = $PSBoundParameters.Remove('AsJob') + $null = $PSBoundParameters.Remove('WhatIf') + $null = $PSBoundParameters.Remove('Confirm') - $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusGeoDRConfiguration' -BoundParameters $targetParameters + $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusGeoDRConfiguration' -BoundParameters $PSBoundParameters $drConfig = Get-AzServiceBusGeoDRConfiguration @readParameters # 2. PUT - $null = $targetParameters.Remove('InputObject') + $null = $PSBoundParameters.Remove('InputObject') if ($hasAsJob) { - $targetParameters.Add('AsJob', $true) + $PSBoundParameters.Add('AsJob', $true) } if($PSCmdlet.ParameterSetName -eq 'Break'){ if ($PSCmdlet.ShouldProcess("ServiceBus Disaster Recovery Alias $($Name)", "Break Pair")) { - Az.ServiceBus.private\Invoke-AzServiceBusBreakDisasterRecoveryConfigPairing_Break @targetParameters + Az.ServiceBus.private\Invoke-AzServiceBusBreakDisasterRecoveryConfigPairing_Break @PSBoundParameters } } elseif($PSCmdlet.ParameterSetName -eq 'BreakViaIdentity'){ $EnvPSBoundParameters = @{} - if ($targetParameters.ContainsKey('Debug')) { + if ($PSBoundParameters.ContainsKey('Debug')) { $EnvPSBoundParameters['Debug'] = $Debug } - if ($targetParameters.ContainsKey('HttpPipelineAppend')) { + if ($PSBoundParameters.ContainsKey('HttpPipelineAppend')) { $EnvPSBoundParameters['HttpPipelineAppend'] = $HttpPipelineAppend } - if ($targetParameters.ContainsKey('HttpPipelinePrepend')) { + if ($PSBoundParameters.ContainsKey('HttpPipelinePrepend')) { $EnvPSBoundParameters['HttpPipelinePrepend'] = $HttpPipelinePrepend } - if ($targetParameters.ContainsKey('Proxy')) { + if ($PSBoundParameters.ContainsKey('Proxy')) { $EnvPSBoundParameters['Proxy'] = $Proxy } - if ($targetParameters.ContainsKey('ProxyCredential')) { + if ($PSBoundParameters.ContainsKey('ProxyCredential')) { $EnvPSBoundParameters['ProxyCredential'] = $ProxyCredential } - if ($targetParameters.ContainsKey('ProxyUseDefaultCredentials')) { + if ($PSBoundParameters.ContainsKey('ProxyUseDefaultCredentials')) { $EnvPSBoundParameters['ProxyUseDefaultCredentials'] = $ProxyUseDefaultCredentials } diff --git a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusGeoDRConfigurationFailOver.ps1 b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusGeoDRConfigurationFailOver.ps1 index 50cc77b0bef6..6254e296529f 100644 --- a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusGeoDRConfigurationFailOver.ps1 +++ b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusGeoDRConfigurationFailOver.ps1 @@ -128,44 +128,43 @@ function Set-AzServiceBusGeoDRConfigurationFailOver{ } process{ try{ - $targetParameters = @{} + $PSBoundParameters - $hasAsJob = $targetParameters.Remove('AsJob') - $null = $targetParameters.Remove('WhatIf') - $null = $targetParameters.Remove('Confirm') + $hasAsJob = $PSBoundParameters.Remove('AsJob') + $null = $PSBoundParameters.Remove('WhatIf') + $null = $PSBoundParameters.Remove('Confirm') - $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusGeoDRConfiguration' -BoundParameters $targetParameters + $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusGeoDRConfiguration' -BoundParameters $PSBoundParameters $drConfig = Get-AzServiceBusGeoDRConfiguration @readParameters # 2. PUT - $null = $targetParameters.Remove('InputObject') + $null = $PSBoundParameters.Remove('InputObject') if ($hasAsJob) { - $targetParameters.Add('AsJob', $true) + $PSBoundParameters.Add('AsJob', $true) } if($PSCmdlet.ParameterSetName -eq 'Fail'){ if ($PSCmdlet.ShouldProcess("ServiceBus Disaster Recovery Alias $($Name)", "Fail Over")) { - Az.ServiceBus.private\Invoke-AzServiceBusFailDisasterRecoveryConfigOver_FailExpanded @targetParameters + Az.ServiceBus.private\Invoke-AzServiceBusFailDisasterRecoveryConfigOver_FailExpanded @PSBoundParameters } } elseif($PSCmdlet.ParameterSetName -eq 'FailViaIdentity'){ $EnvPSBoundParameters = @{} - if ($targetParameters.ContainsKey('Debug')) { + if ($PSBoundParameters.ContainsKey('Debug')) { $EnvPSBoundParameters['Debug'] = $Debug } - if ($targetParameters.ContainsKey('HttpPipelineAppend')) { + if ($PSBoundParameters.ContainsKey('HttpPipelineAppend')) { $EnvPSBoundParameters['HttpPipelineAppend'] = $HttpPipelineAppend } - if ($targetParameters.ContainsKey('HttpPipelinePrepend')) { + if ($PSBoundParameters.ContainsKey('HttpPipelinePrepend')) { $EnvPSBoundParameters['HttpPipelinePrepend'] = $HttpPipelinePrepend } - if ($targetParameters.ContainsKey('Proxy')) { + if ($PSBoundParameters.ContainsKey('Proxy')) { $EnvPSBoundParameters['Proxy'] = $Proxy } - if ($targetParameters.ContainsKey('ProxyCredential')) { + if ($PSBoundParameters.ContainsKey('ProxyCredential')) { $EnvPSBoundParameters['ProxyCredential'] = $ProxyCredential } - if ($targetParameters.ContainsKey('ProxyUseDefaultCredentials')) { + if ($PSBoundParameters.ContainsKey('ProxyUseDefaultCredentials')) { $EnvPSBoundParameters['ProxyUseDefaultCredentials'] = $ProxyUseDefaultCredentials } diff --git a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusNamespace.ps1 b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusNamespace.ps1 index e290bb0f6368..50f1aabe7778 100644 --- a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusNamespace.ps1 +++ b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusNamespace.ps1 @@ -193,33 +193,32 @@ function Set-AzServiceBusNamespace{ } process{ try{ - $targetParameters = @{} + $PSBoundParameters - $hasAlternateName = $targetParameters.Remove('AlternateName') - $hasDisableLocalAuth = $targetParameters.Remove('DisableLocalAuth') - $hasKeyVaultProperty = $targetParameters.Remove('KeyVaultProperty') - $hasUserAssignedIdentityId = $targetParameters.Remove('UserAssignedIdentityId') - $hasIdentityType = $targetParameters.Remove('IdentityType') - $hasMinimumTlsVersion = $targetParameters.Remove('MinimumTlsVersion') - $hasRequireInfrastructureEncryption = $targetParameters.Remove('RequireInfrastructureEncryption') - $hasPublicNetworkAccess = $targetParameters.Remove('PublicNetworkAccess') - $hasSkuCapacity = $targetParameters.Remove('SkuCapacity') - $hasTag = $targetParameters.Remove('Tag') - $hasGeoDataReplicationMaxReplicationLagDurationInSecond = $targetParameters.Remove('GeoDataReplicationMaxReplicationLagDurationInSecond') - $hasGeoDataReplicationLocation = $targetParameters.Remove('GeoDataReplicationLocation') - $hasIPAddressType = $targetParameters.Remove('IPAddressType') - $hasDefaultProfile = $targetParameters.Remove('DefaultProfile') - $hasAsJob = $targetParameters.Remove('AsJob') - $hasNoWait = $targetParameters.Remove('NoWait') - $null = $targetParameters.Remove('WhatIf') - $null = $targetParameters.Remove('Confirm') - $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusNamespace' -BoundParameters $targetParameters + $hasAlternateName = $PSBoundParameters.Remove('AlternateName') + $hasDisableLocalAuth = $PSBoundParameters.Remove('DisableLocalAuth') + $hasKeyVaultProperty = $PSBoundParameters.Remove('KeyVaultProperty') + $hasUserAssignedIdentityId = $PSBoundParameters.Remove('UserAssignedIdentityId') + $hasIdentityType = $PSBoundParameters.Remove('IdentityType') + $hasMinimumTlsVersion = $PSBoundParameters.Remove('MinimumTlsVersion') + $hasRequireInfrastructureEncryption = $PSBoundParameters.Remove('RequireInfrastructureEncryption') + $hasPublicNetworkAccess = $PSBoundParameters.Remove('PublicNetworkAccess') + $hasSkuCapacity = $PSBoundParameters.Remove('SkuCapacity') + $hasTag = $PSBoundParameters.Remove('Tag') + $hasGeoDataReplicationMaxReplicationLagDurationInSecond = $PSBoundParameters.Remove('GeoDataReplicationMaxReplicationLagDurationInSecond') + $hasGeoDataReplicationLocation = $PSBoundParameters.Remove('GeoDataReplicationLocation') + $hasIPAddressType = $PSBoundParameters.Remove('IPAddressType') + $hasDefaultProfile = $PSBoundParameters.Remove('DefaultProfile') + $hasAsJob = $PSBoundParameters.Remove('AsJob') + $hasNoWait = $PSBoundParameters.Remove('NoWait') + $null = $PSBoundParameters.Remove('WhatIf') + $null = $PSBoundParameters.Remove('Confirm') + $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusNamespace' -BoundParameters $PSBoundParameters $serviceBusNamespace = Get-AzServiceBusNamespace @readParameters # 2. PUT - $null = $targetParameters.Remove('InputObject') - $null = $targetParameters.Remove('ResourceGroupName') - $null = $targetParameters.Remove('NamespaceName') - $null = $targetParameters.Remove('Name') - $null = $targetParameters.Remove('SubscriptionId') + $null = $PSBoundParameters.Remove('InputObject') + $null = $PSBoundParameters.Remove('ResourceGroupName') + $null = $PSBoundParameters.Remove('NamespaceName') + $null = $PSBoundParameters.Remove('Name') + $null = $PSBoundParameters.Remove('SubscriptionId') if ($hasAlternateName) { $serviceBusNamespace.AlternateName = $AlternateName @@ -268,15 +267,15 @@ function Set-AzServiceBusNamespace{ $serviceBusNamespace.IPAddressType = $IPAddressType } if ($hasAsJob) { - $targetParameters.Add('AsJob', $true) + $PSBoundParameters.Add('AsJob', $true) } if ($hasNoWait) { - $targetParameters.Add('NoWait', $true) + $PSBoundParameters.Add('NoWait', $true) } if ($PSCmdlet.ShouldProcess("ServiceBusNamespace $($serviceBusNamespace.Name)", "Create or update")) { - Az.ServiceBus.private\New-AzServiceBusNamespace_CreateViaIdentity -InputObject $serviceBusNamespace -Parameter $serviceBusNamespace @targetParameters + Az.ServiceBus.private\New-AzServiceBusNamespace_CreateViaIdentity -InputObject $serviceBusNamespace -Parameter $serviceBusNamespace @PSBoundParameters } } catch{ diff --git a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusNetworkRuleSet.ps1 b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusNetworkRuleSet.ps1 index 5b115f1cec04..01b29625820c 100644 --- a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusNetworkRuleSet.ps1 +++ b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusNetworkRuleSet.ps1 @@ -152,23 +152,22 @@ function Set-AzServiceBusNetworkRuleSet{ } process{ try{ - $targetParameters = @{} + $PSBoundParameters - $hasPublicNetworkAccess = $targetParameters.Remove('PublicNetworkAccess') - $hasTrustedServiceAccessEnabled = $targetParameters.Remove('TrustedServiceAccessEnabled') - $hasDefaultAction = $targetParameters.Remove('DefaultAction') - $hasIPRule = $targetParameters.Remove('IPRule') - $hasVirtualNetworkRule = $targetParameters.Remove('VirtualNetworkRule') - $hasAsJob = $targetParameters.Remove('AsJob') - $null = $targetParameters.Remove('WhatIf') - $null = $targetParameters.Remove('Confirm') - - $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusNetworkRuleSet' -BoundParameters $targetParameters + $hasPublicNetworkAccess = $PSBoundParameters.Remove('PublicNetworkAccess') + $hasTrustedServiceAccessEnabled = $PSBoundParameters.Remove('TrustedServiceAccessEnabled') + $hasDefaultAction = $PSBoundParameters.Remove('DefaultAction') + $hasIPRule = $PSBoundParameters.Remove('IPRule') + $hasVirtualNetworkRule = $PSBoundParameters.Remove('VirtualNetworkRule') + $hasAsJob = $PSBoundParameters.Remove('AsJob') + $null = $PSBoundParameters.Remove('WhatIf') + $null = $PSBoundParameters.Remove('Confirm') + + $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusNetworkRuleSet' -BoundParameters $PSBoundParameters $networkRuleSet = Get-AzServiceBusNetworkRuleSet @readParameters # 2. PUT - $null = $targetParameters.Remove('InputObject') - $null = $targetParameters.Remove('ResourceGroupName') - $null = $targetParameters.Remove('NamespaceName') - $null = $targetParameters.Remove('SubscriptionId') + $null = $PSBoundParameters.Remove('InputObject') + $null = $PSBoundParameters.Remove('ResourceGroupName') + $null = $PSBoundParameters.Remove('NamespaceName') + $null = $PSBoundParameters.Remove('SubscriptionId') $hasProperty = $false @@ -198,11 +197,11 @@ function Set-AzServiceBusNetworkRuleSet{ } if ($hasAsJob) { - $targetParameters.Add('AsJob', $true) + $PSBoundParameters.Add('AsJob', $true) } if ($PSCmdlet.ShouldProcess("ServiceBus Network Rule Set on namespace $($networkRuleSet.Name)", "Create or update")) { - Az.ServiceBus.private\New-AzServiceBusNetworkRuleSet_CreateViaIdentity -InputObject $networkRuleSet -Parameter $networkRuleSet @targetParameters + Az.ServiceBus.private\New-AzServiceBusNetworkRuleSet_CreateViaIdentity -InputObject $networkRuleSet -Parameter $networkRuleSet @PSBoundParameters } } catch{ diff --git a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusQueue.ps1 b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusQueue.ps1 index 69de7d9fd02c..904aea5d8b9b 100644 --- a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusQueue.ps1 +++ b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusQueue.ps1 @@ -213,32 +213,31 @@ function Set-AzServiceBusQueue{ process{ try{ - $targetParameters = @{} + $PSBoundParameters - $hasAutoDeleteOnIdle = $targetParameters.Remove('AutoDeleteOnIdle') - $hasDefaultMessageTimeToLive = $targetParameters.Remove('DefaultMessageTimeToLive') - $hasDeadLetteringOnMessageExpiration = $targetParameters.Remove('DeadLetteringOnMessageExpiration') - $hasDuplicateDetectionHistoryTimeWindow = $targetParameters.Remove('DuplicateDetectionHistoryTimeWindow') - $hasLockDuration = $targetParameters.Remove('LockDuration') - $hasEnableBatchedOperations = $targetParameters.Remove('EnableBatchedOperations') - $hasEnableExpress = $targetParameters.Remove('EnableExpress') - $hasForwardDeadLetteredMessagesTo = $targetParameters.Remove('ForwardDeadLetteredMessagesTo') - $hasForwardTo = $targetParameters.Remove('ForwardTo') - $hasMaxDeliveryCount = $targetParameters.Remove('MaxDeliveryCount') - $hasMaxMessageSizeInKilobytes = $targetParameters.Remove('MaxMessageSizeInKilobytes') - $hasMaxSizeInMegabytes = $targetParameters.Remove('MaxSizeInMegabytes') - $hasStatus = $targetParameters.Remove('Status') - $hasAsJob = $targetParameters.Remove('AsJob') - $null = $targetParameters.Remove('WhatIf') - $null = $targetParameters.Remove('Confirm') - - $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusQueue' -BoundParameters $targetParameters + $hasAutoDeleteOnIdle = $PSBoundParameters.Remove('AutoDeleteOnIdle') + $hasDefaultMessageTimeToLive = $PSBoundParameters.Remove('DefaultMessageTimeToLive') + $hasDeadLetteringOnMessageExpiration = $PSBoundParameters.Remove('DeadLetteringOnMessageExpiration') + $hasDuplicateDetectionHistoryTimeWindow = $PSBoundParameters.Remove('DuplicateDetectionHistoryTimeWindow') + $hasLockDuration = $PSBoundParameters.Remove('LockDuration') + $hasEnableBatchedOperations = $PSBoundParameters.Remove('EnableBatchedOperations') + $hasEnableExpress = $PSBoundParameters.Remove('EnableExpress') + $hasForwardDeadLetteredMessagesTo = $PSBoundParameters.Remove('ForwardDeadLetteredMessagesTo') + $hasForwardTo = $PSBoundParameters.Remove('ForwardTo') + $hasMaxDeliveryCount = $PSBoundParameters.Remove('MaxDeliveryCount') + $hasMaxMessageSizeInKilobytes = $PSBoundParameters.Remove('MaxMessageSizeInKilobytes') + $hasMaxSizeInMegabytes = $PSBoundParameters.Remove('MaxSizeInMegabytes') + $hasStatus = $PSBoundParameters.Remove('Status') + $hasAsJob = $PSBoundParameters.Remove('AsJob') + $null = $PSBoundParameters.Remove('WhatIf') + $null = $PSBoundParameters.Remove('Confirm') + + $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusQueue' -BoundParameters $PSBoundParameters $queue = Get-AzServiceBusQueue @readParameters # 2. PUT - $null = $targetParameters.Remove('InputObject') - $null = $targetParameters.Remove('ResourceGroupName') - $null = $targetParameters.Remove('NamespaceName') - $null = $targetParameters.Remove('Name') - $null = $targetParameters.Remove('SubscriptionId') + $null = $PSBoundParameters.Remove('InputObject') + $null = $PSBoundParameters.Remove('ResourceGroupName') + $null = $PSBoundParameters.Remove('NamespaceName') + $null = $PSBoundParameters.Remove('Name') + $null = $PSBoundParameters.Remove('SubscriptionId') $hasProperty = $false @@ -300,11 +299,11 @@ function Set-AzServiceBusQueue{ } if ($hasAsJob) { - $targetParameters.Add('AsJob', $true) + $PSBoundParameters.Add('AsJob', $true) } if ($PSCmdlet.ShouldProcess("ServiceBus Queue $($queue.Name)", "Create or update")) { - Az.ServiceBus.private\New-AzServiceBusQueue_CreateViaIdentity -InputObject $queue -Parameter $queue @targetParameters + Az.ServiceBus.private\New-AzServiceBusQueue_CreateViaIdentity -InputObject $queue -Parameter $queue @PSBoundParameters } } catch{ diff --git a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusRule.ps1 b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusRule.ps1 index d293c2132d22..7943256bff61 100644 --- a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusRule.ps1 +++ b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusRule.ps1 @@ -231,33 +231,32 @@ function Set-AzServiceBusRule{ } process{ try{ - $targetParameters = @{} + $PSBoundParameters - $hasSqlExpression = $targetParameters.Remove('SqlExpression') - $hasSqlFilterRequiresPreprocessing = $targetParameters.Remove('SqlFilterRequiresPreprocessing') - $hasContentType = $targetParameters.Remove('ContentType') - $hasCorrelationId = $targetParameters.Remove('CorrelationId') - $hasLabel = $targetParameters.Remove('Label') - $hasMessageId = $targetParameters.Remove('MessageId') - $hasCorrelationFilterProperty = $targetParameters.Remove('CorrelationFilterProperty') - $hasReplyTo = $targetParameters.Remove('ReplyTo') - $hasReplyToSessionId = $targetParameters.Remove('ReplyToSessionId') - $hasCorrelationFilterRequiresPreprocessing = $targetParameters.Remove('CorrelationFilterRequiresPreprocessing') - $hasSessionId = $targetParameters.Remove('SessionId') - $hasTo = $targetParameters.Remove('To') - $hasFilterType = $targetParameters.Remove('FilterType') - $hasActionSqlExpression = $targetParameters.Remove('ActionSqlExpression') - $hasActionRequiresPreprocessing = $targetParameters.Remove('ActionRequiresPreprocessing') - - $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusRule' -BoundParameters $targetParameters + $hasSqlExpression = $PSBoundParameters.Remove('SqlExpression') + $hasSqlFilterRequiresPreprocessing = $PSBoundParameters.Remove('SqlFilterRequiresPreprocessing') + $hasContentType = $PSBoundParameters.Remove('ContentType') + $hasCorrelationId = $PSBoundParameters.Remove('CorrelationId') + $hasLabel = $PSBoundParameters.Remove('Label') + $hasMessageId = $PSBoundParameters.Remove('MessageId') + $hasCorrelationFilterProperty = $PSBoundParameters.Remove('CorrelationFilterProperty') + $hasReplyTo = $PSBoundParameters.Remove('ReplyTo') + $hasReplyToSessionId = $PSBoundParameters.Remove('ReplyToSessionId') + $hasCorrelationFilterRequiresPreprocessing = $PSBoundParameters.Remove('CorrelationFilterRequiresPreprocessing') + $hasSessionId = $PSBoundParameters.Remove('SessionId') + $hasTo = $PSBoundParameters.Remove('To') + $hasFilterType = $PSBoundParameters.Remove('FilterType') + $hasActionSqlExpression = $PSBoundParameters.Remove('ActionSqlExpression') + $hasActionRequiresPreprocessing = $PSBoundParameters.Remove('ActionRequiresPreprocessing') + + $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusRule' -BoundParameters $PSBoundParameters $rule = Get-AzServiceBusRule @readParameters # 2. PUT - $null = $targetParameters.Remove('InputObject') - $null = $targetParameters.Remove('ResourceGroupName') - $null = $targetParameters.Remove('NamespaceName') - $null = $targetParameters.Remove('TopicName') - $null = $targetParameters.Remove('SubscriptionName') - $null = $targetParameters.Remove('Name') - $null = $targetParameters.Remove('SubscriptionId') + $null = $PSBoundParameters.Remove('InputObject') + $null = $PSBoundParameters.Remove('ResourceGroupName') + $null = $PSBoundParameters.Remove('NamespaceName') + $null = $PSBoundParameters.Remove('TopicName') + $null = $PSBoundParameters.Remove('SubscriptionName') + $null = $PSBoundParameters.Remove('Name') + $null = $PSBoundParameters.Remove('SubscriptionId') $hasProperty = $false @@ -327,11 +326,11 @@ function Set-AzServiceBusRule{ } if ($hasAsJob) { - $targetParameters.Add('AsJob', $true) + $PSBoundParameters.Add('AsJob', $true) } if ($PSCmdlet.ShouldProcess("ServiceBus Rule $($rule.Name)", "Create or update")) { - Az.ServiceBus.private\New-AzServiceBusRule_CreateViaIdentity -InputObject $rule -Parameter $rule @targetParameters + Az.ServiceBus.private\New-AzServiceBusRule_CreateViaIdentity -InputObject $rule -Parameter $rule @PSBoundParameters } } catch{ diff --git a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusSubscription.ps1 b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusSubscription.ps1 index 0aa840643600..8e8898e380c4 100644 --- a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusSubscription.ps1 +++ b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusSubscription.ps1 @@ -202,31 +202,30 @@ function Set-AzServiceBusSubscription{ } process{ try{ - $targetParameters = @{} + $PSBoundParameters - $hasAutoDeleteOnIdle = $targetParameters.Remove('AutoDeleteOnIdle') - $hasDefaultMessageTimeToLive = $targetParameters.Remove('DefaultMessageTimeToLive') - $hasLockDuration = $targetParameters.Remove('LockDuration') - $hasDuplicateDetectionHistoryTimeWindow = $targetParameters.Remove('DuplicateDetectionHistoryTimeWindow') - $hasEnableBatchedOperations = $targetParameters.Remove('EnableBatchedOperations') - $hasDeadLetteringOnFilterEvaluationException = $targetParameters.Remove('DeadLetteringOnFilterEvaluationException') - $hasMaxDeliveryCount = $targetParameters.Remove('MaxDeliveryCount') - $hasForwardTo = $targetParameters.Remove('ForwardTo') - $hasForwardDeadLetteredMessagesTo = $targetParameters.Remove('ForwardDeadLetteredMessagesTo') - $hasStatus = $targetParameters.Remove('Status') - $hasDeadLetteringOnMessageExpiration = $targetParameters.Remove('DeadLetteringOnMessageExpiration') - $hasAsJob = $targetParameters.Remove('AsJob') - $null = $targetParameters.Remove('WhatIf') - $null = $targetParameters.Remove('Confirm') - - $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusSubscription' -BoundParameters $targetParameters + $hasAutoDeleteOnIdle = $PSBoundParameters.Remove('AutoDeleteOnIdle') + $hasDefaultMessageTimeToLive = $PSBoundParameters.Remove('DefaultMessageTimeToLive') + $hasLockDuration = $PSBoundParameters.Remove('LockDuration') + $hasDuplicateDetectionHistoryTimeWindow = $PSBoundParameters.Remove('DuplicateDetectionHistoryTimeWindow') + $hasEnableBatchedOperations = $PSBoundParameters.Remove('EnableBatchedOperations') + $hasDeadLetteringOnFilterEvaluationException = $PSBoundParameters.Remove('DeadLetteringOnFilterEvaluationException') + $hasMaxDeliveryCount = $PSBoundParameters.Remove('MaxDeliveryCount') + $hasForwardTo = $PSBoundParameters.Remove('ForwardTo') + $hasForwardDeadLetteredMessagesTo = $PSBoundParameters.Remove('ForwardDeadLetteredMessagesTo') + $hasStatus = $PSBoundParameters.Remove('Status') + $hasDeadLetteringOnMessageExpiration = $PSBoundParameters.Remove('DeadLetteringOnMessageExpiration') + $hasAsJob = $PSBoundParameters.Remove('AsJob') + $null = $PSBoundParameters.Remove('WhatIf') + $null = $PSBoundParameters.Remove('Confirm') + + $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusSubscription' -BoundParameters $PSBoundParameters $subscription = Get-AzServiceBusSubscription @readParameters # 2. PUT - $null = $targetParameters.Remove('InputObject') - $null = $targetParameters.Remove('ResourceGroupName') - $null = $targetParameters.Remove('NamespaceName') - $null = $targetParameters.Remove('TopicName') - $null = $targetParameters.Remove('Name') - $null = $targetParameters.Remove('SubscriptionId') + $null = $PSBoundParameters.Remove('InputObject') + $null = $PSBoundParameters.Remove('ResourceGroupName') + $null = $PSBoundParameters.Remove('NamespaceName') + $null = $PSBoundParameters.Remove('TopicName') + $null = $PSBoundParameters.Remove('Name') + $null = $PSBoundParameters.Remove('SubscriptionId') $hasProperty = $false @@ -280,11 +279,11 @@ function Set-AzServiceBusSubscription{ } if ($hasAsJob) { - $targetParameters.Add('AsJob', $true) + $PSBoundParameters.Add('AsJob', $true) } if ($PSCmdlet.ShouldProcess("ServiceBus Subscription $($subscription.Name)", "Create or update")) { - Az.ServiceBus.private\New-AzServiceBusSubscription_CreateViaIdentity -InputObject $subscription -Parameter $subscription @targetParameters + Az.ServiceBus.private\New-AzServiceBusSubscription_CreateViaIdentity -InputObject $subscription -Parameter $subscription @PSBoundParameters } } catch{ diff --git a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusTopic.ps1 b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusTopic.ps1 index 69d96df36c4e..76a372437e03 100644 --- a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusTopic.ps1 +++ b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusTopic.ps1 @@ -188,29 +188,28 @@ function Set-AzServiceBusTopic{ process{ try{ - $targetParameters = @{} + $PSBoundParameters - $hasAutoDeleteOnIdle = $targetParameters.Remove('AutoDeleteOnIdle') - $hasDefaultMessageTimeToLive = $targetParameters.Remove('DefaultMessageTimeToLive') - $hasDuplicateDetectionHistoryTimeWindow = $targetParameters.Remove('DuplicateDetectionHistoryTimeWindow') - $hasEnableBatchedOperations = $targetParameters.Remove('EnableBatchedOperations') - $hasEnableExpress = $targetParameters.Remove('EnableExpress') - $hasMaxMessageSizeInKilobytes = $targetParameters.Remove('MaxMessageSizeInKilobytes') - $hasMaxSizeInMegabytes = $targetParameters.Remove('MaxSizeInMegabytes') - $hasRequiresDuplicateDetection = $targetParameters.Remove('RequiresDuplicateDetection') - $hasSupportOrdering = $targetParameters.Remove('SupportOrdering') - $hasStatus = $targetParameters.Remove('Status') - $hasAsJob = $targetParameters.Remove('AsJob') - $null = $targetParameters.Remove('WhatIf') - $null = $targetParameters.Remove('Confirm') - - $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusTopic' -BoundParameters $targetParameters + $hasAutoDeleteOnIdle = $PSBoundParameters.Remove('AutoDeleteOnIdle') + $hasDefaultMessageTimeToLive = $PSBoundParameters.Remove('DefaultMessageTimeToLive') + $hasDuplicateDetectionHistoryTimeWindow = $PSBoundParameters.Remove('DuplicateDetectionHistoryTimeWindow') + $hasEnableBatchedOperations = $PSBoundParameters.Remove('EnableBatchedOperations') + $hasEnableExpress = $PSBoundParameters.Remove('EnableExpress') + $hasMaxMessageSizeInKilobytes = $PSBoundParameters.Remove('MaxMessageSizeInKilobytes') + $hasMaxSizeInMegabytes = $PSBoundParameters.Remove('MaxSizeInMegabytes') + $hasRequiresDuplicateDetection = $PSBoundParameters.Remove('RequiresDuplicateDetection') + $hasSupportOrdering = $PSBoundParameters.Remove('SupportOrdering') + $hasStatus = $PSBoundParameters.Remove('Status') + $hasAsJob = $PSBoundParameters.Remove('AsJob') + $null = $PSBoundParameters.Remove('WhatIf') + $null = $PSBoundParameters.Remove('Confirm') + + $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusTopic' -BoundParameters $PSBoundParameters $topic = Get-AzServiceBusTopic @readParameters # 2. PUT - $null = $targetParameters.Remove('InputObject') - $null = $targetParameters.Remove('ResourceGroupName') - $null = $targetParameters.Remove('NamespaceName') - $null = $targetParameters.Remove('Name') - $null = $targetParameters.Remove('SubscriptionId') + $null = $PSBoundParameters.Remove('InputObject') + $null = $PSBoundParameters.Remove('ResourceGroupName') + $null = $PSBoundParameters.Remove('NamespaceName') + $null = $PSBoundParameters.Remove('Name') + $null = $PSBoundParameters.Remove('SubscriptionId') $hasProperty = $false @@ -260,11 +259,11 @@ function Set-AzServiceBusTopic{ } if ($hasAsJob) { - $targetParameters.Add('AsJob', $true) + $PSBoundParameters.Add('AsJob', $true) } if ($PSCmdlet.ShouldProcess("ServiceBus Topic $($topic.Name)", "Create or update")) { - Az.ServiceBus.private\New-AzServiceBusTopic_CreateViaIdentity -InputObject $topic -Parameter $topic @targetParameters + Az.ServiceBus.private\New-AzServiceBusTopic_CreateViaIdentity -InputObject $topic -Parameter $topic @PSBoundParameters } } catch{ diff --git a/src/ServiceBus/ServiceBus.Autorest/test/ReadParameterForwarding.Tests.ps1 b/src/ServiceBus/ServiceBus.Autorest/test/ReadParameterForwarding.Tests.ps1 index d86382d6c0e7..9a202fd7be2b 100644 --- a/src/ServiceBus/ServiceBus.Autorest/test/ReadParameterForwarding.Tests.ps1 +++ b/src/ServiceBus/ServiceBus.Autorest/test/ReadParameterForwarding.Tests.ps1 @@ -30,8 +30,8 @@ function Set-AzServiceBusReadTestResource { Set-Alias -Name Get-AzServiceBusReadTestAlias -Value Get-AzServiceBusReadTestResource Describe 'ServiceBus read parameter forwarding' { - It 'filters write-only parameters using read command metadata without changing target parameters' { - $targetParameters = @{ + It 'filters write-only parameters using read command metadata without changing write parameters' { + $writeParameters = @{ Name = 'queue' DefaultProfile = 'profile' ErrorAction = 'Stop' @@ -40,9 +40,9 @@ Describe 'ServiceBus read parameter forwarding' { SyntheticWriteOnly = 'future-value' } - $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusReadTestAlias' -BoundParameters $targetParameters + $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusReadTestAlias' -BoundParameters $writeParameters Get-AzServiceBusReadTestResource @readParameters - Set-AzServiceBusReadTestResource @targetParameters + Set-AzServiceBusReadTestResource @writeParameters $script:serviceBusReadParameters.Name | Should Be 'queue' $script:serviceBusReadParameters.DefaultProfile | Should Be 'profile' @@ -61,7 +61,7 @@ Describe 'ServiceBus read parameter forwarding' { $readParameters.ResourceName | Should Be 'queue' } - It 'uses separate read and target parameter groups in every affected wrapper' { + It 'uses read parameters without replacing the original bound parameters in every affected wrapper' { $wrappers = @( 'Approve-AzServiceBusPrivateEndpointConnection.ps1', 'Deny-AzServiceBusPrivateEndpointConnection.ps1', @@ -78,10 +78,10 @@ Describe 'ServiceBus read parameter forwarding' { foreach ($wrapper in $wrappers) { $source = Get-Content -Path (Join-Path $PSScriptRoot "..\custom\$wrapper") -Raw - $source | Should Match '\$targetParameters\s*=\s*@\{\}\s*\+\s*\$PSBoundParameters' - $source | Should Match 'Get-AzServiceBusReadParameters\s+-CommandName' + $source | Should Not Match '\$targetParameters' + $source | Should Match 'Get-AzServiceBusReadParameters\s+-CommandName\s+''[^'']+''\s+-BoundParameters\s+\$PSBoundParameters' $source | Should Match '@readParameters' - $source | Should Match '@targetParameters' + $source | Should Match '@PSBoundParameters' } } From e56c477e319e4944e7e7a8817c749fb2b69f2d47 Mon Sep 17 00:00:00 2001 From: Yang An Date: Mon, 28 Sep 2026 16:01:35 +1000 Subject: [PATCH 06/12] Forward Change Safety in GeoDR identity actions Copy all bound dynamic parameters supported by the generated Break and Fail actions into the existing via-identity environment splats without hard-coding Change Safety parameter names. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../Add-AzEventHubBoundDynamicParameter.ps1 | 36 ++++++++ ...-AzEventHubGeoDRConfigurationBreakPair.ps1 | 2 + ...t-AzEventHubGeoDRConfigurationFailOver.ps1 | 2 + .../GeoDRDynamicParameterForwarding.Tests.ps1 | 82 +++++++++++++++++++ .../Add-AzServiceBusBoundDynamicParameter.ps1 | 36 ++++++++ ...zServiceBusGeoDRConfigurationBreakPair.ps1 | 2 + ...AzServiceBusGeoDRConfigurationFailOver.ps1 | 2 + .../GeoDRDynamicParameterForwarding.Tests.ps1 | 82 +++++++++++++++++++ 8 files changed, 244 insertions(+) create mode 100644 src/EventHub/EventHub.Autorest/custom/Add-AzEventHubBoundDynamicParameter.ps1 create mode 100644 src/EventHub/EventHub.Autorest/test/GeoDRDynamicParameterForwarding.Tests.ps1 create mode 100644 src/ServiceBus/ServiceBus.Autorest/custom/Add-AzServiceBusBoundDynamicParameter.ps1 create mode 100644 src/ServiceBus/ServiceBus.Autorest/test/GeoDRDynamicParameterForwarding.Tests.ps1 diff --git a/src/EventHub/EventHub.Autorest/custom/Add-AzEventHubBoundDynamicParameter.ps1 b/src/EventHub/EventHub.Autorest/custom/Add-AzEventHubBoundDynamicParameter.ps1 new file mode 100644 index 000000000000..18741d00aca9 --- /dev/null +++ b/src/EventHub/EventHub.Autorest/custom/Add-AzEventHubBoundDynamicParameter.ps1 @@ -0,0 +1,36 @@ +function Add-AzEventHubBoundDynamicParameter { + [Microsoft.Azure.PowerShell.Cmdlets.EventHub.DoNotExportAttribute()] + [CmdletBinding()] + param( + [Parameter(Mandatory)] + [System.String] + ${CommandName}, + + [Parameter(Mandatory)] + [System.Collections.IDictionary] + ${BoundParameters}, + + [Parameter(Mandatory)] + [System.Collections.IDictionary] + ${TargetParameters}, + + [System.String[]] + ${ExcludedParameter} + ) + + $command = @(Get-Command -Name $CommandName -ErrorAction Stop)[0] + while ($command.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { + $command = Get-Command -Name $command.ResolvedCommandName -ErrorAction Stop + } + + if (-not [System.Management.Automation.IDynamicParameters].IsAssignableFrom($command.ImplementingType)) { + return + } + + $instance = [System.Activator]::CreateInstance($command.ImplementingType) + foreach ($parameterName in $instance.GetDynamicParameters().Keys) { + if (($parameterName -notin $ExcludedParameter) -and $BoundParameters.Contains($parameterName)) { + $TargetParameters[$parameterName] = $BoundParameters[$parameterName] + } + } +} diff --git a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubGeoDRConfigurationBreakPair.ps1 b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubGeoDRConfigurationBreakPair.ps1 index 0690e9f819ca..17d30080b5eb 100644 --- a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubGeoDRConfigurationBreakPair.ps1 +++ b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubGeoDRConfigurationBreakPair.ps1 @@ -167,6 +167,8 @@ function Set-AzEventHubGeoDRConfigurationBreakPair{ $EnvPSBoundParameters['ProxyUseDefaultCredentials'] = $ProxyUseDefaultCredentials } + Add-AzEventHubBoundDynamicParameter -CommandName 'Az.EventHub.private\Invoke-AzEventHubBreakDisasterRecoveryConfigPairing_Break' -BoundParameters $PSBoundParameters -TargetParameters $EnvPSBoundParameters -ExcludedParameter InputObject, Name, NamespaceName, ResourceGroupName, SubscriptionId + if($InputObject.Id -ne $null){ $ResourceHashTable = ParseResourceId -ResourceId $InputObject.Id } diff --git a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubGeoDRConfigurationFailOver.ps1 b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubGeoDRConfigurationFailOver.ps1 index fcc032fc5807..aeec7d03cd59 100644 --- a/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubGeoDRConfigurationFailOver.ps1 +++ b/src/EventHub/EventHub.Autorest/custom/Set-AzEventHubGeoDRConfigurationFailOver.ps1 @@ -167,6 +167,8 @@ function Set-AzEventHubGeoDRConfigurationFailOver{ $EnvPSBoundParameters['ProxyUseDefaultCredentials'] = $ProxyUseDefaultCredentials } + Add-AzEventHubBoundDynamicParameter -CommandName 'Az.EventHub.private\Invoke-AzEventHubFailDisasterRecoveryConfigOver_Fail' -BoundParameters $PSBoundParameters -TargetParameters $EnvPSBoundParameters -ExcludedParameter InputObject, Name, NamespaceName, ResourceGroupName, SubscriptionId + if($InputObject.Id -ne $null){ $ResourceHashTable = ParseResourceId -ResourceId $InputObject.Id } diff --git a/src/EventHub/EventHub.Autorest/test/GeoDRDynamicParameterForwarding.Tests.ps1 b/src/EventHub/EventHub.Autorest/test/GeoDRDynamicParameterForwarding.Tests.ps1 new file mode 100644 index 000000000000..ccc4ca33aaa9 --- /dev/null +++ b/src/EventHub/EventHub.Autorest/test/GeoDRDynamicParameterForwarding.Tests.ps1 @@ -0,0 +1,82 @@ +class EventHubTestDynamicParameters : System.Management.Automation.IDynamicParameters { + [object] GetDynamicParameters() { + $parameters = [System.Management.Automation.RuntimeDefinedParameterDictionary]::new() + foreach ($name in 'AcquirePolicyToken', 'ChangeReference', 'FutureDynamic', 'InputObject', 'Name', 'NamespaceName', 'ResourceGroupName', 'SubscriptionId') { + $attributes = [System.Collections.ObjectModel.Collection[System.Attribute]]::new() + $parameters.Add($name, [System.Management.Automation.RuntimeDefinedParameter]::new($name, [object], $attributes)) + } + return $parameters + } +} + +$helperPath = Join-Path $PSScriptRoot '..\custom\Add-AzEventHubBoundDynamicParameter.ps1' +$helperSource = Get-Content -Path $helperPath -Raw +$helperSource = $helperSource -replace '(?m)^\s*\[Microsoft\.Azure\.PowerShell\.Cmdlets\.EventHub\.DoNotExportAttribute\(\)\]\r?\n', '' +. ([scriptblock]::Create($helperSource)) + +Describe 'EventHub GeoDR via-identity dynamic parameter forwarding' { + Mock Get-Command { + [pscustomobject]@{ + CommandType = [System.Management.Automation.CommandTypes]::Cmdlet + ImplementingType = [EventHubTestDynamicParameters] + } + } + + It 'adds only bound, non-path dynamic parameters to the environment splat' { + $boundParameters = @{ + AcquirePolicyToken = $true + ChangeReference = 'change-123' + FutureDynamic = 'future-value' + InputObject = 'identity' + Name = 'alias' + NamespaceName = 'namespace' + ResourceGroupName = 'resource-group' + SubscriptionId = 'subscription' + } + $environmentParameters = @{ Debug = $true } + + Add-AzEventHubBoundDynamicParameter -CommandName 'Az.EventHub.private\Test-Target' -BoundParameters $boundParameters -TargetParameters $environmentParameters -ExcludedParameter InputObject, Name, NamespaceName, ResourceGroupName, SubscriptionId + + $environmentParameters.AcquirePolicyToken | Should Be $true + $environmentParameters.ChangeReference | Should Be 'change-123' + $environmentParameters.FutureDynamic | Should Be 'future-value' + $environmentParameters.Debug | Should Be $true + $environmentParameters.ContainsKey('InputObject') | Should Be $false + $environmentParameters.ContainsKey('Name') | Should Be $false + $environmentParameters.ContainsKey('NamespaceName') | Should Be $false + $environmentParameters.ContainsKey('ResourceGroupName') | Should Be $false + $environmentParameters.ContainsKey('SubscriptionId') | Should Be $false + $environmentParameters.Count | Should Be 4 + } + + It 'does not add supported dynamic parameters that were not bound' { + $environmentParameters = @{} + + Add-AzEventHubBoundDynamicParameter -CommandName 'Az.EventHub.private\Test-Target' -BoundParameters @{ FutureDynamic = 'future-value' } -TargetParameters $environmentParameters + + $environmentParameters.FutureDynamic | Should Be 'future-value' + $environmentParameters.ContainsKey('AcquirePolicyToken') | Should Be $false + $environmentParameters.ContainsKey('ChangeReference') | Should Be $false + } + + It 'uses exact target metadata and environment splats in both via-identity branches' { + $cases = @( + @{ + File = 'Set-AzEventHubGeoDRConfigurationBreakPair.ps1' + Command = 'Az.EventHub.private\Invoke-AzEventHubBreakDisasterRecoveryConfigPairing_Break' + }, + @{ + File = 'Set-AzEventHubGeoDRConfigurationFailOver.ps1' + Command = 'Az.EventHub.private\Invoke-AzEventHubFailDisasterRecoveryConfigOver_Fail' + } + ) + + foreach ($case in $cases) { + $source = Get-Content -Path (Join-Path $PSScriptRoot "..\custom\$($case.File)") -Raw + $escapedCommand = [regex]::Escape($case.Command) + + $source | Should Match "Add-AzEventHubBoundDynamicParameter -CommandName '$escapedCommand' -BoundParameters \`$PSBoundParameters -TargetParameters \`$EnvPSBoundParameters" + $source | Should Match "$escapedCommand .+@EnvPSBoundParameters" + } + } +} diff --git a/src/ServiceBus/ServiceBus.Autorest/custom/Add-AzServiceBusBoundDynamicParameter.ps1 b/src/ServiceBus/ServiceBus.Autorest/custom/Add-AzServiceBusBoundDynamicParameter.ps1 new file mode 100644 index 000000000000..3d7ab0267b70 --- /dev/null +++ b/src/ServiceBus/ServiceBus.Autorest/custom/Add-AzServiceBusBoundDynamicParameter.ps1 @@ -0,0 +1,36 @@ +function Add-AzServiceBusBoundDynamicParameter { + [Microsoft.Azure.PowerShell.Cmdlets.ServiceBus.DoNotExportAttribute()] + [CmdletBinding()] + param( + [Parameter(Mandatory)] + [System.String] + ${CommandName}, + + [Parameter(Mandatory)] + [System.Collections.IDictionary] + ${BoundParameters}, + + [Parameter(Mandatory)] + [System.Collections.IDictionary] + ${TargetParameters}, + + [System.String[]] + ${ExcludedParameter} + ) + + $command = @(Get-Command -Name $CommandName -ErrorAction Stop)[0] + while ($command.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { + $command = Get-Command -Name $command.ResolvedCommandName -ErrorAction Stop + } + + if (-not [System.Management.Automation.IDynamicParameters].IsAssignableFrom($command.ImplementingType)) { + return + } + + $instance = [System.Activator]::CreateInstance($command.ImplementingType) + foreach ($parameterName in $instance.GetDynamicParameters().Keys) { + if (($parameterName -notin $ExcludedParameter) -and $BoundParameters.Contains($parameterName)) { + $TargetParameters[$parameterName] = $BoundParameters[$parameterName] + } + } +} diff --git a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusGeoDRConfigurationBreakPair.ps1 b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusGeoDRConfigurationBreakPair.ps1 index 75115c8a0543..a2d52f8b516a 100644 --- a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusGeoDRConfigurationBreakPair.ps1 +++ b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusGeoDRConfigurationBreakPair.ps1 @@ -168,6 +168,8 @@ function Set-AzServiceBusGeoDRConfigurationBreakPair{ $EnvPSBoundParameters['ProxyUseDefaultCredentials'] = $ProxyUseDefaultCredentials } + Add-AzServiceBusBoundDynamicParameter -CommandName 'Az.ServiceBus.private\Invoke-AzServiceBusBreakDisasterRecoveryConfigPairing_Break' -BoundParameters $PSBoundParameters -TargetParameters $EnvPSBoundParameters -ExcludedParameter InputObject, Name, NamespaceName, ResourceGroupName, SubscriptionId + if($InputObject.Id -ne $null){ $ResourceHashTable = ParseResourceId -ResourceId $InputObject.Id } diff --git a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusGeoDRConfigurationFailOver.ps1 b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusGeoDRConfigurationFailOver.ps1 index 6254e296529f..9b9f2a51a521 100644 --- a/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusGeoDRConfigurationFailOver.ps1 +++ b/src/ServiceBus/ServiceBus.Autorest/custom/Set-AzServiceBusGeoDRConfigurationFailOver.ps1 @@ -168,6 +168,8 @@ function Set-AzServiceBusGeoDRConfigurationFailOver{ $EnvPSBoundParameters['ProxyUseDefaultCredentials'] = $ProxyUseDefaultCredentials } + Add-AzServiceBusBoundDynamicParameter -CommandName 'Az.ServiceBus.private\Invoke-AzServiceBusFailDisasterRecoveryConfigOver_FailExpanded' -BoundParameters $PSBoundParameters -TargetParameters $EnvPSBoundParameters -ExcludedParameter InputObject, Name, NamespaceName, ResourceGroupName, SubscriptionId + if ($InputObject.Id -ne $null){ $ResourceHashTable = ParseResourceId -ResourceId $InputObject.Id } diff --git a/src/ServiceBus/ServiceBus.Autorest/test/GeoDRDynamicParameterForwarding.Tests.ps1 b/src/ServiceBus/ServiceBus.Autorest/test/GeoDRDynamicParameterForwarding.Tests.ps1 new file mode 100644 index 000000000000..991627893bab --- /dev/null +++ b/src/ServiceBus/ServiceBus.Autorest/test/GeoDRDynamicParameterForwarding.Tests.ps1 @@ -0,0 +1,82 @@ +class ServiceBusTestDynamicParameters : System.Management.Automation.IDynamicParameters { + [object] GetDynamicParameters() { + $parameters = [System.Management.Automation.RuntimeDefinedParameterDictionary]::new() + foreach ($name in 'AcquirePolicyToken', 'ChangeReference', 'FutureDynamic', 'InputObject', 'Name', 'NamespaceName', 'ResourceGroupName', 'SubscriptionId') { + $attributes = [System.Collections.ObjectModel.Collection[System.Attribute]]::new() + $parameters.Add($name, [System.Management.Automation.RuntimeDefinedParameter]::new($name, [object], $attributes)) + } + return $parameters + } +} + +$helperPath = Join-Path $PSScriptRoot '..\custom\Add-AzServiceBusBoundDynamicParameter.ps1' +$helperSource = Get-Content -Path $helperPath -Raw +$helperSource = $helperSource -replace '(?m)^\s*\[Microsoft\.Azure\.PowerShell\.Cmdlets\.ServiceBus\.DoNotExportAttribute\(\)\]\r?\n', '' +. ([scriptblock]::Create($helperSource)) + +Describe 'ServiceBus GeoDR via-identity dynamic parameter forwarding' { + Mock Get-Command { + [pscustomobject]@{ + CommandType = [System.Management.Automation.CommandTypes]::Cmdlet + ImplementingType = [ServiceBusTestDynamicParameters] + } + } + + It 'adds only bound, non-path dynamic parameters to the environment splat' { + $boundParameters = @{ + AcquirePolicyToken = $true + ChangeReference = 'change-123' + FutureDynamic = 'future-value' + InputObject = 'identity' + Name = 'alias' + NamespaceName = 'namespace' + ResourceGroupName = 'resource-group' + SubscriptionId = 'subscription' + } + $environmentParameters = @{ Debug = $true } + + Add-AzServiceBusBoundDynamicParameter -CommandName 'Az.ServiceBus.private\Test-Target' -BoundParameters $boundParameters -TargetParameters $environmentParameters -ExcludedParameter InputObject, Name, NamespaceName, ResourceGroupName, SubscriptionId + + $environmentParameters.AcquirePolicyToken | Should Be $true + $environmentParameters.ChangeReference | Should Be 'change-123' + $environmentParameters.FutureDynamic | Should Be 'future-value' + $environmentParameters.Debug | Should Be $true + $environmentParameters.ContainsKey('InputObject') | Should Be $false + $environmentParameters.ContainsKey('Name') | Should Be $false + $environmentParameters.ContainsKey('NamespaceName') | Should Be $false + $environmentParameters.ContainsKey('ResourceGroupName') | Should Be $false + $environmentParameters.ContainsKey('SubscriptionId') | Should Be $false + $environmentParameters.Count | Should Be 4 + } + + It 'does not add supported dynamic parameters that were not bound' { + $environmentParameters = @{} + + Add-AzServiceBusBoundDynamicParameter -CommandName 'Az.ServiceBus.private\Test-Target' -BoundParameters @{ FutureDynamic = 'future-value' } -TargetParameters $environmentParameters + + $environmentParameters.FutureDynamic | Should Be 'future-value' + $environmentParameters.ContainsKey('AcquirePolicyToken') | Should Be $false + $environmentParameters.ContainsKey('ChangeReference') | Should Be $false + } + + It 'uses exact target metadata and environment splats in both via-identity branches' { + $cases = @( + @{ + File = 'Set-AzServiceBusGeoDRConfigurationBreakPair.ps1' + Command = 'Az.ServiceBus.private\Invoke-AzServiceBusBreakDisasterRecoveryConfigPairing_Break' + }, + @{ + File = 'Set-AzServiceBusGeoDRConfigurationFailOver.ps1' + Command = 'Az.ServiceBus.private\Invoke-AzServiceBusFailDisasterRecoveryConfigOver_FailExpanded' + } + ) + + foreach ($case in $cases) { + $source = Get-Content -Path (Join-Path $PSScriptRoot "..\custom\$($case.File)") -Raw + $escapedCommand = [regex]::Escape($case.Command) + + $source | Should Match "Add-AzServiceBusBoundDynamicParameter -CommandName '$escapedCommand' -BoundParameters \`$PSBoundParameters -TargetParameters \`$EnvPSBoundParameters" + $source | Should Match "$escapedCommand .+@EnvPSBoundParameters" + } + } +} From 31a4334f58d6f45179b50c8ae4a5b66ddced4b7a Mon Sep 17 00:00:00 2001 From: Yang An Date: Mon, 28 Sep 2026 16:12:13 +1000 Subject: [PATCH 07/12] Filter Change Safety parameters from CDN reads Use read-command metadata for preliminary CDN profile lookups while preserving the original bound parameters for remove and update writes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../custom/Get-AzCdnReadParameters.ps1 | 30 ++++++ .../custom/Remove-AzCdnProfile.ps1 | 6 +- .../custom/Remove-AzFrontDoorCdnProfile.ps1 | 6 +- .../custom/Update-AzCdnProfile.ps1 | 6 +- .../custom/Update-AzFrontDoorCdnProfile.ps1 | 6 +- src/Cdn/Cdn.Autorest/generate-info.json | 2 +- .../test/ReadParameterForwarding.Tests.ps1 | 102 ++++++++++++++++++ 7 files changed, 149 insertions(+), 9 deletions(-) create mode 100644 src/Cdn/Cdn.Autorest/custom/Get-AzCdnReadParameters.ps1 create mode 100644 src/Cdn/Cdn.Autorest/test/ReadParameterForwarding.Tests.ps1 diff --git a/src/Cdn/Cdn.Autorest/custom/Get-AzCdnReadParameters.ps1 b/src/Cdn/Cdn.Autorest/custom/Get-AzCdnReadParameters.ps1 new file mode 100644 index 000000000000..ecd27902361b --- /dev/null +++ b/src/Cdn/Cdn.Autorest/custom/Get-AzCdnReadParameters.ps1 @@ -0,0 +1,30 @@ +function Get-AzCdnReadParameters { + [Microsoft.Azure.PowerShell.Cmdlets.Cdn.DoNotExportAttribute()] + [CmdletBinding()] + param( + [Parameter(Mandatory)] + [System.String] + ${CommandName}, + + [Parameter(Mandatory)] + [System.Collections.IDictionary] + ${BoundParameters} + ) + + $command = @(Get-Command -Name $CommandName -ErrorAction Stop)[0] + while ($command.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { + $command = Get-Command -Name $command.ResolvedCommandName -ErrorAction Stop + } + + $parameterNames = @($command.Parameters.Keys) + $parameterNames += @($command.Parameters.Values | ForEach-Object { $_.Aliases }) + + $readParameters = @{} + foreach ($parameter in $BoundParameters.GetEnumerator()) { + if ($parameter.Key -in $parameterNames) { + $readParameters[$parameter.Key] = $parameter.Value + } + } + + return $readParameters +} diff --git a/src/Cdn/Cdn.Autorest/custom/Remove-AzCdnProfile.ps1 b/src/Cdn/Cdn.Autorest/custom/Remove-AzCdnProfile.ps1 index 4f212a065d7a..e4968ac43a78 100644 --- a/src/Cdn/Cdn.Autorest/custom/Remove-AzCdnProfile.ps1 +++ b/src/Cdn/Cdn.Autorest/custom/Remove-AzCdnProfile.ps1 @@ -175,9 +175,11 @@ function Remove-AzCdnProfile { $hasPassThru = $PSBoundParameters.Remove('PassThru') if ($PSCmdlet.ParameterSetName -eq 'Delete') { - $cdnProfile = Get-AzCdnProfile @PSBoundParameters + $readParameters = Get-AzCdnReadParameters -CommandName 'Get-AzCdnProfile' -BoundParameters $PSBoundParameters + $cdnProfile = Get-AzCdnProfile @readParameters } elseif ($PSCmdlet.ParameterSetName -eq 'DeleteViaIdentity') { - $cdnProfile = Get-AzCdnProfile @PSBoundParameters + $readParameters = Get-AzCdnReadParameters -CommandName 'Get-AzCdnProfile' -BoundParameters $PSBoundParameters + $cdnProfile = Get-AzCdnProfile @readParameters } else { throw "Not supported ParameterSetName." } diff --git a/src/Cdn/Cdn.Autorest/custom/Remove-AzFrontDoorCdnProfile.ps1 b/src/Cdn/Cdn.Autorest/custom/Remove-AzFrontDoorCdnProfile.ps1 index 077d11bb2c39..77297a985a73 100644 --- a/src/Cdn/Cdn.Autorest/custom/Remove-AzFrontDoorCdnProfile.ps1 +++ b/src/Cdn/Cdn.Autorest/custom/Remove-AzFrontDoorCdnProfile.ps1 @@ -176,9 +176,11 @@ function Remove-AzFrontDoorCdnProfile { $hasPassThru = $PSBoundParameters.Remove('PassThru') if ($PSCmdlet.ParameterSetName -eq 'Delete') { - $frontDoorCdnProfile = Get-AzFrontDoorCdnProfile @PSBoundParameters + $readParameters = Get-AzCdnReadParameters -CommandName 'Get-AzFrontDoorCdnProfile' -BoundParameters $PSBoundParameters + $frontDoorCdnProfile = Get-AzFrontDoorCdnProfile @readParameters } elseif ($PSCmdlet.ParameterSetName -eq 'DeleteViaIdentity') { - $frontDoorCdnProfile = Get-AzFrontDoorCdnProfile @PSBoundParameters + $readParameters = Get-AzCdnReadParameters -CommandName 'Get-AzFrontDoorCdnProfile' -BoundParameters $PSBoundParameters + $frontDoorCdnProfile = Get-AzFrontDoorCdnProfile @readParameters } else { throw "Not supported ParameterSetName." } diff --git a/src/Cdn/Cdn.Autorest/custom/Update-AzCdnProfile.ps1 b/src/Cdn/Cdn.Autorest/custom/Update-AzCdnProfile.ps1 index e5496b364f7d..5d1c470b5a12 100644 --- a/src/Cdn/Cdn.Autorest/custom/Update-AzCdnProfile.ps1 +++ b/src/Cdn/Cdn.Autorest/custom/Update-AzCdnProfile.ps1 @@ -182,9 +182,11 @@ function Update-AzCdnProfile { $hasNoWait = $PSBoundParameters.Remove('NoWait') if ($PSCmdlet.ParameterSetName -eq 'UpdateExpanded') { - $cdnProfile = Get-AzCdnProfile @PSBoundParameters + $readParameters = Get-AzCdnReadParameters -CommandName 'Get-AzCdnProfile' -BoundParameters $PSBoundParameters + $cdnProfile = Get-AzCdnProfile @readParameters } elseif ($PSCmdlet.ParameterSetName -eq 'UpdateViaIdentityExpanded') { - $cdnProfile = Get-AzCdnProfile @PSBoundParameters + $readParameters = Get-AzCdnReadParameters -CommandName 'Get-AzCdnProfile' -BoundParameters $PSBoundParameters + $cdnProfile = Get-AzCdnProfile @readParameters } else { throw "Not supported ParameterSetName." } diff --git a/src/Cdn/Cdn.Autorest/custom/Update-AzFrontDoorCdnProfile.ps1 b/src/Cdn/Cdn.Autorest/custom/Update-AzFrontDoorCdnProfile.ps1 index 4ccf861db0ce..7138e416a62f 100644 --- a/src/Cdn/Cdn.Autorest/custom/Update-AzFrontDoorCdnProfile.ps1 +++ b/src/Cdn/Cdn.Autorest/custom/Update-AzFrontDoorCdnProfile.ps1 @@ -242,9 +242,11 @@ function Update-AzFrontDoorCdnProfile { $hasLogScrubbingState = $PSBoundParameters.Remove('LogScrubbingState') if ($PSCmdlet.ParameterSetName -eq 'UpdateExpanded') { - $frontDoorCdnProfile = Get-AzFrontDoorCdnProfile @PSBoundParameters + $readParameters = Get-AzCdnReadParameters -CommandName 'Get-AzFrontDoorCdnProfile' -BoundParameters $PSBoundParameters + $frontDoorCdnProfile = Get-AzFrontDoorCdnProfile @readParameters } elseif ($PSCmdlet.ParameterSetName -eq 'UpdateViaIdentityExpanded') { - $frontDoorCdnProfile = Get-AzFrontDoorCdnProfile @PSBoundParameters + $readParameters = Get-AzCdnReadParameters -CommandName 'Get-AzFrontDoorCdnProfile' -BoundParameters $PSBoundParameters + $frontDoorCdnProfile = Get-AzFrontDoorCdnProfile @readParameters } else { throw "Not supported ParameterSetName." } diff --git a/src/Cdn/Cdn.Autorest/generate-info.json b/src/Cdn/Cdn.Autorest/generate-info.json index e8d11f117004..a693bf8a040d 100644 --- a/src/Cdn/Cdn.Autorest/generate-info.json +++ b/src/Cdn/Cdn.Autorest/generate-info.json @@ -1,3 +1,3 @@ { - "generate_Id": "39d7c1e4-7bfb-4e14-a49a-ba3e1c9354f5" + "generate_Id": "57914f66-0713-43e5-b23f-da61694bdbae" } diff --git a/src/Cdn/Cdn.Autorest/test/ReadParameterForwarding.Tests.ps1 b/src/Cdn/Cdn.Autorest/test/ReadParameterForwarding.Tests.ps1 new file mode 100644 index 000000000000..c0a0480e8a5a --- /dev/null +++ b/src/Cdn/Cdn.Autorest/test/ReadParameterForwarding.Tests.ps1 @@ -0,0 +1,102 @@ +$helperPath = Join-Path $PSScriptRoot '..\custom\Get-AzCdnReadParameters.ps1' +$helperSource = Get-Content -Path $helperPath -Raw +$helperSource = $helperSource -replace '(?m)^\s*\[Microsoft\.Azure\.PowerShell\.Cmdlets\.Cdn\.DoNotExportAttribute\(\)\]\r?\n', '' +. ([scriptblock]::Create($helperSource)) + +function Get-AzCdnReadTestResource { + [CmdletBinding()] + param( + [Alias('ResourceName')] + [string] $Name, + [object] $DefaultProfile + ) + + $script:cdnReadParameters = @{} + $PSBoundParameters +} + +function Set-AzCdnReadTestResource { + [CmdletBinding()] + param( + [string] $Name, + [object] $DefaultProfile, + [switch] $AcquirePolicyToken, + [string] $ChangeReference, + [string] $SyntheticWriteOnly + ) + + $script:cdnWriteParameters = @{} + $PSBoundParameters +} + +Set-Alias -Name Get-AzCdnReadTestAlias -Value Get-AzCdnReadTestResource + +Describe 'CDN read parameter forwarding' { + It 'filters write-only parameters without changing the write dictionary' { + $writeParameters = @{ + Name = 'profile' + DefaultProfile = 'profile-context' + ErrorAction = 'Stop' + AcquirePolicyToken = $true + ChangeReference = 'change-123' + SyntheticWriteOnly = 'future-value' + } + + $readParameters = Get-AzCdnReadParameters -CommandName 'Get-AzCdnReadTestAlias' -BoundParameters $writeParameters + Get-AzCdnReadTestResource @readParameters + Set-AzCdnReadTestResource @writeParameters + + $script:cdnReadParameters.Name | Should Be 'profile' + $script:cdnReadParameters.DefaultProfile | Should Be 'profile-context' + $script:cdnReadParameters.ErrorAction | Should Be 'Stop' + $script:cdnReadParameters.ContainsKey('AcquirePolicyToken') | Should Be $false + $script:cdnReadParameters.ContainsKey('ChangeReference') | Should Be $false + $script:cdnReadParameters.ContainsKey('SyntheticWriteOnly') | Should Be $false + $script:cdnWriteParameters.AcquirePolicyToken | Should Be $true + $script:cdnWriteParameters.ChangeReference | Should Be 'change-123' + $script:cdnWriteParameters.SyntheticWriteOnly | Should Be 'future-value' + } + + It 'includes aliases from the resolved read command metadata' { + $command = Get-Command -Name 'Get-AzCdnReadTestAlias' + while ($command.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { + $command = Get-Command -Name $command.ResolvedCommandName + } + $parameterNames = @($command.Parameters.Keys) + $parameterNames += @($command.Parameters.Values | ForEach-Object { $_.Aliases }) + + ($parameterNames -contains 'ResourceName') | Should Be $true + } + + It 'uses an exact helper and GET pair in every affected parameter-set branch' { + $cases = @( + @{ File = 'Remove-AzCdnProfile.ps1'; ReadCommand = 'Get-AzCdnProfile'; WriteCommand = 'Remove-AzCdnProfile' }, + @{ File = 'Remove-AzFrontDoorCdnProfile.ps1'; ReadCommand = 'Get-AzFrontDoorCdnProfile'; WriteCommand = 'Remove-AzCdnProfile' }, + @{ File = 'Update-AzCdnProfile.ps1'; ReadCommand = 'Get-AzCdnProfile'; WriteCommand = 'Update-AzCdnProfile' }, + @{ File = 'Update-AzFrontDoorCdnProfile.ps1'; ReadCommand = 'Get-AzFrontDoorCdnProfile'; WriteCommand = 'Update-AzCdnProfile' } + ) + $pairPattern = "(?m)^[ \t]*\`$readParameters = Get-AzCdnReadParameters -CommandName '([^']+)' -BoundParameters \`$PSBoundParameters\r?\n[ \t]*\`$\w+ = \1 @readParameters[ \t]*\r?$" + + foreach ($case in $cases) { + $source = Get-Content -Path (Join-Path $PSScriptRoot "..\custom\$($case.File)") -Raw + $pairs = [regex]::Matches($source, $pairPattern) + + $pairs.Count | Should Be 2 + foreach ($pair in $pairs) { + $pair.Groups[1].Value | Should Be $case.ReadCommand + } + $source | Should Not Match '\$targetParameters' + $source | Should Match ([regex]::Escape("Az.Cdn.internal\$($case.WriteCommand) @PSBoundParameters")) + } + } + + It 'packages the internal helper and triggers regeneration' { + $customPath = Join-Path $PSScriptRoot '..\custom' + $moduleSource = Get-Content -Path (Join-Path $customPath 'Az.Cdn.custom.psm1') -Raw + $helperSource = Get-Content -Path (Join-Path $customPath 'Get-AzCdnReadParameters.ps1') -Raw + $generation = Get-Content -Path (Join-Path $PSScriptRoot '..\generate-info.json') -Raw | ConvertFrom-Json + + $helperSource | Should Match '\[Microsoft\.Azure\.PowerShell\.Cmdlets\.Cdn\.DoNotExportAttribute\(\)\]' + $moduleSource | Should Match "Get-ChildItem\s+-Path\s+\`$PSScriptRoot\s+-Recurse\s+-Include\s+'\*\.ps1'" + { [guid]::Parse($generation.generate_Id) } | Should Not Throw + $generation.generate_Id | Should Not Be '39d7c1e4-7bfb-4e14-a49a-ba3e1c9354f5' + } +} From 09e770883916d2ce21de442e8dee038325e99194 Mon Sep 17 00:00:00 2001 From: Yang An Date: Mon, 28 Sep 2026 19:36:49 +1000 Subject: [PATCH 08/12] Fix GeoDR dynamic parameter dictionary lookup Use ContainsKey for real PSBoundParameters dictionaries and cover the live cmdlet invocation shape in regression tests. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../Add-AzEventHubBoundDynamicParameter.ps1 | 2 +- .../EventHub.Autorest/generate-info.json | 2 +- .../GeoDRDynamicParameterForwarding.Tests.ps1 | 16 ++++++++++++++++ .../Add-AzServiceBusBoundDynamicParameter.ps1 | 2 +- .../ServiceBus.Autorest/generate-info.json | 2 +- .../GeoDRDynamicParameterForwarding.Tests.ps1 | 16 ++++++++++++++++ 6 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/EventHub/EventHub.Autorest/custom/Add-AzEventHubBoundDynamicParameter.ps1 b/src/EventHub/EventHub.Autorest/custom/Add-AzEventHubBoundDynamicParameter.ps1 index 18741d00aca9..8904f31c61ef 100644 --- a/src/EventHub/EventHub.Autorest/custom/Add-AzEventHubBoundDynamicParameter.ps1 +++ b/src/EventHub/EventHub.Autorest/custom/Add-AzEventHubBoundDynamicParameter.ps1 @@ -29,7 +29,7 @@ function Add-AzEventHubBoundDynamicParameter { $instance = [System.Activator]::CreateInstance($command.ImplementingType) foreach ($parameterName in $instance.GetDynamicParameters().Keys) { - if (($parameterName -notin $ExcludedParameter) -and $BoundParameters.Contains($parameterName)) { + if (($parameterName -notin $ExcludedParameter) -and $BoundParameters.ContainsKey($parameterName)) { $TargetParameters[$parameterName] = $BoundParameters[$parameterName] } } diff --git a/src/EventHub/EventHub.Autorest/generate-info.json b/src/EventHub/EventHub.Autorest/generate-info.json index 5e91eccfaab6..26bbe5a4e62b 100644 --- a/src/EventHub/EventHub.Autorest/generate-info.json +++ b/src/EventHub/EventHub.Autorest/generate-info.json @@ -1,3 +1,3 @@ { - "generate_Id": "7433a5f8-b6ec-4ce4-a9b6-8b320d711a49" + "generate_Id": "9240a33b-cdb2-4523-a6cc-096a195383eb" } diff --git a/src/EventHub/EventHub.Autorest/test/GeoDRDynamicParameterForwarding.Tests.ps1 b/src/EventHub/EventHub.Autorest/test/GeoDRDynamicParameterForwarding.Tests.ps1 index ccc4ca33aaa9..7b750d507d9a 100644 --- a/src/EventHub/EventHub.Autorest/test/GeoDRDynamicParameterForwarding.Tests.ps1 +++ b/src/EventHub/EventHub.Autorest/test/GeoDRDynamicParameterForwarding.Tests.ps1 @@ -59,6 +59,22 @@ Describe 'EventHub GeoDR via-identity dynamic parameter forwarding' { $environmentParameters.ContainsKey('ChangeReference') | Should Be $false } + It 'accepts the PSBoundParameters dictionary used by custom cmdlets' { + function Invoke-EventHubTestForwarding { + param( + [string] $ChangeReference + ) + + $environmentParameters = @{} + Add-AzEventHubBoundDynamicParameter -CommandName 'Az.EventHub.private\Test-Target' -BoundParameters $PSBoundParameters -TargetParameters $environmentParameters + return $environmentParameters + } + + $environmentParameters = Invoke-EventHubTestForwarding -ChangeReference 'change-123' + + $environmentParameters.ChangeReference | Should Be 'change-123' + } + It 'uses exact target metadata and environment splats in both via-identity branches' { $cases = @( @{ diff --git a/src/ServiceBus/ServiceBus.Autorest/custom/Add-AzServiceBusBoundDynamicParameter.ps1 b/src/ServiceBus/ServiceBus.Autorest/custom/Add-AzServiceBusBoundDynamicParameter.ps1 index 3d7ab0267b70..f0c6061c286f 100644 --- a/src/ServiceBus/ServiceBus.Autorest/custom/Add-AzServiceBusBoundDynamicParameter.ps1 +++ b/src/ServiceBus/ServiceBus.Autorest/custom/Add-AzServiceBusBoundDynamicParameter.ps1 @@ -29,7 +29,7 @@ function Add-AzServiceBusBoundDynamicParameter { $instance = [System.Activator]::CreateInstance($command.ImplementingType) foreach ($parameterName in $instance.GetDynamicParameters().Keys) { - if (($parameterName -notin $ExcludedParameter) -and $BoundParameters.Contains($parameterName)) { + if (($parameterName -notin $ExcludedParameter) -and $BoundParameters.ContainsKey($parameterName)) { $TargetParameters[$parameterName] = $BoundParameters[$parameterName] } } diff --git a/src/ServiceBus/ServiceBus.Autorest/generate-info.json b/src/ServiceBus/ServiceBus.Autorest/generate-info.json index 73e72c635e25..51d5d25d45e9 100644 --- a/src/ServiceBus/ServiceBus.Autorest/generate-info.json +++ b/src/ServiceBus/ServiceBus.Autorest/generate-info.json @@ -1,3 +1,3 @@ { - "generate_Id": "6f3a9805-5577-4f34-a04b-9650247850a6" + "generate_Id": "522c1679-6822-4201-80a6-7fa4965c2384" } diff --git a/src/ServiceBus/ServiceBus.Autorest/test/GeoDRDynamicParameterForwarding.Tests.ps1 b/src/ServiceBus/ServiceBus.Autorest/test/GeoDRDynamicParameterForwarding.Tests.ps1 index 991627893bab..43c516d26d4a 100644 --- a/src/ServiceBus/ServiceBus.Autorest/test/GeoDRDynamicParameterForwarding.Tests.ps1 +++ b/src/ServiceBus/ServiceBus.Autorest/test/GeoDRDynamicParameterForwarding.Tests.ps1 @@ -59,6 +59,22 @@ Describe 'ServiceBus GeoDR via-identity dynamic parameter forwarding' { $environmentParameters.ContainsKey('ChangeReference') | Should Be $false } + It 'accepts the PSBoundParameters dictionary used by custom cmdlets' { + function Invoke-ServiceBusTestForwarding { + param( + [string] $ChangeReference + ) + + $environmentParameters = @{} + Add-AzServiceBusBoundDynamicParameter -CommandName 'Az.ServiceBus.private\Test-Target' -BoundParameters $PSBoundParameters -TargetParameters $environmentParameters + return $environmentParameters + } + + $environmentParameters = Invoke-ServiceBusTestForwarding -ChangeReference 'change-123' + + $environmentParameters.ChangeReference | Should Be 'change-123' + } + It 'uses exact target metadata and environment splats in both via-identity branches' { $cases = @( @{ From f9356b8bf92af51cf1148501b451f2172a327858 Mon Sep 17 00:00:00 2001 From: Yang An Date: Mon, 28 Sep 2026 21:06:35 +1000 Subject: [PATCH 09/12] Strengthen CDN read alias regression test Exercise the metadata-filtering helper directly with an aliased parameter instead of independently reconstructing command metadata. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../test/ReadParameterForwarding.Tests.ps1 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Cdn/Cdn.Autorest/test/ReadParameterForwarding.Tests.ps1 b/src/Cdn/Cdn.Autorest/test/ReadParameterForwarding.Tests.ps1 index c0a0480e8a5a..fc98a4ceff66 100644 --- a/src/Cdn/Cdn.Autorest/test/ReadParameterForwarding.Tests.ps1 +++ b/src/Cdn/Cdn.Autorest/test/ReadParameterForwarding.Tests.ps1 @@ -56,14 +56,14 @@ Describe 'CDN read parameter forwarding' { } It 'includes aliases from the resolved read command metadata' { - $command = Get-Command -Name 'Get-AzCdnReadTestAlias' - while ($command.CommandType -eq [System.Management.Automation.CommandTypes]::Alias) { - $command = Get-Command -Name $command.ResolvedCommandName + $writeParameters = @{ + ResourceName = 'profile' } - $parameterNames = @($command.Parameters.Keys) - $parameterNames += @($command.Parameters.Values | ForEach-Object { $_.Aliases }) - ($parameterNames -contains 'ResourceName') | Should Be $true + $readParameters = Get-AzCdnReadParameters -CommandName 'Get-AzCdnReadTestAlias' -BoundParameters $writeParameters + + $readParameters.ContainsKey('ResourceName') | Should Be $true + $readParameters.ResourceName | Should Be 'profile' } It 'uses an exact helper and GET pair in every affected parameter-set branch' { From 93a564ee027f38f039baf95ae3fc13739a1cabf4 Mon Sep 17 00:00:00 2001 From: Yang An Date: Mon, 28 Sep 2026 22:43:19 +1000 Subject: [PATCH 10/12] Fix forwarding tests in packaged modules Keep artifact-level helper packaging assertions, but remove source-only generate-info checks because generation metadata is not included in built module artifacts. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/Cdn/Cdn.Autorest/test/ReadParameterForwarding.Tests.ps1 | 5 +---- .../EventHub.Autorest/test/ReadParameterForwarding.Tests.ps1 | 5 +---- .../test/ReadParameterForwarding.Tests.ps1 | 5 +---- .../test/ReadParameterForwarding.Tests.ps1 | 5 +---- 4 files changed, 4 insertions(+), 16 deletions(-) diff --git a/src/Cdn/Cdn.Autorest/test/ReadParameterForwarding.Tests.ps1 b/src/Cdn/Cdn.Autorest/test/ReadParameterForwarding.Tests.ps1 index fc98a4ceff66..d50a9c5afa7a 100644 --- a/src/Cdn/Cdn.Autorest/test/ReadParameterForwarding.Tests.ps1 +++ b/src/Cdn/Cdn.Autorest/test/ReadParameterForwarding.Tests.ps1 @@ -88,15 +88,12 @@ Describe 'CDN read parameter forwarding' { } } - It 'packages the internal helper and triggers regeneration' { + It 'packages the internal helper' { $customPath = Join-Path $PSScriptRoot '..\custom' $moduleSource = Get-Content -Path (Join-Path $customPath 'Az.Cdn.custom.psm1') -Raw $helperSource = Get-Content -Path (Join-Path $customPath 'Get-AzCdnReadParameters.ps1') -Raw - $generation = Get-Content -Path (Join-Path $PSScriptRoot '..\generate-info.json') -Raw | ConvertFrom-Json $helperSource | Should Match '\[Microsoft\.Azure\.PowerShell\.Cmdlets\.Cdn\.DoNotExportAttribute\(\)\]' $moduleSource | Should Match "Get-ChildItem\s+-Path\s+\`$PSScriptRoot\s+-Recurse\s+-Include\s+'\*\.ps1'" - { [guid]::Parse($generation.generate_Id) } | Should Not Throw - $generation.generate_Id | Should Not Be '39d7c1e4-7bfb-4e14-a49a-ba3e1c9354f5' } } diff --git a/src/EventHub/EventHub.Autorest/test/ReadParameterForwarding.Tests.ps1 b/src/EventHub/EventHub.Autorest/test/ReadParameterForwarding.Tests.ps1 index 932345a56e85..2ce31073b72b 100644 --- a/src/EventHub/EventHub.Autorest/test/ReadParameterForwarding.Tests.ps1 +++ b/src/EventHub/EventHub.Autorest/test/ReadParameterForwarding.Tests.ps1 @@ -93,17 +93,14 @@ Describe 'EventHub read parameter forwarding' { $source | Should Match "CommandName 'Az\.EventHub\.private\\Get-AzEventHubNamespaceAuthorizationRule_GetViaIdentity'" } - It 'packages the internal helper and triggers regeneration' { + It 'packages the internal helper' { $customPath = Join-Path $PSScriptRoot '..\custom' $helperPath = Join-Path $customPath 'Get-AzEventHubReadParameters.ps1' $moduleSource = Get-Content -Path (Join-Path $customPath 'Az.EventHub.custom.psm1') -Raw $helperSource = Get-Content -Path $helperPath -Raw - $generation = Get-Content -Path (Join-Path $PSScriptRoot '..\generate-info.json') -Raw | ConvertFrom-Json Test-Path -Path $helperPath | Should Be $true $helperSource | Should Match '\[Microsoft\.Azure\.PowerShell\.Cmdlets\.EventHub\.DoNotExportAttribute\(\)\]' $moduleSource | Should Match "Get-ChildItem\s+-Path\s+\`$PSScriptRoot\s+-Recurse\s+-Include\s+'\*\.ps1'" - { [guid]::Parse($generation.generate_Id) } | Should Not Throw - $generation.generate_Id | Should Not Be '37e57dcc-9680-41ff-a019-ec549669f7b0' } } diff --git a/src/Network/NetworkSecurityPerimeter.Autorest/test/ReadParameterForwarding.Tests.ps1 b/src/Network/NetworkSecurityPerimeter.Autorest/test/ReadParameterForwarding.Tests.ps1 index 729f972d722d..ff173e8e0ae2 100644 --- a/src/Network/NetworkSecurityPerimeter.Autorest/test/ReadParameterForwarding.Tests.ps1 +++ b/src/Network/NetworkSecurityPerimeter.Autorest/test/ReadParameterForwarding.Tests.ps1 @@ -78,17 +78,14 @@ Describe 'NetworkSecurityPerimeter read parameter forwarding' { } } - It 'packages the internal helper and triggers regeneration' { + It 'packages the internal helper' { $customPath = Join-Path $PSScriptRoot '..\custom' $helperPath = Join-Path $customPath 'Get-AzNetworkSecurityPerimeterReadParameters.ps1' $moduleSource = Get-Content -Path (Join-Path $customPath 'Az.NetworkSecurityPerimeter.custom.psm1') -Raw $helperSource = Get-Content -Path $helperPath -Raw - $generation = Get-Content -Path (Join-Path $PSScriptRoot '..\generate-info.json') -Raw | ConvertFrom-Json Test-Path -Path $helperPath | Should Be $true $helperSource | Should Match '\[Microsoft\.Azure\.PowerShell\.Cmdlets\.NetworkSecurityPerimeter\.DoNotExportAttribute\(\)\]' $moduleSource | Should Match "Get-ChildItem\s+-Path\s+\`$PSScriptRoot\s+-Recurse\s+-Include\s+'\*\.ps1'" - { [guid]::Parse($generation.generate_Id) } | Should Not Throw - $generation.generate_Id | Should Not Be '22876a3f-6f36-449b-a291-2b1c423db247' } } diff --git a/src/ServiceBus/ServiceBus.Autorest/test/ReadParameterForwarding.Tests.ps1 b/src/ServiceBus/ServiceBus.Autorest/test/ReadParameterForwarding.Tests.ps1 index 9a202fd7be2b..c684bcd421bc 100644 --- a/src/ServiceBus/ServiceBus.Autorest/test/ReadParameterForwarding.Tests.ps1 +++ b/src/ServiceBus/ServiceBus.Autorest/test/ReadParameterForwarding.Tests.ps1 @@ -93,17 +93,14 @@ Describe 'ServiceBus read parameter forwarding' { $source | Should Match "CommandName 'Az\.ServiceBus\.private\\Get-AzServiceBusNamespaceAuthorizationRule_GetViaIdentity'" } - It 'packages the internal helper and triggers regeneration' { + It 'packages the internal helper' { $customPath = Join-Path $PSScriptRoot '..\custom' $helperPath = Join-Path $customPath 'Get-AzServiceBusReadParameters.ps1' $moduleSource = Get-Content -Path (Join-Path $customPath 'Az.ServiceBus.custom.psm1') -Raw $helperSource = Get-Content -Path $helperPath -Raw - $generation = Get-Content -Path (Join-Path $PSScriptRoot '..\generate-info.json') -Raw | ConvertFrom-Json Test-Path -Path $helperPath | Should Be $true $helperSource | Should Match '\[Microsoft\.Azure\.PowerShell\.Cmdlets\.ServiceBus\.DoNotExportAttribute\(\)\]' $moduleSource | Should Match "Get-ChildItem\s+-Path\s+\`$PSScriptRoot\s+-Recurse\s+-Include\s+'\*\.ps1'" - { [guid]::Parse($generation.generate_Id) } | Should Not Throw - $generation.generate_Id | Should Not Be 'd42664e3-3ae4-4daf-a410-fba6f9958c4e' } } From 55cdb03ffc62a42c15c26f5f0e28ff6f2f544975 Mon Sep 17 00:00:00 2001 From: Yang An Date: Mon, 28 Sep 2026 22:54:51 +1000 Subject: [PATCH 11/12] Restore Network changelog spacing Remove an unrelated blank-line deletion from the Change Safety PR. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/Network/Network/ChangeLog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Network/Network/ChangeLog.md b/src/Network/Network/ChangeLog.md index 361b04eb638d..d76afbf444de 100644 --- a/src/Network/Network/ChangeLog.md +++ b/src/Network/Network/ChangeLog.md @@ -128,6 +128,7 @@ ## Version 8.0.1 * Onboarded `Microsoft.HorizonDB/clusters` to Private Link Common Cmdlets + ## Version 8.0.0 * Added ChangeSafety Support * Changed `UserAssignedIdentityId` type to string[] From ab9c4268531caa872d1e9c140cad41ba867ac34e Mon Sep 17 00:00:00 2001 From: Yang An Date: Tue, 29 Sep 2026 12:10:03 +1000 Subject: [PATCH 12/12] Add forwarding fix changelogs Document the Change Safety forwarding fixes in all affected modules and remove the PR-specific test files. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../test/ReadParameterForwarding.Tests.ps1 | 99 ---------------- src/Cdn/Cdn/ChangeLog.md | 2 +- .../GeoDRDynamicParameterForwarding.Tests.ps1 | 98 ---------------- .../test/ReadParameterForwarding.Tests.ps1 | 106 ------------------ src/EventHub/EventHub/ChangeLog.md | 1 + src/Network/Network/ChangeLog.md | 1 + .../test/ReadParameterForwarding.Tests.ps1 | 91 --------------- .../GeoDRDynamicParameterForwarding.Tests.ps1 | 98 ---------------- .../test/ReadParameterForwarding.Tests.ps1 | 106 ------------------ src/ServiceBus/ServiceBus/ChangeLog.md | 1 + 10 files changed, 4 insertions(+), 599 deletions(-) delete mode 100644 src/Cdn/Cdn.Autorest/test/ReadParameterForwarding.Tests.ps1 delete mode 100644 src/EventHub/EventHub.Autorest/test/GeoDRDynamicParameterForwarding.Tests.ps1 delete mode 100644 src/EventHub/EventHub.Autorest/test/ReadParameterForwarding.Tests.ps1 delete mode 100644 src/Network/NetworkSecurityPerimeter.Autorest/test/ReadParameterForwarding.Tests.ps1 delete mode 100644 src/ServiceBus/ServiceBus.Autorest/test/GeoDRDynamicParameterForwarding.Tests.ps1 delete mode 100644 src/ServiceBus/ServiceBus.Autorest/test/ReadParameterForwarding.Tests.ps1 diff --git a/src/Cdn/Cdn.Autorest/test/ReadParameterForwarding.Tests.ps1 b/src/Cdn/Cdn.Autorest/test/ReadParameterForwarding.Tests.ps1 deleted file mode 100644 index d50a9c5afa7a..000000000000 --- a/src/Cdn/Cdn.Autorest/test/ReadParameterForwarding.Tests.ps1 +++ /dev/null @@ -1,99 +0,0 @@ -$helperPath = Join-Path $PSScriptRoot '..\custom\Get-AzCdnReadParameters.ps1' -$helperSource = Get-Content -Path $helperPath -Raw -$helperSource = $helperSource -replace '(?m)^\s*\[Microsoft\.Azure\.PowerShell\.Cmdlets\.Cdn\.DoNotExportAttribute\(\)\]\r?\n', '' -. ([scriptblock]::Create($helperSource)) - -function Get-AzCdnReadTestResource { - [CmdletBinding()] - param( - [Alias('ResourceName')] - [string] $Name, - [object] $DefaultProfile - ) - - $script:cdnReadParameters = @{} + $PSBoundParameters -} - -function Set-AzCdnReadTestResource { - [CmdletBinding()] - param( - [string] $Name, - [object] $DefaultProfile, - [switch] $AcquirePolicyToken, - [string] $ChangeReference, - [string] $SyntheticWriteOnly - ) - - $script:cdnWriteParameters = @{} + $PSBoundParameters -} - -Set-Alias -Name Get-AzCdnReadTestAlias -Value Get-AzCdnReadTestResource - -Describe 'CDN read parameter forwarding' { - It 'filters write-only parameters without changing the write dictionary' { - $writeParameters = @{ - Name = 'profile' - DefaultProfile = 'profile-context' - ErrorAction = 'Stop' - AcquirePolicyToken = $true - ChangeReference = 'change-123' - SyntheticWriteOnly = 'future-value' - } - - $readParameters = Get-AzCdnReadParameters -CommandName 'Get-AzCdnReadTestAlias' -BoundParameters $writeParameters - Get-AzCdnReadTestResource @readParameters - Set-AzCdnReadTestResource @writeParameters - - $script:cdnReadParameters.Name | Should Be 'profile' - $script:cdnReadParameters.DefaultProfile | Should Be 'profile-context' - $script:cdnReadParameters.ErrorAction | Should Be 'Stop' - $script:cdnReadParameters.ContainsKey('AcquirePolicyToken') | Should Be $false - $script:cdnReadParameters.ContainsKey('ChangeReference') | Should Be $false - $script:cdnReadParameters.ContainsKey('SyntheticWriteOnly') | Should Be $false - $script:cdnWriteParameters.AcquirePolicyToken | Should Be $true - $script:cdnWriteParameters.ChangeReference | Should Be 'change-123' - $script:cdnWriteParameters.SyntheticWriteOnly | Should Be 'future-value' - } - - It 'includes aliases from the resolved read command metadata' { - $writeParameters = @{ - ResourceName = 'profile' - } - - $readParameters = Get-AzCdnReadParameters -CommandName 'Get-AzCdnReadTestAlias' -BoundParameters $writeParameters - - $readParameters.ContainsKey('ResourceName') | Should Be $true - $readParameters.ResourceName | Should Be 'profile' - } - - It 'uses an exact helper and GET pair in every affected parameter-set branch' { - $cases = @( - @{ File = 'Remove-AzCdnProfile.ps1'; ReadCommand = 'Get-AzCdnProfile'; WriteCommand = 'Remove-AzCdnProfile' }, - @{ File = 'Remove-AzFrontDoorCdnProfile.ps1'; ReadCommand = 'Get-AzFrontDoorCdnProfile'; WriteCommand = 'Remove-AzCdnProfile' }, - @{ File = 'Update-AzCdnProfile.ps1'; ReadCommand = 'Get-AzCdnProfile'; WriteCommand = 'Update-AzCdnProfile' }, - @{ File = 'Update-AzFrontDoorCdnProfile.ps1'; ReadCommand = 'Get-AzFrontDoorCdnProfile'; WriteCommand = 'Update-AzCdnProfile' } - ) - $pairPattern = "(?m)^[ \t]*\`$readParameters = Get-AzCdnReadParameters -CommandName '([^']+)' -BoundParameters \`$PSBoundParameters\r?\n[ \t]*\`$\w+ = \1 @readParameters[ \t]*\r?$" - - foreach ($case in $cases) { - $source = Get-Content -Path (Join-Path $PSScriptRoot "..\custom\$($case.File)") -Raw - $pairs = [regex]::Matches($source, $pairPattern) - - $pairs.Count | Should Be 2 - foreach ($pair in $pairs) { - $pair.Groups[1].Value | Should Be $case.ReadCommand - } - $source | Should Not Match '\$targetParameters' - $source | Should Match ([regex]::Escape("Az.Cdn.internal\$($case.WriteCommand) @PSBoundParameters")) - } - } - - It 'packages the internal helper' { - $customPath = Join-Path $PSScriptRoot '..\custom' - $moduleSource = Get-Content -Path (Join-Path $customPath 'Az.Cdn.custom.psm1') -Raw - $helperSource = Get-Content -Path (Join-Path $customPath 'Get-AzCdnReadParameters.ps1') -Raw - - $helperSource | Should Match '\[Microsoft\.Azure\.PowerShell\.Cmdlets\.Cdn\.DoNotExportAttribute\(\)\]' - $moduleSource | Should Match "Get-ChildItem\s+-Path\s+\`$PSScriptRoot\s+-Recurse\s+-Include\s+'\*\.ps1'" - } -} diff --git a/src/Cdn/Cdn/ChangeLog.md b/src/Cdn/Cdn/ChangeLog.md index 13a5dbaf79c8..ef40f7f66c53 100644 --- a/src/Cdn/Cdn/ChangeLog.md +++ b/src/Cdn/Cdn/ChangeLog.md @@ -20,6 +20,7 @@ ## Upcoming Release +* Fixed Change Safety parameter forwarding in custom read-before-write cmdlets. * Documented the planned removal of standalone EdgeAction resource cmdlets in Az.Cdn 7.0.0 and Az 17.0.0 on November 15, 2026. This advance announcement did not change cmdlet behavior or add runtime warnings; EdgeAction delivery-rule actions and URL signing are not affected. * Added post-migration endpoint cutover guidance for Azure Front Door (classic) and Azure CDN from Microsoft (classic) migrations. @@ -159,4 +160,3 @@ Fixed enabling CDN custom domain HTTPS for Microsoft and Akamai SKU's ## Version 1.0.0 * General availability of `Az.Cdn` module - diff --git a/src/EventHub/EventHub.Autorest/test/GeoDRDynamicParameterForwarding.Tests.ps1 b/src/EventHub/EventHub.Autorest/test/GeoDRDynamicParameterForwarding.Tests.ps1 deleted file mode 100644 index 7b750d507d9a..000000000000 --- a/src/EventHub/EventHub.Autorest/test/GeoDRDynamicParameterForwarding.Tests.ps1 +++ /dev/null @@ -1,98 +0,0 @@ -class EventHubTestDynamicParameters : System.Management.Automation.IDynamicParameters { - [object] GetDynamicParameters() { - $parameters = [System.Management.Automation.RuntimeDefinedParameterDictionary]::new() - foreach ($name in 'AcquirePolicyToken', 'ChangeReference', 'FutureDynamic', 'InputObject', 'Name', 'NamespaceName', 'ResourceGroupName', 'SubscriptionId') { - $attributes = [System.Collections.ObjectModel.Collection[System.Attribute]]::new() - $parameters.Add($name, [System.Management.Automation.RuntimeDefinedParameter]::new($name, [object], $attributes)) - } - return $parameters - } -} - -$helperPath = Join-Path $PSScriptRoot '..\custom\Add-AzEventHubBoundDynamicParameter.ps1' -$helperSource = Get-Content -Path $helperPath -Raw -$helperSource = $helperSource -replace '(?m)^\s*\[Microsoft\.Azure\.PowerShell\.Cmdlets\.EventHub\.DoNotExportAttribute\(\)\]\r?\n', '' -. ([scriptblock]::Create($helperSource)) - -Describe 'EventHub GeoDR via-identity dynamic parameter forwarding' { - Mock Get-Command { - [pscustomobject]@{ - CommandType = [System.Management.Automation.CommandTypes]::Cmdlet - ImplementingType = [EventHubTestDynamicParameters] - } - } - - It 'adds only bound, non-path dynamic parameters to the environment splat' { - $boundParameters = @{ - AcquirePolicyToken = $true - ChangeReference = 'change-123' - FutureDynamic = 'future-value' - InputObject = 'identity' - Name = 'alias' - NamespaceName = 'namespace' - ResourceGroupName = 'resource-group' - SubscriptionId = 'subscription' - } - $environmentParameters = @{ Debug = $true } - - Add-AzEventHubBoundDynamicParameter -CommandName 'Az.EventHub.private\Test-Target' -BoundParameters $boundParameters -TargetParameters $environmentParameters -ExcludedParameter InputObject, Name, NamespaceName, ResourceGroupName, SubscriptionId - - $environmentParameters.AcquirePolicyToken | Should Be $true - $environmentParameters.ChangeReference | Should Be 'change-123' - $environmentParameters.FutureDynamic | Should Be 'future-value' - $environmentParameters.Debug | Should Be $true - $environmentParameters.ContainsKey('InputObject') | Should Be $false - $environmentParameters.ContainsKey('Name') | Should Be $false - $environmentParameters.ContainsKey('NamespaceName') | Should Be $false - $environmentParameters.ContainsKey('ResourceGroupName') | Should Be $false - $environmentParameters.ContainsKey('SubscriptionId') | Should Be $false - $environmentParameters.Count | Should Be 4 - } - - It 'does not add supported dynamic parameters that were not bound' { - $environmentParameters = @{} - - Add-AzEventHubBoundDynamicParameter -CommandName 'Az.EventHub.private\Test-Target' -BoundParameters @{ FutureDynamic = 'future-value' } -TargetParameters $environmentParameters - - $environmentParameters.FutureDynamic | Should Be 'future-value' - $environmentParameters.ContainsKey('AcquirePolicyToken') | Should Be $false - $environmentParameters.ContainsKey('ChangeReference') | Should Be $false - } - - It 'accepts the PSBoundParameters dictionary used by custom cmdlets' { - function Invoke-EventHubTestForwarding { - param( - [string] $ChangeReference - ) - - $environmentParameters = @{} - Add-AzEventHubBoundDynamicParameter -CommandName 'Az.EventHub.private\Test-Target' -BoundParameters $PSBoundParameters -TargetParameters $environmentParameters - return $environmentParameters - } - - $environmentParameters = Invoke-EventHubTestForwarding -ChangeReference 'change-123' - - $environmentParameters.ChangeReference | Should Be 'change-123' - } - - It 'uses exact target metadata and environment splats in both via-identity branches' { - $cases = @( - @{ - File = 'Set-AzEventHubGeoDRConfigurationBreakPair.ps1' - Command = 'Az.EventHub.private\Invoke-AzEventHubBreakDisasterRecoveryConfigPairing_Break' - }, - @{ - File = 'Set-AzEventHubGeoDRConfigurationFailOver.ps1' - Command = 'Az.EventHub.private\Invoke-AzEventHubFailDisasterRecoveryConfigOver_Fail' - } - ) - - foreach ($case in $cases) { - $source = Get-Content -Path (Join-Path $PSScriptRoot "..\custom\$($case.File)") -Raw - $escapedCommand = [regex]::Escape($case.Command) - - $source | Should Match "Add-AzEventHubBoundDynamicParameter -CommandName '$escapedCommand' -BoundParameters \`$PSBoundParameters -TargetParameters \`$EnvPSBoundParameters" - $source | Should Match "$escapedCommand .+@EnvPSBoundParameters" - } - } -} diff --git a/src/EventHub/EventHub.Autorest/test/ReadParameterForwarding.Tests.ps1 b/src/EventHub/EventHub.Autorest/test/ReadParameterForwarding.Tests.ps1 deleted file mode 100644 index 2ce31073b72b..000000000000 --- a/src/EventHub/EventHub.Autorest/test/ReadParameterForwarding.Tests.ps1 +++ /dev/null @@ -1,106 +0,0 @@ -$helperPath = Join-Path $PSScriptRoot '..\custom\Get-AzEventHubReadParameters.ps1' -$helperSource = Get-Content -Path $helperPath -Raw -$helperSource = $helperSource -replace '(?m)^\s*\[Microsoft\.Azure\.PowerShell\.Cmdlets\.EventHub\.DoNotExportAttribute\(\)\]\r?\n', '' -. ([scriptblock]::Create($helperSource)) - -function Get-AzEventHubReadTestResource { - [CmdletBinding()] - param( - [Alias('ResourceName')] - [string] $Name, - [object] $DefaultProfile - ) - - $script:eventHubReadParameters = @{} + $PSBoundParameters -} - -function Set-AzEventHubReadTestResource { - [CmdletBinding()] - param( - [string] $Name, - [object] $DefaultProfile, - [switch] $AcquirePolicyToken, - [string] $ChangeReference, - [string] $SyntheticWriteOnly - ) - - $script:eventHubWriteParameters = @{} + $PSBoundParameters -} - -Set-Alias -Name Get-AzEventHubReadTestAlias -Value Get-AzEventHubReadTestResource - -Describe 'EventHub read parameter forwarding' { - It 'filters write-only parameters using read command metadata without changing write parameters' { - $writeParameters = @{ - Name = 'eventhub' - DefaultProfile = 'profile' - ErrorAction = 'Stop' - AcquirePolicyToken = $true - ChangeReference = 'change-123' - SyntheticWriteOnly = 'future-value' - } - - $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHubReadTestAlias' -BoundParameters $writeParameters - Get-AzEventHubReadTestResource @readParameters - Set-AzEventHubReadTestResource @writeParameters - - $script:eventHubReadParameters.Name | Should Be 'eventhub' - $script:eventHubReadParameters.DefaultProfile | Should Be 'profile' - $script:eventHubReadParameters.ErrorAction | Should Be 'Stop' - $script:eventHubReadParameters.ContainsKey('AcquirePolicyToken') | Should Be $false - $script:eventHubReadParameters.ContainsKey('ChangeReference') | Should Be $false - $script:eventHubReadParameters.ContainsKey('SyntheticWriteOnly') | Should Be $false - $script:eventHubWriteParameters.AcquirePolicyToken | Should Be $true - $script:eventHubWriteParameters.ChangeReference | Should Be 'change-123' - $script:eventHubWriteParameters.SyntheticWriteOnly | Should Be 'future-value' - } - - It 'recognizes read parameter aliases' { - $readParameters = Get-AzEventHubReadParameters -CommandName 'Get-AzEventHubReadTestResource' -BoundParameters @{ ResourceName = 'eventhub' } - - $readParameters.ResourceName | Should Be 'eventhub' - } - - It 'uses read parameters without replacing the original bound parameters in every affected wrapper' { - $wrappers = @( - 'Approve-AzEventHubPrivateEndpointConnection.ps1', - 'Deny-AzEventHubPrivateEndpointConnection.ps1', - 'Set-AzEventHub.ps1', - 'Set-AzEventHubApplicationGroup.ps1', - 'Set-AzEventHubAuthorizationRule.ps1', - 'Set-AzEventHubCluster.ps1', - 'Set-AzEventHubConsumerGroup.ps1', - 'Set-AzEventHubGeoDRConfigurationBreakPair.ps1', - 'Set-AzEventHubGeoDRConfigurationFailOver.ps1', - 'Set-AzEventHubNamespace.ps1', - 'Set-AzEventHubNetworkRuleSet.ps1' - ) - - foreach ($wrapper in $wrappers) { - $source = Get-Content -Path (Join-Path $PSScriptRoot "..\custom\$wrapper") -Raw - $source | Should Not Match '\$targetParameters' - $source | Should Match 'Get-AzEventHubReadParameters\s+-CommandName\s+''[^'']+''\s+-BoundParameters\s+\$PSBoundParameters' - $source | Should Match '@readParameters' - $source | Should Match '@PSBoundParameters' - } - } - - It 'keeps exact expanded and via-identity read variants for authorization rules' { - $source = Get-Content -Path (Join-Path $PSScriptRoot '..\custom\Set-AzEventHubAuthorizationRule.ps1') -Raw - - $source | Should Match "CommandName 'Az\.EventHub\.private\\Get-AzEventHubAuthorizationRule_Get'" - $source | Should Match "CommandName 'Az\.EventHub\.private\\Get-AzEventHubAuthorizationRule_GetViaIdentity'" - $source | Should Match "CommandName 'Az\.EventHub\.private\\Get-AzEventHubNamespaceAuthorizationRule_GetViaIdentity'" - } - - It 'packages the internal helper' { - $customPath = Join-Path $PSScriptRoot '..\custom' - $helperPath = Join-Path $customPath 'Get-AzEventHubReadParameters.ps1' - $moduleSource = Get-Content -Path (Join-Path $customPath 'Az.EventHub.custom.psm1') -Raw - $helperSource = Get-Content -Path $helperPath -Raw - - Test-Path -Path $helperPath | Should Be $true - $helperSource | Should Match '\[Microsoft\.Azure\.PowerShell\.Cmdlets\.EventHub\.DoNotExportAttribute\(\)\]' - $moduleSource | Should Match "Get-ChildItem\s+-Path\s+\`$PSScriptRoot\s+-Recurse\s+-Include\s+'\*\.ps1'" - } -} diff --git a/src/EventHub/EventHub/ChangeLog.md b/src/EventHub/EventHub/ChangeLog.md index ec175fff137f..f56261f6eb43 100644 --- a/src/EventHub/EventHub/ChangeLog.md +++ b/src/EventHub/EventHub/ChangeLog.md @@ -19,6 +19,7 @@ --> ## Upcoming Release * Added Change Safety support for additional cmdlets. +* Fixed Change Safety parameter forwarding in custom read-before-write and GeoDR cmdlets. ## Version 5.6.0 * Added parameter `IPAddressType` to cmdlets 'New-AzEventHubNamespace' and 'Set-AzEventHubNamespace' diff --git a/src/Network/Network/ChangeLog.md b/src/Network/Network/ChangeLog.md index d76afbf444de..26b79782a725 100644 --- a/src/Network/Network/ChangeLog.md +++ b/src/Network/Network/ChangeLog.md @@ -19,6 +19,7 @@ ---> ## Upcoming Release +* Fixed Change Safety parameter forwarding in custom read-before-write cmdlets. * Added provider-led ExpressRoute cross-connection migration commands to validate, inspect, prepare, migrate, commit, and roll back migrations, and shut down or restore BGP (Border Gateway Protocol). - Added `Invoke-AzExpressRouteCrossConnectionMigration` to invoke the migration action. - Added `New-AzExpressRouteCrossConnectionPortMapping` to construct source-to-target port mappings. Migration actions support confirmation, WhatIf, and background jobs. diff --git a/src/Network/NetworkSecurityPerimeter.Autorest/test/ReadParameterForwarding.Tests.ps1 b/src/Network/NetworkSecurityPerimeter.Autorest/test/ReadParameterForwarding.Tests.ps1 deleted file mode 100644 index ff173e8e0ae2..000000000000 --- a/src/Network/NetworkSecurityPerimeter.Autorest/test/ReadParameterForwarding.Tests.ps1 +++ /dev/null @@ -1,91 +0,0 @@ -$helperPath = Join-Path $PSScriptRoot '..\custom\Get-AzNetworkSecurityPerimeterReadParameters.ps1' -$helperSource = Get-Content -Path $helperPath -Raw -$helperSource = $helperSource -replace '(?m)^\s*\[Microsoft\.Azure\.PowerShell\.Cmdlets\.NetworkSecurityPerimeter\.DoNotExportAttribute\(\)\]\r?\n', '' -. ([scriptblock]::Create($helperSource)) - -function Get-AzNetworkSecurityPerimeterReadTestResource { - [CmdletBinding()] - param( - [Alias('ResourceName')] - [string] $Name, - [object] $DefaultProfile - ) - - $script:nspReadParameters = @{} + $PSBoundParameters -} - -function Set-AzNetworkSecurityPerimeterReadTestResource { - [CmdletBinding()] - param( - [string] $Name, - [object] $DefaultProfile, - [switch] $AcquirePolicyToken, - [string] $ChangeReference, - [string] $SyntheticWriteOnly - ) - - $script:nspWriteParameters = @{} + $PSBoundParameters -} - -Set-Alias -Name Get-AzNetworkSecurityPerimeterReadTestAlias -Value Get-AzNetworkSecurityPerimeterReadTestResource - -Describe 'NetworkSecurityPerimeter read parameter forwarding' { - It 'filters write-only parameters using read command metadata without changing write parameters' { - $writeParameters = @{ - Name = 'access-rule' - DefaultProfile = 'profile' - ErrorAction = 'Stop' - AcquirePolicyToken = $true - ChangeReference = 'change-123' - SyntheticWriteOnly = 'future-value' - } - - $readParameters = Get-AzNetworkSecurityPerimeterReadParameters -CommandName 'Get-AzNetworkSecurityPerimeterReadTestAlias' -BoundParameters $writeParameters - Get-AzNetworkSecurityPerimeterReadTestResource @readParameters - Set-AzNetworkSecurityPerimeterReadTestResource @writeParameters - - $script:nspReadParameters.Name | Should Be 'access-rule' - $script:nspReadParameters.DefaultProfile | Should Be 'profile' - $script:nspReadParameters.ErrorAction | Should Be 'Stop' - $script:nspReadParameters.ContainsKey('AcquirePolicyToken') | Should Be $false - $script:nspReadParameters.ContainsKey('ChangeReference') | Should Be $false - $script:nspReadParameters.ContainsKey('SyntheticWriteOnly') | Should Be $false - $script:nspWriteParameters.AcquirePolicyToken | Should Be $true - $script:nspWriteParameters.ChangeReference | Should Be 'change-123' - $script:nspWriteParameters.SyntheticWriteOnly | Should Be 'future-value' - } - - It 'recognizes read parameter aliases' { - $readParameters = Get-AzNetworkSecurityPerimeterReadParameters -CommandName 'Get-AzNetworkSecurityPerimeterReadTestResource' -BoundParameters @{ ResourceName = 'access-rule' } - - $readParameters.ResourceName | Should Be 'access-rule' - } - - It 'uses read parameters without replacing the original bound parameters in every affected wrapper' { - $wrappers = @( - 'Update-AzNetworkSecurityPerimeterAccessRule.ps1', - 'Update-AzNetworkSecurityPerimeterAssociation.ps1', - 'Update-AzNetworkSecurityPerimeterLink.ps1', - 'Update-AzNetworkSecurityPerimeterLoggingConfiguration.ps1' - ) - - foreach ($wrapper in $wrappers) { - $source = Get-Content -Path (Join-Path $PSScriptRoot "..\custom\$wrapper") -Raw - $source | Should Not Match '\$targetParameters' - $source | Should Match 'Get-AzNetworkSecurityPerimeterReadParameters\s+-CommandName\s+''[^'']+''\s+-BoundParameters\s+\$PSBoundParameters' - $source | Should Match '@readParameters' - $source | Should Match '@PSBoundParameters' - } - } - - It 'packages the internal helper' { - $customPath = Join-Path $PSScriptRoot '..\custom' - $helperPath = Join-Path $customPath 'Get-AzNetworkSecurityPerimeterReadParameters.ps1' - $moduleSource = Get-Content -Path (Join-Path $customPath 'Az.NetworkSecurityPerimeter.custom.psm1') -Raw - $helperSource = Get-Content -Path $helperPath -Raw - - Test-Path -Path $helperPath | Should Be $true - $helperSource | Should Match '\[Microsoft\.Azure\.PowerShell\.Cmdlets\.NetworkSecurityPerimeter\.DoNotExportAttribute\(\)\]' - $moduleSource | Should Match "Get-ChildItem\s+-Path\s+\`$PSScriptRoot\s+-Recurse\s+-Include\s+'\*\.ps1'" - } -} diff --git a/src/ServiceBus/ServiceBus.Autorest/test/GeoDRDynamicParameterForwarding.Tests.ps1 b/src/ServiceBus/ServiceBus.Autorest/test/GeoDRDynamicParameterForwarding.Tests.ps1 deleted file mode 100644 index 43c516d26d4a..000000000000 --- a/src/ServiceBus/ServiceBus.Autorest/test/GeoDRDynamicParameterForwarding.Tests.ps1 +++ /dev/null @@ -1,98 +0,0 @@ -class ServiceBusTestDynamicParameters : System.Management.Automation.IDynamicParameters { - [object] GetDynamicParameters() { - $parameters = [System.Management.Automation.RuntimeDefinedParameterDictionary]::new() - foreach ($name in 'AcquirePolicyToken', 'ChangeReference', 'FutureDynamic', 'InputObject', 'Name', 'NamespaceName', 'ResourceGroupName', 'SubscriptionId') { - $attributes = [System.Collections.ObjectModel.Collection[System.Attribute]]::new() - $parameters.Add($name, [System.Management.Automation.RuntimeDefinedParameter]::new($name, [object], $attributes)) - } - return $parameters - } -} - -$helperPath = Join-Path $PSScriptRoot '..\custom\Add-AzServiceBusBoundDynamicParameter.ps1' -$helperSource = Get-Content -Path $helperPath -Raw -$helperSource = $helperSource -replace '(?m)^\s*\[Microsoft\.Azure\.PowerShell\.Cmdlets\.ServiceBus\.DoNotExportAttribute\(\)\]\r?\n', '' -. ([scriptblock]::Create($helperSource)) - -Describe 'ServiceBus GeoDR via-identity dynamic parameter forwarding' { - Mock Get-Command { - [pscustomobject]@{ - CommandType = [System.Management.Automation.CommandTypes]::Cmdlet - ImplementingType = [ServiceBusTestDynamicParameters] - } - } - - It 'adds only bound, non-path dynamic parameters to the environment splat' { - $boundParameters = @{ - AcquirePolicyToken = $true - ChangeReference = 'change-123' - FutureDynamic = 'future-value' - InputObject = 'identity' - Name = 'alias' - NamespaceName = 'namespace' - ResourceGroupName = 'resource-group' - SubscriptionId = 'subscription' - } - $environmentParameters = @{ Debug = $true } - - Add-AzServiceBusBoundDynamicParameter -CommandName 'Az.ServiceBus.private\Test-Target' -BoundParameters $boundParameters -TargetParameters $environmentParameters -ExcludedParameter InputObject, Name, NamespaceName, ResourceGroupName, SubscriptionId - - $environmentParameters.AcquirePolicyToken | Should Be $true - $environmentParameters.ChangeReference | Should Be 'change-123' - $environmentParameters.FutureDynamic | Should Be 'future-value' - $environmentParameters.Debug | Should Be $true - $environmentParameters.ContainsKey('InputObject') | Should Be $false - $environmentParameters.ContainsKey('Name') | Should Be $false - $environmentParameters.ContainsKey('NamespaceName') | Should Be $false - $environmentParameters.ContainsKey('ResourceGroupName') | Should Be $false - $environmentParameters.ContainsKey('SubscriptionId') | Should Be $false - $environmentParameters.Count | Should Be 4 - } - - It 'does not add supported dynamic parameters that were not bound' { - $environmentParameters = @{} - - Add-AzServiceBusBoundDynamicParameter -CommandName 'Az.ServiceBus.private\Test-Target' -BoundParameters @{ FutureDynamic = 'future-value' } -TargetParameters $environmentParameters - - $environmentParameters.FutureDynamic | Should Be 'future-value' - $environmentParameters.ContainsKey('AcquirePolicyToken') | Should Be $false - $environmentParameters.ContainsKey('ChangeReference') | Should Be $false - } - - It 'accepts the PSBoundParameters dictionary used by custom cmdlets' { - function Invoke-ServiceBusTestForwarding { - param( - [string] $ChangeReference - ) - - $environmentParameters = @{} - Add-AzServiceBusBoundDynamicParameter -CommandName 'Az.ServiceBus.private\Test-Target' -BoundParameters $PSBoundParameters -TargetParameters $environmentParameters - return $environmentParameters - } - - $environmentParameters = Invoke-ServiceBusTestForwarding -ChangeReference 'change-123' - - $environmentParameters.ChangeReference | Should Be 'change-123' - } - - It 'uses exact target metadata and environment splats in both via-identity branches' { - $cases = @( - @{ - File = 'Set-AzServiceBusGeoDRConfigurationBreakPair.ps1' - Command = 'Az.ServiceBus.private\Invoke-AzServiceBusBreakDisasterRecoveryConfigPairing_Break' - }, - @{ - File = 'Set-AzServiceBusGeoDRConfigurationFailOver.ps1' - Command = 'Az.ServiceBus.private\Invoke-AzServiceBusFailDisasterRecoveryConfigOver_FailExpanded' - } - ) - - foreach ($case in $cases) { - $source = Get-Content -Path (Join-Path $PSScriptRoot "..\custom\$($case.File)") -Raw - $escapedCommand = [regex]::Escape($case.Command) - - $source | Should Match "Add-AzServiceBusBoundDynamicParameter -CommandName '$escapedCommand' -BoundParameters \`$PSBoundParameters -TargetParameters \`$EnvPSBoundParameters" - $source | Should Match "$escapedCommand .+@EnvPSBoundParameters" - } - } -} diff --git a/src/ServiceBus/ServiceBus.Autorest/test/ReadParameterForwarding.Tests.ps1 b/src/ServiceBus/ServiceBus.Autorest/test/ReadParameterForwarding.Tests.ps1 deleted file mode 100644 index c684bcd421bc..000000000000 --- a/src/ServiceBus/ServiceBus.Autorest/test/ReadParameterForwarding.Tests.ps1 +++ /dev/null @@ -1,106 +0,0 @@ -$helperPath = Join-Path $PSScriptRoot '..\custom\Get-AzServiceBusReadParameters.ps1' -$helperSource = Get-Content -Path $helperPath -Raw -$helperSource = $helperSource -replace '(?m)^\s*\[Microsoft\.Azure\.PowerShell\.Cmdlets\.ServiceBus\.DoNotExportAttribute\(\)\]\r?\n', '' -. ([scriptblock]::Create($helperSource)) - -function Get-AzServiceBusReadTestResource { - [CmdletBinding()] - param( - [Alias('ResourceName')] - [string] $Name, - [object] $DefaultProfile - ) - - $script:serviceBusReadParameters = @{} + $PSBoundParameters -} - -function Set-AzServiceBusReadTestResource { - [CmdletBinding()] - param( - [string] $Name, - [object] $DefaultProfile, - [switch] $AcquirePolicyToken, - [string] $ChangeReference, - [string] $SyntheticWriteOnly - ) - - $script:serviceBusWriteParameters = @{} + $PSBoundParameters -} - -Set-Alias -Name Get-AzServiceBusReadTestAlias -Value Get-AzServiceBusReadTestResource - -Describe 'ServiceBus read parameter forwarding' { - It 'filters write-only parameters using read command metadata without changing write parameters' { - $writeParameters = @{ - Name = 'queue' - DefaultProfile = 'profile' - ErrorAction = 'Stop' - AcquirePolicyToken = $true - ChangeReference = 'change-123' - SyntheticWriteOnly = 'future-value' - } - - $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusReadTestAlias' -BoundParameters $writeParameters - Get-AzServiceBusReadTestResource @readParameters - Set-AzServiceBusReadTestResource @writeParameters - - $script:serviceBusReadParameters.Name | Should Be 'queue' - $script:serviceBusReadParameters.DefaultProfile | Should Be 'profile' - $script:serviceBusReadParameters.ErrorAction | Should Be 'Stop' - $script:serviceBusReadParameters.ContainsKey('AcquirePolicyToken') | Should Be $false - $script:serviceBusReadParameters.ContainsKey('ChangeReference') | Should Be $false - $script:serviceBusReadParameters.ContainsKey('SyntheticWriteOnly') | Should Be $false - $script:serviceBusWriteParameters.AcquirePolicyToken | Should Be $true - $script:serviceBusWriteParameters.ChangeReference | Should Be 'change-123' - $script:serviceBusWriteParameters.SyntheticWriteOnly | Should Be 'future-value' - } - - It 'recognizes read parameter aliases' { - $readParameters = Get-AzServiceBusReadParameters -CommandName 'Get-AzServiceBusReadTestResource' -BoundParameters @{ ResourceName = 'queue' } - - $readParameters.ResourceName | Should Be 'queue' - } - - It 'uses read parameters without replacing the original bound parameters in every affected wrapper' { - $wrappers = @( - 'Approve-AzServiceBusPrivateEndpointConnection.ps1', - 'Deny-AzServiceBusPrivateEndpointConnection.ps1', - 'Set-AzServiceBusAuthorizationRule.ps1', - 'Set-AzServiceBusGeoDRConfigurationBreakPair.ps1', - 'Set-AzServiceBusGeoDRConfigurationFailOver.ps1', - 'Set-AzServiceBusNamespace.ps1', - 'Set-AzServiceBusNetworkRuleSet.ps1', - 'Set-AzServiceBusQueue.ps1', - 'Set-AzServiceBusRule.ps1', - 'Set-AzServiceBusSubscription.ps1', - 'Set-AzServiceBusTopic.ps1' - ) - - foreach ($wrapper in $wrappers) { - $source = Get-Content -Path (Join-Path $PSScriptRoot "..\custom\$wrapper") -Raw - $source | Should Not Match '\$targetParameters' - $source | Should Match 'Get-AzServiceBusReadParameters\s+-CommandName\s+''[^'']+''\s+-BoundParameters\s+\$PSBoundParameters' - $source | Should Match '@readParameters' - $source | Should Match '@PSBoundParameters' - } - } - - It 'keeps exact expanded and via-identity read variants for authorization rules' { - $source = Get-Content -Path (Join-Path $PSScriptRoot '..\custom\Set-AzServiceBusAuthorizationRule.ps1') -Raw - - $source | Should Match "CommandName 'Az\.ServiceBus\.private\\Get-AzServiceBusQueueAuthorizationRule_Get'" - $source | Should Match "CommandName 'Az\.ServiceBus\.private\\Get-AzServiceBusTopicAuthorizationRule_GetViaIdentity'" - $source | Should Match "CommandName 'Az\.ServiceBus\.private\\Get-AzServiceBusNamespaceAuthorizationRule_GetViaIdentity'" - } - - It 'packages the internal helper' { - $customPath = Join-Path $PSScriptRoot '..\custom' - $helperPath = Join-Path $customPath 'Get-AzServiceBusReadParameters.ps1' - $moduleSource = Get-Content -Path (Join-Path $customPath 'Az.ServiceBus.custom.psm1') -Raw - $helperSource = Get-Content -Path $helperPath -Raw - - Test-Path -Path $helperPath | Should Be $true - $helperSource | Should Match '\[Microsoft\.Azure\.PowerShell\.Cmdlets\.ServiceBus\.DoNotExportAttribute\(\)\]' - $moduleSource | Should Match "Get-ChildItem\s+-Path\s+\`$PSScriptRoot\s+-Recurse\s+-Include\s+'\*\.ps1'" - } -} diff --git a/src/ServiceBus/ServiceBus/ChangeLog.md b/src/ServiceBus/ServiceBus/ChangeLog.md index e1c240079d4e..9d7a5954d19e 100644 --- a/src/ServiceBus/ServiceBus/ChangeLog.md +++ b/src/ServiceBus/ServiceBus/ChangeLog.md @@ -20,6 +20,7 @@ --> ## Upcoming Release * Added Change Safety support for additional cmdlets. +* Fixed Change Safety parameter forwarding in custom read-before-write and GeoDR cmdlets. ## Version 4.3.0 * Added parameters 'GeoDataReplicationMaxReplicationLagDurationInSecond', 'GeoDataReplicationLocation', and 'IPAddressType' to cmdlets 'New-AzServiceBusNamespace' and 'Set-AzServiceBusNamespace'