Skip to content
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

Migrate SignalR from generation to main #20230

Merged
merged 5 commits into from
Nov 29, 2022
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
  •  
  •  
  •  
460 changes: 360 additions & 100 deletions src/SignalR/SignalR.Autorest/Az.SignalR.format.ps1xml

Large diffs are not rendered by default.

14 changes: 9 additions & 5 deletions src/SignalR/SignalR.Autorest/Az.SignalR.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@
}
}
if(-not $accountsModule) {
$hasAdequateVersion = (Get-Module -Name $accountsName -ListAvailable | Where-Object { $_.Version -ge [System.Version]'2.2.3' } | Measure-Object).Count -gt 0
$hasAdequateVersion = (Get-Module -Name $accountsName -ListAvailable | Where-Object { $_.Version -ge [System.Version]'2.7.5' } | Measure-Object).Count -gt 0
if($hasAdequateVersion) {
$accountsModule = Import-Module -Name $accountsName -MinimumVersion 2.2.3 -Scope Global -PassThru
$accountsModule = Import-Module -Name $accountsName -MinimumVersion 2.7.5 -Scope Global -PassThru
}
}
}

if(-not $accountsModule) {
Write-Error "`nThis module requires $accountsName version 2.2.3 or greater. For installation instructions, please see: https://docs.microsoft.com/powershell/azure/install-az-ps" -ErrorAction Stop
} elseif (($accountsModule.Version -lt [System.Version]'2.2.3') -and (-not $localAccounts)) {
Write-Error "`nThis module requires $accountsName version 2.2.3 or greater. An earlier version of Az.Accounts is imported in the current PowerShell session. If you are running test, please try to add the switch '-RegenerateSupportModule' when executing 'test-module.ps1'. Otherwise please open a new PowerShell session and import this module again.`nAdditionally, this error could indicate that multiple incompatible versions of Azure PowerShell modules are installed on your system. For troubleshooting information, please see: https://aka.ms/azps-version-error" -ErrorAction Stop
Write-Error "`nThis module requires $accountsName version 2.7.5 or greater. For installation instructions, please see: https://docs.microsoft.com/powershell/azure/install-az-ps" -ErrorAction Stop
} elseif (($accountsModule.Version -lt [System.Version]'2.7.5') -and (-not $localAccounts)) {
Write-Error "`nThis module requires $accountsName version 2.7.5 or greater. An earlier version of Az.Accounts is imported in the current PowerShell session. If you are running test, please try to add the switch '-RegenerateSupportModule' when executing 'test-module.ps1'. Otherwise please open a new PowerShell session and import this module again.`nAdditionally, this error could indicate that multiple incompatible versions of Azure PowerShell modules are installed on your system. For troubleshooting information, please see: https://aka.ms/azps-version-error" -ErrorAction Stop
}
Write-Information "Loaded Module '$($accountsModule.Name)'"

Expand All @@ -50,6 +50,10 @@

# Tweaks the pipeline on module load
$instance.OnModuleLoad = $VTable.OnModuleLoad

# Following two delegates are added for telemetry
$instance.GetTelemetryId = $VTable.GetTelemetryId
$instance.Telemetry = $VTable.Telemetry


# Tweaks the pipeline per call
Expand Down
28 changes: 28 additions & 0 deletions src/SignalR/SignalR.Autorest/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using System;
using System.Reflection;
using System.Runtime.InteropServices;

[assembly: AssemblyTitle("Microsoft Azure Powershell - SignalR")]
[assembly: AssemblyCompany(Microsoft.WindowsAzure.Commands.Common.AzurePowerShell.AssemblyCompany)]
[assembly: AssemblyProduct(Microsoft.WindowsAzure.Commands.Common.AzurePowerShell.AssemblyProduct)]
[assembly: AssemblyCopyright(Microsoft.WindowsAzure.Commands.Common.AzurePowerShell.AssemblyCopyright)]

