Skip to content

Migrate ServiceBus from generation to main #24809

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
12 changes: 6 additions & 6 deletions src/ServiceBus/ServiceBus.Autorest/Az.ServiceBus.format.ps1xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<Configuration>
<ViewDefinitions>
<View>
<Name>Microsoft.Azure.PowerShell.Cmdlets.ServiceBus.Models.Api20221001Preview.CorrelationFilterProperties</Name>
<Name>Microsoft.Azure.PowerShell.Cmdlets.ServiceBus.Models.CorrelationFilterProperties</Name>
<ViewSelectedBy>
<TypeName>Microsoft.Azure.PowerShell.Cmdlets.ServiceBus.Models.Api20221001Preview.CorrelationFilterProperties</TypeName>
<TypeName>Microsoft.Azure.PowerShell.Cmdlets.ServiceBus.Models.CorrelationFilterProperties#Multiple</TypeName>
</ViewSelectedBy>
<TableControl>
<TableHeaders>
Expand All @@ -24,9 +24,9 @@
</TableControl>
</View>
<View>
<Name>Microsoft.Azure.PowerShell.Cmdlets.ServiceBus.Models.Api20221001Preview.ResourceNamespacePatchTags</Name>
<Name>Microsoft.Azure.PowerShell.Cmdlets.ServiceBus.Models.ResourceNamespacePatchTags</Name>
<ViewSelectedBy>
<TypeName>Microsoft.Azure.PowerShell.Cmdlets.ServiceBus.Models.Api20221001Preview.ResourceNamespacePatchTags</TypeName>
<TypeName>Microsoft.Azure.PowerShell.Cmdlets.ServiceBus.Models.ResourceNamespacePatchTags#Multiple</TypeName>
</ViewSelectedBy>
<TableControl>
<TableHeaders>
Expand All @@ -46,9 +46,9 @@
</TableControl>
</View>
<View>
<Name>Microsoft.Azure.PowerShell.Cmdlets.ServiceBus.Models.Api10.TrackedResourceTags</Name>
<Name>Microsoft.Azure.PowerShell.Cmdlets.ServiceBus.Models.TrackedResourceTags</Name>
<ViewSelectedBy>
<TypeName>Microsoft.Azure.PowerShell.Cmdlets.ServiceBus.Models.Api10.TrackedResourceTags</TypeName>
<TypeName>Microsoft.Azure.PowerShell.Cmdlets.ServiceBus.Models.TrackedResourceTags#Multiple</TypeName>
</ViewSelectedBy>
<TableControl>
<TableHeaders>
Expand Down
4 changes: 2 additions & 2 deletions src/ServiceBus/ServiceBus.Autorest/Az.ServiceBus.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
DotNetFrameworkVersion = '4.7.2'
RequiredAssemblies = './bin/Az.ServiceBus.private.dll'
FormatsToProcess = './Az.ServiceBus.format.ps1xml'
FunctionsToExport = 'Approve-AzServiceBusPrivateEndpointConnection', 'Complete-AzServiceBusMigration', 'Deny-AzServiceBusPrivateEndpointConnection', 'Get-AzServiceBusAuthorizationRule', 'Get-AzServiceBusGeoDRConfiguration', 'Get-AzServiceBusKey', 'Get-AzServiceBusMigration', 'Get-AzServiceBusNamespace', 'Get-AzServiceBusNetworkRuleSet', 'Get-AzServiceBusPrivateEndpointConnection', 'Get-AzServiceBusPrivateLink', 'Get-AzServiceBusQueue', 'Get-AzServiceBusRule', 'Get-AzServiceBusSubscription', 'Get-AzServiceBusTopic', 'New-AzServiceBusAuthorizationRule', 'New-AzServiceBusGeoDRConfiguration', 'New-AzServiceBusIPRuleConfig', 'New-AzServiceBusKey', 'New-AzServiceBusKeyVaultPropertiesObject', 'New-AzServiceBusNamespace', 'New-AzServiceBusQueue', 'New-AzServiceBusRule', 'New-AzServiceBusSubscription', 'New-AzServiceBusTopic', 'New-AzServiceBusVirtualNetworkRuleConfig', 'Remove-AzServiceBusAuthorizationRule', 'Remove-AzServiceBusGeoDRConfiguration', 'Remove-AzServiceBusMigration', 'Remove-AzServiceBusNamespace', 'Remove-AzServiceBusPrivateEndpointConnection', 'Remove-AzServiceBusQueue', 'Remove-AzServiceBusRule', 'Remove-AzServiceBusSubscription', 'Remove-AzServiceBusTopic', 'Set-AzServiceBusAuthorizationRule', 'Set-AzServiceBusGeoDRConfigurationBreakPair', 'Set-AzServiceBusGeoDRConfigurationFailOver', 'Set-AzServiceBusNamespace', 'Set-AzServiceBusNetworkRuleSet', 'Set-AzServiceBusQueue', 'Set-AzServiceBusRule', 'Set-AzServiceBusSubscription', 'Set-AzServiceBusTopic', 'Start-AzServiceBusMigration', 'Stop-AzServiceBusMigration', 'Test-AzServiceBusName', '*'
AliasesToExport = 'Get-AzServiceBusNamespaceV2', 'New-AzServiceBusNamespaceV2', 'Remove-AzServiceBusNamespaceV2', 'Set-AzServiceBusNamespaceV2', '*'
FunctionsToExport = 'Approve-AzServiceBusPrivateEndpointConnection', 'Complete-AzServiceBusMigration', 'Deny-AzServiceBusPrivateEndpointConnection', 'Get-AzServiceBusAuthorizationRule', 'Get-AzServiceBusGeoDRConfiguration', 'Get-AzServiceBusKey', 'Get-AzServiceBusMigration', 'Get-AzServiceBusNamespace', 'Get-AzServiceBusNetworkRuleSet', 'Get-AzServiceBusPrivateEndpointConnection', 'Get-AzServiceBusPrivateLink', 'Get-AzServiceBusQueue', 'Get-AzServiceBusRule', 'Get-AzServiceBusSubscription', 'Get-AzServiceBusTopic', 'New-AzServiceBusAuthorizationRule', 'New-AzServiceBusGeoDRConfiguration', 'New-AzServiceBusIPRuleConfig', 'New-AzServiceBusKey', 'New-AzServiceBusKeyVaultPropertiesObject', 'New-AzServiceBusNamespace', 'New-AzServiceBusQueue', 'New-AzServiceBusRule', 'New-AzServiceBusSubscription', 'New-AzServiceBusTopic', 'New-AzServiceBusVirtualNetworkRuleConfig', 'Remove-AzServiceBusAuthorizationRule', 'Remove-AzServiceBusGeoDRConfiguration', 'Remove-AzServiceBusMigration', 'Remove-AzServiceBusNamespace', 'Remove-AzServiceBusPrivateEndpointConnection', 'Remove-AzServiceBusQueue', 'Remove-AzServiceBusRule', 'Remove-AzServiceBusSubscription', 'Remove-AzServiceBusTopic', 'Set-AzServiceBusAuthorizationRule', 'Set-AzServiceBusGeoDRConfigurationBreakPair', 'Set-AzServiceBusGeoDRConfigurationFailOver', 'Set-AzServiceBusNamespace', 'Set-AzServiceBusNetworkRuleSet', 'Set-AzServiceBusQueue', 'Set-AzServiceBusRule', 'Set-AzServiceBusSubscription', 'Set-AzServiceBusTopic', 'Start-AzServiceBusMigration', 'Stop-AzServiceBusMigration', 'Test-AzServiceBusName'
AliasesToExport = 'Get-AzServiceBusNamespaceV2', 'New-AzServiceBusNamespaceV2', 'Remove-AzServiceBusNamespaceV2', 'Set-AzServiceBusNamespaceV2'
PrivateData = @{
PSData = @{
Tags = 'Azure', 'ResourceManager', 'ARM', 'PSModule', 'ServiceBus'
Expand Down
22 changes: 6 additions & 16 deletions src/ServiceBus/ServiceBus.Autorest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,13 @@ subject-prefix: $(service-name)
identity-correction-for-post: true
resourcegroup-append: true
nested-object-to-string: true

# For new modules, please avoid setting 3.x using the use-extension method and instead, use 4.x as the default option
use-extension:
"@autorest/powershell": "3.x"
keep-pec-and-plr: true
disable-transform-identity-type: true
flatten-userassignedidentity : false

directive:
- where:
variant: ^Create$|^CreateViaIdentityExpanded$|^Update$|^UpdateViaIdentity$
variant: ^Create$|^CreateViaIdentityExpanded$|^Update$|^UpdateViaIdentity$|^CreateViaJsonFilePath$|^CreateViaJsonString$
remove: true
- where:
variant: ^CreateViaIdentity$
Expand Down Expand Up @@ -524,14 +523,5 @@ directive:
clear-alias: true

- model-cmdlet:
- KeyVaultProperties

- where:
parameter-name: Status
set:
breaking-change:
old-parameter-type: EntityStatus
new-parameter-type: String
deprecated-by-version: 4.0.0
deprecated-by-azversion: 12.0.0
change-effective-date: 2024/05/21
- model-name: KeyVaultProperties
cmdlet-name: New-AzServiceBusKeyVaultPropertiesObject
16 changes: 12 additions & 4 deletions src/ServiceBus/ServiceBus.Autorest/build-module.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
# Code generated by Microsoft (R) AutoRest Code Generator.Changes may cause incorrect behavior and will be lost if the code
# is regenerated.
# ----------------------------------------------------------------------------------
param([switch]$Isolated, [switch]$Run, [switch]$Test, [switch]$Docs, [switch]$Pack, [switch]$Code, [switch]$Release, [switch]$Debugger, [switch]$NoDocs)
param([switch]$NotIsolated, [switch]$Run, [switch]$Test, [switch]$Docs, [switch]$Pack, [switch]$Code, [switch]$Release, [switch]$Debugger, [switch]$NoDocs, [switch]$UX)
$ErrorActionPreference = 'Stop'

if($PSEdition -ne 'Core') {
Write-Error 'This script requires PowerShell Core to execute. [Note] Generated cmdlets will work in both PowerShell Core or Windows PowerShell.'
}

if(-not $Isolated -and -not $Debugger) {
if(-not $NotIsolated -and -not $Debugger) {
Write-Host -ForegroundColor Green 'Creating isolated process...'
$pwsh = [System.Diagnostics.Process]::GetCurrentProcess().Path
& "$pwsh" -NonInteractive -NoLogo -NoProfile -File $MyInvocation.MyCommand.Path @PSBoundParameters -Isolated
& "$pwsh" -NonInteractive -NoLogo -NoProfile -File $MyInvocation.MyCommand.Path @PSBoundParameters -NotIsolated

if($LastExitCode -ne 0) {
# Build failed. Don't attempt to run the module.
Expand All @@ -45,6 +45,14 @@ if(-not $Isolated -and -not $Debugger) {
}
}

if($UX) {
. (Join-Path $PSScriptRoot 'generate-portal-ux.ps1')
if($LastExitCode -ne 0) {
# UX generation failed. Don't attempt to run the module.
return
}
}

if($Pack) {
. (Join-Path $PSScriptRoot 'pack-module.ps1')
if($LastExitCode -ne 0) {
Expand Down Expand Up @@ -122,7 +130,7 @@ $examplesFolder = Join-Path $PSScriptRoot 'examples'
$null = New-Item -ItemType Directory -Force -Path $examplesFolder

Write-Host -ForegroundColor Green 'Creating cmdlets for specified models...'
$modelCmdlets = @('KeyVaultProperties')
$modelCmdlets = @(@{modelName="KeyVaultProperties"; cmdletName="New-AzServiceBusKeyVaultPropertiesObject"})
$modelCmdletFolder = Join-Path (Join-Path $PSScriptRoot './custom') 'autogen-model-cmdlets'
if (Test-Path $modelCmdletFolder) {
$null = Remove-Item -Force -Recurse -Path $modelCmdletFolder
Expand Down
6 changes: 3 additions & 3 deletions src/ServiceBus/ServiceBus.Autorest/check-dependencies.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
# Code generated by Microsoft (R) AutoRest Code Generator.Changes may cause incorrect behavior and will be lost if the code
# is regenerated.
# ----------------------------------------------------------------------------------
param([switch]$Isolated, [switch]$Accounts, [switch]$Pester, [switch]$Resources)
param([switch]$NotIsolated, [switch]$Accounts, [switch]$Pester, [switch]$Resources)
$ErrorActionPreference = 'Stop'

if(-not $Isolated) {
if(-not $NotIsolated) {
Write-Host -ForegroundColor Green 'Creating isolated process...'
$pwsh = [System.Diagnostics.Process]::GetCurrentProcess().Path
& "$pwsh" -NoExit -NoLogo -NoProfile -File $MyInvocation.MyCommand.Path @PSBoundParameters -Isolated
& "$pwsh" -NoExit -NoLogo -NoProfile -File $MyInvocation.MyCommand.Path @PSBoundParameters -NotIsolated
return
}

Expand Down
105 changes: 92 additions & 13 deletions src/ServiceBus/ServiceBus.Autorest/create-model-cmdlets.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

function CreateModelCmdlet {

param([string[]]$Models)
param([Hashtable[]]$Models)

if ($Models.Count -eq 0)
{
Expand All @@ -30,7 +30,6 @@ function CreateModelCmdlet {
} else {
$ModuleName = 'Az.ServiceBus'
}

$CsFiles = Get-ChildItem -Path $ModelCsPath -Recurse -Filter *.cs
$Content = ''
$null = $CsFiles | ForEach-Object -Process { if ($_.Name.Split('.').count -eq 2 )
Expand All @@ -39,15 +38,34 @@ function CreateModelCmdlet {

$Tree = [Microsoft.CodeAnalysis.CSharp.SyntaxFactory]::ParseCompilationUnit($Content)
$Nodes = $Tree.ChildNodes().ChildNodes()
$classConstantMember = @{}
foreach ($Model in $Models)
{
$InterfaceNode = $Nodes | Where-Object { ($_.Keyword.value -eq 'interface') -and ($_.Identifier.value -eq "I$Model") }
$ModelName = $Model.modelName
$InterfaceNode = $Nodes | Where-Object { ($_.Keyword.value -eq 'interface') -and ($_.Identifier.value -eq "I$ModelName") }
$ClassNode = $Nodes | Where-Object { ($_.Keyword.value -eq 'class') -and ($_.Identifier.value -eq "$ModelName") }
$classConstantMember = @()
foreach ($class in $ClassNode) {
foreach ($member in $class.Members) {
$isConstant = $false
foreach ($attr in $member.AttributeLists) {
$memberName = $attr.Attributes.Name.ToString()
if ($memberName.EndsWith('.Constant')) {
$isConstant = $true
break
}
}
if (($member.Modifiers.ToString() -eq 'public') -and $isConstant) {
$classConstantMember += $member.Identifier.Value
}
}
}
if ($InterfaceNode.count -eq 0) {
continue
}
# through a queue, we iterate all the parent models.
$Queue = @($InterfaceNode)
$visited = @("I$Model")
$visited = @("I$ModelName")
$AllInterfaceNodes = @()
while ($Queue.count -ne 0)
{
Expand All @@ -65,7 +83,7 @@ function CreateModelCmdlet {
}

$Namespace = $InterfaceNode.Parent.Name
$ObjectType = $Model
$ObjectType = $ModelName
$ObjectTypeWithNamespace = "${Namespace}.${ObjectType}"
# remove duplicated module name
if ($ObjectType.StartsWith('ServiceBus')) {
Expand All @@ -81,10 +99,15 @@ function CreateModelCmdlet {
{
foreach ($Member in $Node.Members)
{
if ($classConstantMember.Contains($Member.Identifier.Value)) {
# skip constant member
continue
}
$Arguments = $Member.AttributeLists.Attributes.ArgumentList.Arguments
$Required = $false
$Description = ""
$Readonly = $False
$mutability = @{Read = $true; Create = $true; Update = $true}
foreach ($Argument in $Arguments)
{
if ($Argument.NameEquals.Name.Identifier.Value -eq "Required")
Expand All @@ -99,15 +122,37 @@ function CreateModelCmdlet {
{
$Readonly = $Argument.Expression.Token.Value
}
if ($Argument.NameEquals.Name.Identifier.Value -eq "Read")
{
$mutability.Read = $Argument.Expression.Token.Value
}
if ($Argument.NameEquals.Name.Identifier.Value -eq "Create")
{
$mutability.Create = $Argument.Expression.Token.Value
}
if ($Argument.NameEquals.Name.Identifier.Value -eq "Update")
{
$mutability.Update = $Argument.Expression.Token.Value
}
}
if ($Readonly)
{
continue
}
$Identifier = $Member.Identifier.Value
$Type = $Member.Type.ToString().replace('?', '').Split("::")[-1]
$Type = $Member.Type.ToString().replace('?', '').Split("::")[-1]
if ($Type.StartsWith("System.Collections.Generic.List"))
{
# if the type is a list, we need to convert it to array
$matched = $Type -match '\<(?<Name>.+)\>$'
if ($matched)
{
$Type = $matches.Name + '[]';
}
}
$ParameterDefinePropertyList = New-Object System.Collections.Generic.List[string]
if ($Required)
if ($Required -and $mutability.Create -and $mutability.Update)
{
$ParameterDefinePropertyList.Add("Mandatory")
}
Expand All @@ -117,11 +162,9 @@ function CreateModelCmdlet {
}
$ParameterDefineProperty = [System.String]::Join(", ", $ParameterDefinePropertyList)
# check whether completer is needed
$completer = '';
if($Type.Split('.').Split('.')[-2] -eq 'Support') {
# If Type is an array, need to strip []
$strippedType = $Type.Replace('[]', '')
$completer += "`n [ArgumentCompleter([${strippedType}])]"
$completer = '';
if(IsEnumType($Member)){
$completer += GetCompleter($Member)
}
$ParameterDefineScript = "
[Parameter($ParameterDefineProperty)]${completer}
Expand All @@ -137,6 +180,12 @@ function CreateModelCmdlet {
$ParameterDefineScript = $ParameterDefineScriptList | Join-String -Separator ","
$ParameterAssignScript = $ParameterAssignScriptList | Join-String -Separator ""

$cmdletName = "New-Az${ModulePrefix}${ObjectType}Object"
if ('' -ne $Model.cmdletName) {
$cmdletName = $Model.cmdletName
}
$OutputPath = Join-Path -ChildPath "${cmdletName}.ps1" -Path $OutputDir
$cmdletNameInLowerCase = $cmdletName.ToLower()
$Script = "
# ----------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
Expand All @@ -162,9 +211,9 @@ Create an in-memory object for ${ObjectType}.
.Outputs
${ObjectTypeWithNamespace}
.Link
https://learn.microsoft.com/powershell/module/${ModuleName}/new-Az${ModulePrefix}${ObjectType}Object
https://learn.microsoft.com/powershell/module/${ModuleName}/${cmdletNameInLowerCase}
#>
function New-Az${ModulePrefix}${ObjectType}Object {
function ${cmdletName} {
[OutputType('${ObjectTypeWithNamespace}')]
[CmdletBinding(PositionalBinding=`$false)]
Param(
Expand All @@ -181,3 +230,33 @@ ${ParameterAssignScript}
Set-Content -Path $OutputPath -Value $Script
}
}

function IsEnumType {
param (
[Microsoft.CodeAnalysis.CSharp.Syntax.PropertyDeclarationSyntax]$property
)
$isEnum = $false
foreach ($attr in $property.AttributeLists) {
$attributeName = $attr.Attributes.Name.ToString()
if ($attributeName.Contains('ArgumentCompleter')) {
$isEnum = $true
break
}
}
return $isEnum;
}

function GetCompleter {
param (
[Microsoft.CodeAnalysis.CSharp.Syntax.PropertyDeclarationSyntax]$property
)
foreach ($attr in $property.AttributeLists) {
$attributeName = $attr.Attributes.Name.ToString()
if ($attributeName.Contains('ArgumentCompleter')) {
$attributeName = $attributeName.Split("::")[-1]
$possibleValues = [System.String]::Join(", ", $attr.Attributes.ArgumentList.Arguments)
$completer += "`n [${attributeName}(${possibleValues})]"
return $completer
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Approves a ServiceBus PrivateEndpointConnection
#>

function Approve-AzServiceBusPrivateEndpointConnection{
[OutputType([Microsoft.Azure.PowerShell.Cmdlets.ServiceBus.Models.Api20221001Preview.IPrivateEndpointConnection])]
[OutputType([Microsoft.Azure.PowerShell.Cmdlets.ServiceBus.Models.IPrivateEndpointConnection])]
[CmdletBinding(DefaultParameterSetName = 'SetExpanded', PositionalBinding = $false, ConfirmImpact = 'Medium')]
param(
[Parameter(ParameterSetName = 'SetExpanded', HelpMessage = "The name of the Private Endpoint Connection")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Denies a ServiceBus PrivateEndpointConnection
#>

function Deny-AzServiceBusPrivateEndpointConnection{
[OutputType([Microsoft.Azure.PowerShell.Cmdlets.ServiceBus.Models.Api20221001Preview.IPrivateEndpointConnection])]
[OutputType([Microsoft.Azure.PowerShell.Cmdlets.ServiceBus.Models.IPrivateEndpointConnection])]
[CmdletBinding(DefaultParameterSetName = 'SetExpanded', PositionalBinding = $false, ConfirmImpact = 'Medium')]
param(
[Parameter(ParameterSetName = 'SetExpanded', HelpMessage = "The name of the Private Endpoint Connection")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Gets the Authorization Rule of a ServiceBus namespace, queue or topic.
#>

function Get-AzServiceBusAuthorizationRule{
[OutputType([Microsoft.Azure.PowerShell.Cmdlets.ServiceBus.Models.Api20221001Preview.ISbAuthorizationRule])]
[OutputType([Microsoft.Azure.PowerShell.Cmdlets.ServiceBus.Models.ISbAuthorizationRule])]
[CmdletBinding(DefaultParameterSetName = 'GetExpandedNamespace', PositionalBinding = $false, ConfirmImpact = 'Medium')]
param(
[Parameter(ParameterSetName = 'GetExpandedQueue', HelpMessage = "The name of the Authorization Rule")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Gets the SASKey of a ServiceBus namespace, queue or topic.
#>

function Get-AzServiceBusKey{
[OutputType([Microsoft.Azure.PowerShell.Cmdlets.ServiceBus.Models.Api20221001Preview.IAccessKeys])]
[OutputType([Microsoft.Azure.PowerShell.Cmdlets.ServiceBus.Models.IAccessKeys])]
[CmdletBinding(DefaultParameterSetName = 'GetExpandedNamespace', PositionalBinding = $false, ConfirmImpact = 'Medium')]
param(
[Parameter(ParameterSetName = 'GetExpandedQueue', Mandatory, HelpMessage = "The name of the Authorization Rule")]
Expand Down
Loading