Skip to content

Commit 31a3ca3

Browse files
JoyerJinmikefrobbinsazure-powershell-botgrizzlytheodoreisra-fel
authored
[PS] Migrate ProviderHub module to autorest v4 (#27864)
Co-authored-by: Mike F. Robbins <[email protected]> Co-authored-by: Azure PowerShell <[email protected]> Co-authored-by: Theodore Chang <[email protected]> Co-authored-by: Yeming Liu <[email protected]> Co-authored-by: Jin Lei <[email protected]> Co-authored-by: Vincent Dai <[email protected]>
1 parent c690c21 commit 31a3ca3

File tree

102 files changed

+8523
-1121
lines changed

Some content is hidden

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

102 files changed

+8523
-1121
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0 (the ""License"");
3+
// you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at
5+
// http://www.apache.org/licenses/LICENSE-2.0
6+
// Unless required by applicable law or agreed to in writing, software
7+
// distributed under the License is distributed on an ""AS IS"" BASIS,
8+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9+
// See the License for the specific language governing permissions and
10+
// limitations under the License.
11+
// Code generated by Microsoft (R) AutoRest Code Generator.Changes may cause incorrect behavior and will be lost if the code
12+
// is regenerated.
13+
14+
using System;
15+
using System.Reflection;
16+
using System.Runtime.CompilerServices;
17+
using System.Runtime.InteropServices;
18+
19+
[assembly: System.Reflection.AssemblyCompanyAttribute("Microsoft")]
20+
[assembly: System.Reflection.AssemblyCopyrightAttribute("Copyright © Microsoft")]
21+
[assembly: System.Reflection.AssemblyProductAttribute("Microsoft Azure PowerShell")]
22+
[assembly: System.Reflection.AssemblyTitleAttribute("Microsoft Azure PowerShell - ProviderHub")]
23+
[assembly: System.Reflection.AssemblyFileVersionAttribute("0.3.1")]
24+
[assembly: System.Reflection.AssemblyVersionAttribute("0.3.1")]
25+
[assembly: System.Runtime.InteropServices.ComVisibleAttribute(false)]
26+
[assembly: System.CLSCompliantAttribute(false)]
27+
28+

src/ProviderHub/ProviderHub.Autorest/README.md

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,11 @@ input-file:
5454
module-version: 0.1.0
5555
title: ProviderHub
5656
subject-prefix: $(service-name)
57-
identity-correction-for-post: true
58-
59-
# For new modules, please avoid setting 3.x using the use-extension method and instead, use 4.x as the default option
60-
use-extension:
61-
"@autorest/powershell": "3.x"
6257

6358
directive:
6459
- from: swagger-document
6560
where: $.definitions.Error.properties
6661
transform: delete $.innerError
67-
- from: swagger-document
68-
where: $
69-
transform: $ = $.replace(/"authorizations"/, '"fakefields"');
7062
- from: swagger-document
7163
where: $.definitions.FeaturesRule.properties
7264
transform: >-
@@ -78,17 +70,14 @@ directive:
7870
- no-inline:
7971
- Error
8072
- where:
81-
variant: ^Create$|^CreateViaIdentity$|^CreateViaIdentityExpanded$|^Update$|^UpdateViaIdentity$|^Manifest$|^ManifestViaIdentity$|^ManifestViaIdentityExpanded$
73+
variant: ^(Create|Update|Manifest)(?!.*?(Expanded|JsonFilePath|JsonString))
74+
remove: true
75+
- where:
76+
variant: ^ManifestViaIdentityExpanded$|^CreateViaIdentityExpanded$
8277
remove: true
8378
- where:
8479
verb: Set
8580
remove: true
86-
- from: source-file-csharp
87-
where: $
88-
transform: $ = $.replace(/fakefield/g, 'authorization');
89-
- from: source-file-csharp
90-
where: $
91-
transform: $ = $.replace(/Fakefield/g, 'Authorization');
9281

9382
# Hide commands to use Custom
9483
- where:
@@ -108,7 +97,7 @@ directive:
10897
subject: SkuNestedResourceTypeSecond
10998
hide: true
11099
- where:
111-
verb: Get|New|Remove
100+
verb: Get|New|Remove|Update
112101
subject: SkuNestedResourceTypeThird
113102
hide: true
114103
- where:

src/ProviderHub/ProviderHub.Autorest/custom/Get-AzProviderHubResourceTypeRegistration.ps1

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,16 @@ Gets a resource type details in the given subscription and provider.
1919
.Description
2020
Gets a resource type details in the given subscription and provider.
2121
.Example
22-
PS C:\> {{ Add code here }}
23-
24-
{{ Add output here }}
22+
Get-AzProviderHubResourceTypeRegistration -ProviderNamespace "Microsoft.Contoso"
2523
.Example
26-
PS C:\> {{ Add code here }}
27-
28-
{{ Add output here }}
24+
Get-AzProviderHubResourceTypeRegistration -ProviderNamespace "Microsoft.Contoso" -ResourceType "testResourceType1"
25+
.Example
26+
Get-AzProviderHubResourceTypeRegistration -ProviderNamespace "Microsoft.Contoso" -ResourceType "testResourceType1/nestedResourceType"
2927
3028
.Inputs
3129
Microsoft.Azure.PowerShell.Cmdlets.ProviderHub.Models.IProviderHubIdentity
3230
.Outputs
33-
Microsoft.Azure.PowerShell.Cmdlets.ProviderHub.Models.Api20201120.IResourceTypeRegistration
31+
Microsoft.Azure.PowerShell.Cmdlets.ProviderHub.Models.IResourceTypeRegistration
3432
.Notes
3533
COMPLEX PARAMETER PROPERTIES
3634
@@ -51,7 +49,7 @@ INPUTOBJECT <IProviderHubIdentity>: Identity Parameter
5149
https://learn.microsoft.com/powershell/module/az.providerhub/get-azproviderhubresourcetyperegistration
5250
#>
5351
function Get-AzProviderHubResourceTypeRegistration {
54-
[OutputType([Microsoft.Azure.PowerShell.Cmdlets.ProviderHub.Models.Api20201120.IResourceTypeRegistration])]
52+
[OutputType([Microsoft.Azure.PowerShell.Cmdlets.ProviderHub.Models.IResourceTypeRegistration])]
5553
[CmdletBinding(DefaultParameterSetName='List', PositionalBinding=$false)]
5654
param(
5755
[Parameter(ParameterSetName='Get', Mandatory)]
@@ -62,6 +60,7 @@ param(
6260
${ProviderNamespace},
6361

6462
[Parameter(ParameterSetName='Get', Mandatory)]
63+
[Parameter(ParameterSetName='GetViaIdentityProviderRegistration', Mandatory)]
6564
[Microsoft.Azure.PowerShell.Cmdlets.ProviderHub.Category('Path')]
6665
[System.String]
6766
# The resource type.
@@ -79,15 +78,21 @@ param(
7978
[Microsoft.Azure.PowerShell.Cmdlets.ProviderHub.Category('Path')]
8079
[Microsoft.Azure.PowerShell.Cmdlets.ProviderHub.Models.IProviderHubIdentity]
8180
# Identity Parameter
82-
# To construct, see NOTES section for INPUTOBJECT properties and create a hash table.
8381
${InputObject},
8482

83+
[Parameter(ParameterSetName='GetViaIdentityProviderRegistration', Mandatory, ValueFromPipeline)]
84+
[Microsoft.Azure.PowerShell.Cmdlets.ProviderHub.Category('Path')]
85+
[Microsoft.Azure.PowerShell.Cmdlets.ProviderHub.Models.IProviderHubIdentity]
86+
# Identity Parameter
87+
${ProviderRegistrationInputObject},
88+
8589
[Parameter()]
8690
[Alias('AzureRMContext', 'AzureCredential')]
8791
[ValidateNotNull()]
8892
[Microsoft.Azure.PowerShell.Cmdlets.ProviderHub.Category('Azure')]
8993
[System.Management.Automation.PSObject]
90-
# The credentials, account, tenant, and subscription used for communication with Azure.
94+
# The DefaultProfile parameter is not functional.
95+
# Use the SubscriptionId parameter when available if executing the cmdlet against a different subscription.
9196
${DefaultProfile},
9297

9398
[Parameter(DontShow)]
@@ -137,19 +142,31 @@ begin {
137142
$PSBoundParameters['OutBuffer'] = 1
138143
}
139144
$parameterSet = $PSCmdlet.ParameterSetName
145+
146+
$testPlayback = $false
147+
$PSBoundParameters['HttpPipelinePrepend'] | Foreach-Object { if ($_) { $testPlayback = $testPlayback -or ('Microsoft.Azure.PowerShell.Cmdlets.ProviderHub.Runtime.PipelineMock' -eq $_.Target.GetType().FullName -and 'Playback' -eq $_.Target.Mode) } }
148+
140149
$mapping = @{
141150
Get = 'Az.ProviderHub.private\Get-AzProviderHubResourceTypeRegistration_Get';
142151
GetViaIdentity = 'Az.ProviderHub.private\Get-AzProviderHubResourceTypeRegistration_GetViaIdentity';
152+
GetViaIdentityProviderRegistration = 'Az.ProviderHub.private\Get-AzProviderHubResourceTypeRegistration_GetViaIdentityProviderRegistration';
143153
List = 'Az.ProviderHub.private\Get-AzProviderHubResourceTypeRegistration_List';
144154
}
145-
if (('Get', 'List') -contains $parameterSet -and -not $PSBoundParameters.ContainsKey('SubscriptionId')) {
146-
$PSBoundParameters['SubscriptionId'] = (Get-AzContext).Subscription.Id
155+
if (('Get', 'List') -contains $parameterSet -and -not $PSBoundParameters.ContainsKey('SubscriptionId') ) {
156+
if ($testPlayback) {
157+
$PSBoundParameters['SubscriptionId'] = . (Join-Path $PSScriptRoot '..' 'utils' 'Get-SubscriptionIdTestSafe.ps1')
158+
} else {
159+
$PSBoundParameters['SubscriptionId'] = (Get-AzContext).Subscription.Id
160+
}
147161
}
148162
if ($PSBoundParameters.ContainsKey('ResourceType')) {
149163
$resourceTypePath = $PSBoundParameters['ResourceType'] -Split "/" -Join "/resourcetyperegistrations/"
150164
$PSBoundParameters['ResourceType'] = $resourceTypePath
151165
}
152166
$wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand(($mapping[$parameterSet]), [System.Management.Automation.CommandTypes]::Cmdlet)
167+
if ($null -eq $wrappedCmd) {
168+
$wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand(($mapping[$parameterSet]), [System.Management.Automation.CommandTypes]::Function)
169+
}
153170
$scriptCmd = {& $wrappedCmd @PSBoundParameters}
154171
$steppablePipeline = $scriptCmd.GetSteppablePipeline($MyInvocation.CommandOrigin)
155172
$steppablePipeline.Begin($PSCmdlet)

src/ProviderHub/ProviderHub.Autorest/custom/Get-AzProviderHubSku.ps1

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,14 @@ Gets the sku details for the given resource type and sku name.
1919
.Description
2020
Gets the sku details for the given resource type and sku name.
2121
.Example
22-
PS C:\> {{ Add code here }}
23-
24-
{{ Add output here }}
22+
Get-AzProviderHubSku -ProviderNamespace "Microsoft.Contoso" -ResourceType "testResourceType" -Sku "default"
2523
.Example
26-
PS C:\> {{ Add code here }}
27-
28-
{{ Add output here }}
24+
Get-AzProviderHubSku -ProviderNamespace "Microsoft.Contoso" -ResourceType "testResourceType/nestedResourceType" -Sku "default"
2925
3026
.Inputs
3127
Microsoft.Azure.PowerShell.Cmdlets.ProviderHub.Models.IProviderHubIdentity
3228
.Outputs
33-
Microsoft.Azure.PowerShell.Cmdlets.ProviderHub.Models.Api20201120.ISkuResource
29+
Microsoft.Azure.PowerShell.Cmdlets.ProviderHub.Models.ISkuResource
3430
.Notes
3531
COMPLEX PARAMETER PROPERTIES
3632
@@ -51,7 +47,7 @@ INPUTOBJECT <IProviderHubIdentity>: Identity Parameter
5147
https://learn.microsoft.com/powershell/module/az.providerhub/get-azproviderhubsku
5248
#>
5349
function Get-AzProviderHubSku {
54-
[OutputType([Microsoft.Azure.PowerShell.Cmdlets.ProviderHub.Models.Api20201120.ISkuResource])]
50+
[OutputType([Microsoft.Azure.PowerShell.Cmdlets.ProviderHub.Models.ISkuResource])]
5551
[CmdletBinding(DefaultParameterSetName='List', PositionalBinding=$false)]
5652
param(
5753
[Parameter(ParameterSetName='Get', Mandatory)]
@@ -65,6 +61,7 @@ param(
6561
${ProviderNamespace},
6662

6763
[Parameter(ParameterSetName='Get', Mandatory)]
64+
[Parameter(ParameterSetName='GetViaIdentityProviderRegistration', Mandatory)]
6865
[Parameter(ParameterSetName='List', Mandatory)]
6966
[Parameter(ParameterSetName='List1', Mandatory)]
7067
[Parameter(ParameterSetName='List2', Mandatory)]
@@ -75,6 +72,8 @@ param(
7572
${ResourceType},
7673

7774
[Parameter(ParameterSetName='Get', Mandatory)]
75+
[Parameter(ParameterSetName='GetViaIdentityProviderRegistration', Mandatory)]
76+
[Parameter(ParameterSetName='GetViaIdentityResourcetypeRegistration', Mandatory)]
7877
[Microsoft.Azure.PowerShell.Cmdlets.ProviderHub.Category('Path')]
7978
[System.String]
8079
# The SKU.
@@ -95,9 +94,20 @@ param(
9594
[Microsoft.Azure.PowerShell.Cmdlets.ProviderHub.Category('Path')]
9695
[Microsoft.Azure.PowerShell.Cmdlets.ProviderHub.Models.IProviderHubIdentity]
9796
# Identity Parameter
98-
# To construct, see NOTES section for INPUTOBJECT properties and create a hash table.
9997
${InputObject},
10098

99+
[Parameter(ParameterSetName='GetViaIdentityProviderRegistration', Mandatory, ValueFromPipeline)]
100+
[Microsoft.Azure.PowerShell.Cmdlets.ProviderHub.Category('Path')]
101+
[Microsoft.Azure.PowerShell.Cmdlets.ProviderHub.Models.IProviderHubIdentity]
102+
# Identity Parameter
103+
${ProviderRegistrationInputObject},
104+
105+
[Parameter(ParameterSetName='GetViaIdentityResourcetypeRegistration', Mandatory, ValueFromPipeline)]
106+
[Microsoft.Azure.PowerShell.Cmdlets.ProviderHub.Category('Path')]
107+
[Microsoft.Azure.PowerShell.Cmdlets.ProviderHub.Models.IProviderHubIdentity]
108+
# Identity Parameter
109+
${ResourcetypeRegistrationInputObject},
110+
101111
[Parameter(ParameterSetName='List1', Mandatory)]
102112
[Parameter(ParameterSetName='List2', Mandatory)]
103113
[Parameter(ParameterSetName='List3', Mandatory)]
@@ -124,7 +134,8 @@ param(
124134
[ValidateNotNull()]
125135
[Microsoft.Azure.PowerShell.Cmdlets.ProviderHub.Category('Azure')]
126136
[System.Management.Automation.PSObject]
127-
# The credentials, account, tenant, and subscription used for communication with Azure.
137+
# The DefaultProfile parameter is not functional.
138+
# Use the SubscriptionId parameter when available if executing the cmdlet against a different subscription.
128139
${DefaultProfile},
129140

130141
[Parameter(DontShow)]
@@ -174,22 +185,35 @@ begin {
174185
$PSBoundParameters['OutBuffer'] = 1
175186
}
176187
$parameterSet = $PSCmdlet.ParameterSetName
188+
189+
$testPlayback = $false
190+
$PSBoundParameters['HttpPipelinePrepend'] | Foreach-Object { if ($_) { $testPlayback = $testPlayback -or ('Microsoft.Azure.PowerShell.Cmdlets.ProviderHub.Runtime.PipelineMock' -eq $_.Target.GetType().FullName -and 'Playback' -eq $_.Target.Mode) } }
191+
177192
$mapping = @{
178193
Get = 'Az.ProviderHub.private\Get-AzProviderHubSku_Get';
179194
GetViaIdentity = 'Az.ProviderHub.private\Get-AzProviderHubSku_GetViaIdentity';
195+
GetViaIdentityProviderRegistration = 'Az.ProviderHub.private\Get-AzProviderHubSku_GetViaIdentityProviderRegistration';
196+
GetViaIdentityResourcetypeRegistration = 'Az.ProviderHub.private\Get-AzProviderHubSku_GetViaIdentityResourcetypeRegistration';
180197
List = 'Az.ProviderHub.private\Get-AzProviderHubSku_List';
181198
List1 = 'Az.ProviderHub.private\Get-AzProviderHubSku_List1';
182199
List2 = 'Az.ProviderHub.private\Get-AzProviderHubSku_List2';
183200
List3 = 'Az.ProviderHub.private\Get-AzProviderHubSku_List3';
184201
}
185-
if (('Get', 'List', 'List1', 'List2', 'List3') -contains $parameterSet -and -not $PSBoundParameters.ContainsKey('SubscriptionId')) {
186-
$PSBoundParameters['SubscriptionId'] = (Get-AzContext).Subscription.Id
202+
if (('Get', 'List', 'List1', 'List2', 'List3') -contains $parameterSet -and -not $PSBoundParameters.ContainsKey('SubscriptionId') ) {
203+
if ($testPlayback) {
204+
$PSBoundParameters['SubscriptionId'] = . (Join-Path $PSScriptRoot '..' 'utils' 'Get-SubscriptionIdTestSafe.ps1')
205+
} else {
206+
$PSBoundParameters['SubscriptionId'] = (Get-AzContext).Subscription.Id
207+
}
187208
}
188209
if ($PSBoundParameters.ContainsKey('ResourceType')) {
189210
$resourceTypePath = $PSBoundParameters['ResourceType'] -Split "/" -Join "/resourcetyperegistrations/"
190211
$PSBoundParameters['ResourceType'] = $resourceTypePath
191212
}
192213
$wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand(($mapping[$parameterSet]), [System.Management.Automation.CommandTypes]::Cmdlet)
214+
if ($null -eq $wrappedCmd) {
215+
$wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand(($mapping[$parameterSet]), [System.Management.Automation.CommandTypes]::Function)
216+
}
193217
$scriptCmd = {& $wrappedCmd @PSBoundParameters}
194218
$steppablePipeline = $scriptCmd.GetSteppablePipeline($MyInvocation.CommandOrigin)
195219
$steppablePipeline.Begin($PSCmdlet)

0 commit comments

Comments
 (0)