[assembly: ComVisible(false)]
[assembly: CLSCompliant(false)]
[assembly: Guid("d62fc115-2d5e-4d8c-8093-a52013cd999e")]
[assembly: AssemblyVersion("0.1.0")]
[assembly: AssemblyFileVersion("0.1.0")]
82 changes: 68 additions & 14 deletions src/SignalR/SignalR.Autorest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ This directory contains the PowerShell module for the WebPubSub service.
This module was primarily generated via [AutoRest](https://github.com/Azure/autorest) using the [PowerShell](https://github.com/Azure/autorest.powershell) extension.

## Module Requirements
- [Az.Accounts module](https://www.powershellgallery.com/packages/Az.Accounts/), version 2.2.3 or greater
- [Az.Accounts module](https://www.powershellgallery.com/packages/Az.Accounts/), version 2.7.5 or greater

## Authentication
AutoRest does not generate authentication code for the module. Authentication is handled via Az.Accounts by altering the HTTP payload before it is sent.
Expand All @@ -36,7 +36,7 @@ require:
sanitize-names: true
input-file:
# You need to specify your swagger files here.
- $(repo)/specification/webpubsub/resource-manager/Microsoft.SignalRService/stable/2021-10-01/webpubsub.json
- $(repo)/specification/webpubsub/resource-manager/Microsoft.SignalRService/preview/2022-08-01-preview/webpubsub.json
# If the swagger has not been put in the repo, you may uncomment the following line and refer to it locally
# - (this-folder)/relative-path-to-your-swagger

Expand All @@ -49,7 +49,8 @@ psm1-custom: custom/Az.SignalR.custom.psm1
# Normally, title is the service name
title: WebPubSub
subject-prefix: ''
branch: ab0c850713dcb87f906e8f38f73d43099668a60f
# When updating the commit hash, please update all occurrences in the file
branch: 492cf91751be945ceae53cfdd53b1ff2fb878703

# If there are post APIs for some kinds of actions in the RP, you may need to
# uncomment following line to support viaIdentity for these post APIs
Expand Down Expand Up @@ -97,6 +98,11 @@ directive:
variant: ^Check$|^CheckViaIdentity$|^CheckViaIdentityExpanded$
subject: WebPubSubNameAvailability
remove: true
# Get the custom domain after 'new' complete
- where:
verb: New
subject: WebPubSubCustomDomain
hide: true
# Hide parameters
- where:
verb: Update
Expand Down Expand Up @@ -129,7 +135,7 @@ directive:
"default": {
"description": "Error response describing why the operation failed.",
"schema": {
"$ref": "https://github.com/Azure/azure-rest-api-specs/blob/ab0c850713dcb87f906e8f38f73d43099668a60f/specification/common-types/resource-management/v2/types.json#/definitions/ErrorResponse"
"$ref": "https://github.com/Azure/azure-rest-api-specs/blob/492cf91751be945ceae53cfdd53b1ff2fb878703/specification/common-types/resource-management/v2/types.json#/definitions/ErrorResponse"
}
}
}
Expand All @@ -149,7 +155,27 @@ directive:
"default": {
"description": "Error response describing why the operation failed.",
"schema": {
"$ref": "https://github.com/Azure/azure-rest-api-specs/blob/ab0c850713dcb87f906e8f38f73d43099668a60f/specification/common-types/resource-management/v2/types.json#/definitions/ErrorResponse"
"$ref": "https://github.com/Azure/azure-rest-api-specs/blob/492cf91751be945ceae53cfdd53b1ff2fb878703/specification/common-types/resource-management/v2/types.json#/definitions/ErrorResponse"
}
}
}
- from: swagger-document
where: $.paths["/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.SignalRService/webPubSub/{resourceName}/customDomains/{name}"].put.responses
transform: >-
return {
"201": {
"description": "Created. The response describes the custom domain and contains a Location header to query the operation result.",
"schema": {
"$ref": "#/definitions/CustomDomain"
}
},
"200": {
"description": "The async operation to restart is finished.",
},
"default": {
"description": "Error response describing why the operation failed.",
"schema": {
"$ref": "https://github.com/Azure/azure-rest-api-specs/blob/492cf91751be945ceae53cfdd53b1ff2fb878703/specification/common-types/resource-management/v2/types.json#/definitions/ErrorResponse"
}
}
}
Expand All @@ -162,10 +188,6 @@ directive:
where: $.definitions.EventHandler.properties.systemEvents.description
transform: >-
return "Gets ot sets the list of system events. Valid values contain: 'connect', 'connected', 'disconnected'."
- from: swagger-document
where: $.definitions.RegenerateKeyParameters.properties.keyType.description
transform: >-
return "Must be either 'primary', 'secondary' or 'salt'(case-insensitive)."
# format output
- where:
model-name: WebPubSubResource
Expand Down Expand Up @@ -212,6 +234,24 @@ directive:
- CapacityMinimum
- CapacityMaximum
- CapacityScaleType
- where:
model-name: CustomCertificate
set:
format-table:
properties:
- Name
- KeyVaultBaseUri
- KeyVaultSecretName
- KeyVaultSecretVersion
- ProvisioningState
- where:
model-name: CustomDomain
set:
format-table:
properties:
- Name
- DomainName
- ProvisioningState
# rename parameters
- where:
parameter-name: IdentityUserAssignedIdentity
Expand Down Expand Up @@ -269,20 +309,34 @@ directive:
set:
property-name: ResourceLogCategory
# remove the subject before the 'Name' when multiple *Name parameter exist
- where:
subject: WebPubSubEventHandler
parameter-name: EventHandlerName
set:
parameter-name: Name
- where:
subject: WebPubSubHub
parameter-name: HubName
set:
parameter-name: Name
alias: HubName
- where:
subject: WebPubSub
parameter-name: ResourceName
set:
parameter-name: Name
alias: ResourceName
- where:
subject: WebPubSubCustomCertificate
parameter-name: CertificateName
set:
parameter-name: Name
alias: CertificateName
# Disable Inline on the Baseclass(Model).
- no-inline:
- EventListenerEndpoint
- EventListenerFilter
```

## Azure Web PubSub custom development guidance

This chapter contains development guidance specific to Azure Web PubSub service.

### Generate error handling customization code

The default error handling logic only prints the message field of the `ErrorResponse`. However, it's usually not enough for our services where we have to combine the `target` and `message` fields to figure out how to fix the error. Therefore, we should run the script "resources\GenerateCustomErrorHandling.ps1" to generate error handling customization code for each cmdlets. If you have written other csharp customization logic, take care because the script overrides the current files.
4 changes: 2 additions & 2 deletions src/SignalR/SignalR.Autorest/check-dependencies.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ if(-not $Isolated) {
function DownloadModule ([bool]$predicate, [string]$path, [string]$moduleName, [string]$versionMinimum, [string]$requiredVersion) {
if($predicate) {
$module = Get-Module -ListAvailable -Name $moduleName
if((-not $module) -or ($versionMinimum -and ($module | ForEach-Object { $_.Version } | Where-Object { $_ -ge [System.Version]$versionMinimum } | Measure-Object).Count -eq 0)) {
if((-not $module) -or ($versionMinimum -and ($module | ForEach-Object { $_.Version } | Where-Object { $_ -ge [System.Version]$versionMinimum } | Measure-Object).Count -eq 0) -or ($requiredVersion -and ($module | ForEach-Object { $_.Version } | Where-Object { $_ -eq [System.Version]$requiredVersion } | Measure-Object).Count -eq 0)) {
$null = New-Item -ItemType Directory -Force -Path $path
Write-Host -ForegroundColor Green "Installing local $moduleName module into '$path'..."
if ($requiredVersion) {
Expand All @@ -47,7 +47,7 @@ if(Test-Path -Path $localModulesPath) {
$env:PSModulePath = "$localModulesPath$([IO.Path]::PathSeparator)$env:PSModulePath"
}

DownloadModule -predicate ($all -or $Accounts) -path $localModulesPath -moduleName 'Az.Accounts' -versionMinimum '2.2.3'
DownloadModule -predicate ($all -or $Accounts) -path $localModulesPath -moduleName 'Az.Accounts' -versionMinimum '2.7.5'
DownloadModule -predicate ($all -or $Pester) -path $localModulesPath -moduleName 'Pester' -requiredVersion '4.10.1'

$tools = Join-Path $PSScriptRoot 'tools'
Expand Down
8 changes: 5 additions & 3 deletions src/SignalR/SignalR.Autorest/create-model-cmdlets.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function CreateModelCmdlet {
}

$ModelCsPath = Join-Path (Join-Path $PSScriptRoot 'generated\api') 'Models'
$ModuleName = 'Az.SignalR'.Split(".")[1]
$ModuleName = ''
$OutputDir = Join-Path $PSScriptRoot 'custom\autogen-model-cmdlets'
$null = New-Item -ItemType Directory -Force -Path $OutputDir

Expand Down Expand Up @@ -115,7 +115,9 @@ function CreateModelCmdlet {
# check whether completer is needed
$completer = '';
if($Type.Split('.').Split('.')[-2] -eq 'Support') {
$completer += "`n [ArgumentCompleter([${Type}])]"
# If Type is an array, need to strip []
$strippedType = $Type.Replace('[]', '')
$completer += "`n [ArgumentCompleter([${strippedType}])]"
}
$ParameterDefineScript = "
[Parameter($ParameterDefineProperty)]${completer}
Expand Down Expand Up @@ -156,7 +158,7 @@ Create an in-memory object for ${ObjectType}.
.Outputs
${ObjectTypeWithNamespace}
.Link
https://docs.microsoft.com/powershell/module/az.${ModuleName}/new-Az${ModulePrefix}${ObjectType}Object
https://learn.microsoft.com/powershell/module/az.${ModuleName}/new-Az${ModulePrefix}${ObjectType}Object
#>
function New-Az${ModulePrefix}${ObjectType}Object {
[OutputType('${ObjectTypeWithNamespace}')]
Expand Down
17 changes: 17 additions & 0 deletions src/SignalR/SignalR.Autorest/custom/csharp/GetAzOperation_List.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.Azure.PowerShell.Cmdlets.WebPubSub.Models.Api20;

namespace Microsoft.Azure.PowerShell.Cmdlets.WebPubSub.Cmdlets
{
public partial class GetAzOperation_List
{
partial void overrideOnDefault(HttpResponseMessage responseMessage, Task<IErrorResponse> errorResponseTask, ref Task<bool> returnNow)
{
this.WriteError(responseMessage, errorResponseTask, ref returnNow);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.Azure.PowerShell.Cmdlets.WebPubSub.Models.Api20;

namespace Microsoft.Azure.PowerShell.Cmdlets.WebPubSub.Cmdlets
{
public partial class GetAzWebPubSubCustomCertificate_Get
{
partial void overrideOnDefault(HttpResponseMessage responseMessage, Task<IErrorResponse> errorResponseTask, ref Task<bool> returnNow)
{
this.WriteError(responseMessage, errorResponseTask, ref returnNow);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.Azure.PowerShell.Cmdlets.WebPubSub.Models.Api20;

namespace Microsoft.Azure.PowerShell.Cmdlets.WebPubSub.Cmdlets
{
public partial class GetAzWebPubSubCustomCertificate_GetViaIdentity
{
partial void overrideOnDefault(HttpResponseMessage responseMessage, Task<IErrorResponse> errorResponseTask, ref Task<bool> returnNow)
{
this.WriteError(responseMessage, errorResponseTask, ref returnNow);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.Azure.PowerShell.Cmdlets.WebPubSub.Models.Api20;

namespace Microsoft.Azure.PowerShell.Cmdlets.WebPubSub.Cmdlets
{
public partial class GetAzWebPubSubCustomCertificate_List
{
partial void overrideOnDefault(HttpResponseMessage responseMessage, Task<IErrorResponse> errorResponseTask, ref Task<bool> returnNow)
{
this.WriteError(responseMessage, errorResponseTask, ref returnNow);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.Azure.PowerShell.Cmdlets.WebPubSub.Models.Api20;

namespace Microsoft.Azure.PowerShell.Cmdlets.WebPubSub.Cmdlets
{
public partial class GetAzWebPubSubCustomDomain_Get
{
partial void overrideOnDefault(HttpResponseMessage responseMessage, Task<IErrorResponse> errorResponseTask, ref Task<bool> returnNow)
{
this.WriteError(responseMessage, errorResponseTask, ref returnNow);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.Azure.PowerShell.Cmdlets.WebPubSub.Models.Api20;

namespace Microsoft.Azure.PowerShell.Cmdlets.WebPubSub.Cmdlets
{
public partial class GetAzWebPubSubCustomDomain_GetViaIdentity
{
partial void overrideOnDefault(HttpResponseMessage responseMessage, Task<IErrorResponse> errorResponseTask, ref Task<bool> returnNow)
{
this.WriteError(responseMessage, errorResponseTask, ref returnNow);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.Azure.PowerShell.Cmdlets.WebPubSub.Models.Api20;

namespace Microsoft.Azure.PowerShell.Cmdlets.WebPubSub.Cmdlets
{
public partial class GetAzWebPubSubCustomDomain_List
{
partial void overrideOnDefault(HttpResponseMessage responseMessage, Task<IErrorResponse> errorResponseTask, ref Task<bool> returnNow)
{
this.WriteError(responseMessage, errorResponseTask, ref returnNow);
}
}
}
Loading