Skip to content

Commit 2d66db5

Browse files
authored
Merge pull request Azure#9866 from Tashi711/master
Update SignalR Cmdlets
2 parents 01a81fb + 97e87e2 commit 2d66db5

30 files changed

+4032
-2351
lines changed

src/SignalR/SignalR.Test/ScenarioTests/AzureRmSignalRTests.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ function Test-AzureRmSignalRWithDefaultArgs {
103103
$location = Get-ProviderLocation "Microsoft.SignalRService/SignalR"
104104

105105
try {
106+
New-AzResourceGroup -Name $resourceGroupName -Location $location
107+
106108
# New without SignalR resource group, use the SignalR instance name as the resource group
107109
$signalr = New-AzSignalR -Name $resourceGroupName
108110
Verify-SignalR $signalr $resourceGroupName $location "Standard_S1" 1

src/SignalR/SignalR.Test/SessionRecords/Microsoft.Azure.Commands.SignalR.Test.ScenarioTests.AzureRmSignalRTests/TestAzureRmSignalR.json

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

src/SignalR/SignalR.Test/SessionRecords/Microsoft.Azure.Commands.SignalR.Test.ScenarioTests.AzureRmSignalRTests/TestAzureRmSignalRWithDefaultArgs.json

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

src/SignalR/SignalR.Test/SignalR.Test.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<PsModuleName>SignalR</PsModuleName>
@@ -11,7 +11,7 @@
1111
</PropertyGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="Microsoft.Azure.Management.SignalR" Version="0.11.0-preview" />
14+
<PackageReference Include="Microsoft.Azure.Management.SignalR" Version="1.0.1" />
1515
</ItemGroup>
1616

1717
</Project>

src/SignalR/SignalR/Az.SignalR.psd1

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,15 @@ NestedModules = @('.\Microsoft.Azure.PowerShell.Cmdlets.SignalR.dll')
7474
FunctionsToExport = @()
7575

7676
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
77-
CmdletsToExport = 'New-AzSignalR', 'Get-AzSignalR', 'Get-AzSignalRKey',
78-
'New-AzSignalRKey', 'Remove-AzSignalR'
77+
CmdletsToExport = 'New-AzSignalR', 'Get-AzSignalR', 'Get-AzSignalRKey',
78+
'New-AzSignalRKey', 'Remove-AzSignalR', 'Update-AzSignalR',
79+
'Test-AzSignalRName', 'Restart-AzSignalR', 'Get-AzSignalRUsage'
7980

8081
# Variables to export from this module
8182
# VariablesToExport = @()
8283

8384
# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
84-
AliasesToExport = @()
85+
AliasesToExport = 'Test-AzSignalR'
8586

8687
# DSC resources to export from this module
8788
# DscResourcesToExport = @()

src/SignalR/SignalR/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- Additional information about change #1
1919
-->
2020
## Upcoming Release
21+
* Add Update, Restart, CheckNameAvailability, GetUsage Cmdlets
2122

2223
## Version 1.0.3
2324
* Fixed miscellaneous typos across module
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System.Management.Automation;
16+
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
17+
using Microsoft.Azure.Commands.SignalR.Models;
18+
using Microsoft.Azure.Management.SignalR;
19+
20+
namespace Microsoft.Azure.Commands.SignalR.Cmdlets
21+
{
22+
[Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "SignalRUsage")]
23+
[OutputType(typeof(PSSignalRUsage))]
24+
public class GetAzureRmSignalRUsage : SignalRCmdletBottom
25+
{
26+
[Parameter(
27+
Mandatory = true,
28+
Position = 0,
29+
HelpMessage = "The SignalR service location.")]
30+
[LocationCompleter("Microsoft.SignalR/SignalR")]
31+
[ValidateNotNullOrEmpty()]
32+
public string Location { get; set; }
33+
34+
public override void ExecuteCmdlet()
35+
{
36+
base.ExecuteCmdlet();
37+
38+
RunCmdlet(() =>
39+
{
40+
var usages = Client.Usages.List(Location);
41+
foreach (var usage in usages)
42+
{
43+
WriteObject(new PSSignalRUsage(usage));
44+
}
45+
});
46+
}
47+
}
48+
}

src/SignalR/SignalR/Cmdlets/NewAzureRmSignalR.cs

Lines changed: 67 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,17 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using System.Collections;
16+
using System.Collections.Generic;
17+
using System.Management.Automation;
1518
using Microsoft.Azure.Commands.Common.Strategies;
1619
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
1720
using Microsoft.Azure.Commands.SignalR.Models;
18-
using Microsoft.Azure.Commands.SignalR.Strategies;
21+
using Microsoft.Azure.Management.Internal.Resources;
22+
using Microsoft.Azure.Management.SignalR;
1923
using Microsoft.Azure.Management.SignalR.Models;
20-
using System.Collections.Generic;
21-
using System.Management.Automation;
22-
using System.Threading.Tasks;
23-
using Microsoft.Azure.Commands.SignalR.Strategies.ResourceManager;
24-
using Microsoft.Azure.Commands.SignalR.Strategies.SignalRRp;
24+
using Microsoft.WindowsAzure.Commands.Common;
25+
using Newtonsoft.Json;
2526

2627
namespace Microsoft.Azure.Commands.SignalR.Cmdlets
2728
{
@@ -30,6 +31,7 @@ namespace Microsoft.Azure.Commands.SignalR.Cmdlets
3031
public sealed class NewAzureRmSignalR : SignalRCmdletBase
3132
{
3233
private const string DefaultSku = "Standard_S1";
34+
private const int DefaultUnitCount = 1;
3335

3436
[Parameter(
3537
Mandatory = false,
@@ -53,88 +55,86 @@ public sealed class NewAzureRmSignalR : SignalRCmdletBase
5355

5456
[Parameter(
5557
Mandatory = false,
56-
HelpMessage = "The SignalR service SKU.")]
58+
HelpMessage = "The SignalR service SKU. Default to \"Standard_S1\".")]
5759
[PSArgumentCompleter("Free_F1", "Standard_S1")]
58-
public string Sku { get; set; } = DefaultSku;
60+
public string Sku { get; set; }
5961

6062
[Parameter(
6163
Mandatory = false,
62-
HelpMessage = "The SignalR service unit count, from 1 to 10. Default to 1.")]
63-
[PSArgumentCompleter("1", "2", "3", "4", "5", "6", "7", "8", "9", "10")]
64-
[ValidateRange(1, 10)]
65-
public int UnitCount { get; set; } = 1;
64+
HelpMessage = "The SignalR service unit count, value only from {1, 2, 5, 10, 20, 50, 100}. Default to 1.")]
65+
[PSArgumentCompleter("1", "2", "5", "10", "20", "50", "100")]
66+
public int UnitCount { get; set; } = DefaultUnitCount;
6667

6768
[Parameter(
6869
Mandatory = false,
6970
HelpMessage = "The tags for the SignalR service.")]
7071
public IDictionary<string, string> Tag { get; set; }
7172

73+
[Parameter(
74+
Mandatory = false,
75+
HelpMessage = "The service mode for the SignalR service.")]
76+
[PSArgumentCompleter("Default", "Serverless", "Classic")]
77+
public string ServiceMode { get; set; }
78+
79+
[Parameter(
80+
Mandatory = false,
81+
HelpMessage = "The allowed origins for the SignalR service. To allow all, use \"*\" and remove all other origins from the list. Slashes are not allowed as part of domain or after top-level domain")]
82+
public string[] AllowedOrigin { get; set; }
83+
7284
[Parameter(
7385
Mandatory = false,
7486
HelpMessage = "Run the cmdlet in background job.")]
7587
public SwitchParameter AsJob { get; set; }
7688

7789
public override void ExecuteCmdlet()
78-
=> this.StartAndWait(SimpleExecuteCmdlet);
79-
80-
sealed class Parameters : IParameters<SignalRResource>
8190
{
82-
public string Location
91+
base.ExecuteCmdlet();
92+
93+
RunCmdlet(() =>
8394
{
84-
get
85-
{
86-
return _cmdlet.Location;
87-
}
95+
ResolveResourceGroupName(required: false);
96+
ResourceGroupName = ResourceGroupName ?? Name;
8897

89-
set
98+
if (ShouldProcess($"SignalR service {ResourceGroupName}/{Name}", "new"))
9099
{
91-
_cmdlet.Location = value;
100+
PromptParameter(nameof(ResourceGroupName), ResourceGroupName);
101+
PromptParameter(nameof(Name), Name);
102+
103+
if (Location == null)
104+
{
105+
Location = GetLocationFromResourceGroup();
106+
PromptParameter(nameof(Location), null, true, Location, "(from resource group location)");
107+
}
108+
else
109+
{
110+
PromptParameter(nameof(Location), Location);
111+
}
112+
113+
PromptParameter(nameof(Sku), Sku, true, DefaultSku);
114+
PromptParameter(nameof(UnitCount), UnitCount);
115+
PromptParameter(nameof(Tag), Tag == null ? null : JsonConvert.SerializeObject(Tag));
116+
PromptParameter(nameof(ServiceMode), ServiceMode);
117+
118+
IList<string> origins = ParseAndCheckAllowedOrigins(AllowedOrigin);
119+
PromptParameter(nameof(AllowedOrigin), origins == null ? null : JsonConvert.SerializeObject(origins));
120+
121+
Sku = Sku ?? DefaultSku;
122+
123+
IList<SignalRFeature> features = ServiceMode == null ? null : new List<SignalRFeature> { new SignalRFeature(value: ServiceMode) };
124+
SignalRCorsSettings cors = AllowedOrigin == null ? null : new SignalRCorsSettings(allowedOrigins: origins);
125+
126+
var parameters = new SignalRCreateParameters(
127+
location: Location,
128+
tags: Tag,
129+
sku: new ResourceSku(name: Sku, capacity: UnitCount),
130+
properties: new SignalRCreateOrUpdateProperties(features: features, cors: cors));
131+
132+
Client.SignalR.CreateOrUpdate(ResourceGroupName, Name, parameters);
133+
134+
var signalr = Client.SignalR.Get(ResourceGroupName, Name);
135+
WriteObject(new PSSignalRResource(signalr));
92136
}
93-
}
94-
95-
public string DefaultLocation => "eastus";
96-
97-
readonly NewAzureRmSignalR _cmdlet;
98-
99-
public Parameters(NewAzureRmSignalR cmdlet)
100-
{
101-
_cmdlet = cmdlet;
102-
}
103-
104-
public Task<ResourceConfig<SignalRResource>> CreateConfigAsync()
105-
{
106-
_cmdlet.ResolveResourceGroupName(required: false);
107-
_cmdlet.ResourceGroupName = _cmdlet.ResourceGroupName ?? _cmdlet.Name;
108-
109-
var resourceGroup = ResourceGroupStrategy.CreateResourceGroupConfig(
110-
_cmdlet.ResourceGroupName);
111-
112-
var result = SignalRStrategy.Strategy.CreateResourceConfig(
113-
resourceGroup: resourceGroup,
114-
name: _cmdlet.Name,
115-
createModel: engine => new SignalRResource(
116-
tags: _cmdlet.Tag,
117-
sku: new ResourceSku(_cmdlet.Sku, capacity: _cmdlet.UnitCount),
118-
hostNamePrefix: null /* _cmdlet.Name*/)); // hostNamePrefix is just a placeholder and ignored in the resource provider.
119-
120-
return Task.FromResult(result);
121-
}
122-
}
123-
124-
async Task SimpleExecuteCmdlet(IAsyncCmdlet asyncCmdlet)
125-
{
126-
var client = new Client(DefaultProfile.DefaultContext);
127-
128-
var parameters = new Parameters(this);
129-
130-
var result = await client.RunAsync(
131-
client.SubscriptionId, parameters, asyncCmdlet);
132-
133-
if (result != null)
134-
{
135-
var psResult = new PSSignalRResource(result);
136-
asyncCmdlet.WriteObject(psResult);
137-
}
137+
});
138138
}
139139
}
140140
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System;
16+
using System.Management.Automation;
17+
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
18+
using Microsoft.Azure.Commands.SignalR.Models;
19+
using Microsoft.Azure.Commands.SignalR.Properties;
20+
using Microsoft.Azure.Management.SignalR;
21+
22+
namespace Microsoft.Azure.Commands.SignalR.Cmdlets
23+
{
24+
[Cmdlet("Restart", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "SignalR", SupportsShouldProcess = true, DefaultParameterSetName = ResourceGroupParameterSet)]
25+
[OutputType(typeof(bool))]
26+
public class RestartAzureRmSignalR : SignalRCmdletBase, IWithInputObject, IWithResourceId
27+
{
28+
[Parameter(
29+
Mandatory = false,
30+
ParameterSetName = ResourceGroupParameterSet,
31+
HelpMessage = "The resource group name. The default one will be used if not specified.")]
32+
[ResourceGroupCompleter()]
33+
[ValidateNotNullOrEmpty()]
34+
public override string ResourceGroupName { get; set; }
35+
36+
[Parameter(
37+
Mandatory = true,
38+
Position = 0,
39+
ParameterSetName = ResourceGroupParameterSet,
40+
HelpMessage = "The SignalR service name.")]
41+
[ValidateNotNullOrEmpty()]
42+
public string Name { get; set; }
43+
44+
[Parameter(
45+
Mandatory = true,
46+
ParameterSetName = ResourceIdParameterSet,
47+
ValueFromPipelineByPropertyName = true,
48+
HelpMessage = "The SignalR service resource ID.")]
49+
[ValidateNotNullOrEmpty]
50+
public string ResourceId { get; set; }
51+
52+
[Parameter(
53+
Mandatory = true,
54+
ParameterSetName = InputObjectParameterSet,
55+
ValueFromPipeline = true,
56+
HelpMessage = "The SignalR resource object.")]
57+
[ValidateNotNull]
58+
public PSSignalRResource InputObject { get; set; }
59+
60+
[Parameter(
61+
Mandatory = false,
62+
HelpMessage = "Run the cmdlet in background job.")]
63+
public SwitchParameter AsJob { get; set; }
64+
65+
[Parameter(Mandatory = false)]
66+
public SwitchParameter PassThru { get; set; }
67+
68+
public override void ExecuteCmdlet()
69+
{
70+
base.ExecuteCmdlet();
71+
72+
RunCmdlet(() =>
73+
{
74+
switch (ParameterSetName)
75+
{
76+
case ResourceGroupParameterSet:
77+
ResolveResourceGroupName();
78+
break;
79+
case ResourceIdParameterSet:
80+
this.LoadFromResourceId();
81+
break;
82+
case InputObjectParameterSet:
83+
this.LoadFromInputObject();
84+
break;
85+
default:
86+
throw new ArgumentException(Resources.ParameterSetError);
87+
}
88+
89+
if (ShouldProcess($"SignalR service {ResourceGroupName}/{Name}", "restart"))
90+
{
91+
PromptParameter(nameof(ResourceGroupName), ResourceGroupName);
92+
PromptParameter(nameof(Name), Name);
93+
94+
Client.SignalR.Restart(ResourceGroupName, Name);
95+
96+
if (PassThru)
97+
{
98+
WriteObject(true);
99+
}
100+
}
101+
});
102+
}
103+
}
104+
}

0 commit comments

Comments
 (0)