Skip to content

Commit 66a68e0

Browse files
author
Hongzhou You
committed
change allowed origin param to string[]
1 parent 32947b3 commit 66a68e0

File tree

5 files changed

+25
-29
lines changed

5 files changed

+25
-29
lines changed

src/SignalR/SignalR/Cmdlets/NewAzureRmSignalR.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public sealed class NewAzureRmSignalR : SignalRCmdletBase
6363
Mandatory = false,
6464
HelpMessage = "The SignalR service unit count, value only from {1, 2, 5, 10, 20, 50, 100}. Default to 1.")]
6565
[PSArgumentCompleter("1", "2", "5", "10", "20", "50", "100")]
66-
public int? UnitCount { get; set; }
66+
public int UnitCount { get; set; } = DefaultUnitCount;
6767

6868
[Parameter(
6969
Mandatory = false,
@@ -78,8 +78,8 @@ public sealed class NewAzureRmSignalR : SignalRCmdletBase
7878

7979
[Parameter(
8080
Mandatory = false,
81-
HelpMessage = "The allowed origins for the SignalR service, splitted by ',', ';' or ' ' (space). To allow all, use \"*\" and remove all other origins from the list. Slashes are not allowed as part of domain or after TLD")]
82-
public string AllowedOrigin { get; set; }
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 TLD")]
82+
public string[] AllowedOrigin { get; set; }
8383

8484
[Parameter(
8585
Mandatory = false,
@@ -111,15 +111,14 @@ public override void ExecuteCmdlet()
111111
}
112112

113113
PromptParameter(nameof(Sku), Sku, true, DefaultSku);
114-
PromptParameter(nameof(UnitCount), UnitCount, true, DefaultUnitCount);
114+
PromptParameter(nameof(UnitCount), UnitCount);
115115
PromptParameter(nameof(Tag), Tag == null ? null : JsonConvert.SerializeObject(Tag));
116116
PromptParameter(nameof(ServiceMode), ServiceMode);
117117

118-
IList<string> origins = ParseAllowedOrigins(AllowedOrigin);
118+
IList<string> origins = ParseAndCheckAllowedOrigins(AllowedOrigin);
119119
PromptParameter(nameof(AllowedOrigin), origins == null ? null : JsonConvert.SerializeObject(origins));
120120

121121
Sku = Sku ?? DefaultSku;
122-
UnitCount = UnitCount ?? DefaultUnitCount;
123122

124123
IList<SignalRFeature> features = ServiceMode == null ? null : new List<SignalRFeature> { new SignalRFeature(value: ServiceMode) };
125124
SignalRCorsSettings cors = AllowedOrigin == null ? null : new SignalRCorsSettings(allowedOrigins: origins);

src/SignalR/SignalR/Cmdlets/SignalRCmdletBottom.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,25 +90,20 @@ protected void PromptParameter(string name, object value, bool check = false, ob
9090
}
9191
}
9292

93-
protected IList<string> ParseAllowedOrigins(string parameter)
93+
protected IList<string> ParseAndCheckAllowedOrigins(string[] parameter)
9494
{
9595
if (parameter == null)
9696
{
9797
return null;
9898
}
99-
IList<string> origins = parameter.Split(new char[] { ',', ';', ' ' }, StringSplitOptions.RemoveEmptyEntries);
99+
IList<string> origins = parameter.ToList();
100100
Regex regex = new Regex(@"^(http|https)://[^ *\\/""]+$");
101101
foreach (var url in origins)
102102
{
103103
if (url != "*" && !regex.IsMatch(url))
104104
{
105105
string message = $"Invalid origin: \"{url}\"";
106-
ThrowTerminatingError(
107-
new ErrorRecord(
108-
new PSInvalidOperationException(message),
109-
string.Empty,
110-
ErrorCategory.InvalidData,
111-
null));
106+
throw new PSInvalidOperationException(message);
112107
}
113108
}
114109
return origins;

src/SignalR/SignalR/Cmdlets/UpdateAzureRmSignalR.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ public class UpdateAzureRmSignalR : SignalRCmdletBase, IWithInputObject, IWithRe
8888

8989
[Parameter(
9090
Mandatory = false,
91-
HelpMessage = "The allowed origins for the SignalR service, splitted by ',', ';' or ' ' (space). To allow all, use \"*\" and remove all other origins from the list. Slashes are not allowed as part of domain or after TLD")]
92-
public string AllowedOrigin { get; set; }
91+
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 TLD")]
92+
public string[] AllowedOrigin { get; set; }
9393

9494
[Parameter(
9595
Mandatory = false,
@@ -126,7 +126,7 @@ public override void ExecuteCmdlet()
126126
PromptParameter(nameof(Tag), Tag == null ? null : JsonConvert.SerializeObject(Tag));
127127
PromptParameter(nameof(ServiceMode), ServiceMode);
128128

129-
IList<string> origins = ParseAllowedOrigins(AllowedOrigin);
129+
IList<string> origins = ParseAndCheckAllowedOrigins(AllowedOrigin);
130130
PromptParameter(nameof(AllowedOrigin), origins == null ? null : JsonConvert.SerializeObject(origins));
131131

132132
Sku = Sku ?? DefaultSku;

src/SignalR/SignalR/help/New-AzSignalR.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Create a SignalR service.
1515
```
1616
New-AzSignalR [-ResourceGroupName <String>] [-Name] <String> [-Location <String>] [-Sku <String>]
1717
[-UnitCount <Int32>] [-Tag <System.Collections.Generic.IDictionary`2[System.String,System.String]>]
18-
[-ServiceMode <String>] [-AllowedOrigin <String>] [-AsJob] [-DefaultProfile <IAzureContextContainer>]
18+
[-ServiceMode <String>] [-AllowedOrigin <String[]>] [-AsJob] [-DefaultProfile <IAzureContextContainer>]
1919
[-WhatIf] [-Confirm] [<CommonParameters>]
2020
```
2121

@@ -39,7 +39,7 @@ mysignalr1.service.signalr.net eastus 52.179.3.5 Standard
3939

4040
### Specify ServiceMode and AllowedOrigin
4141
```powershell
42-
PS C:\> New-AzSignalR -ResourceGroupName myResourceGroup1 -Name mysignalr2 -Location eastus -ServiceMode Serverless -AllowedOrigin "http://example1.com:12345, http://example2.com"
42+
PS C:\> New-AzSignalR -ResourceGroupName myResourceGroup1 -Name mysignalr2 -Location eastus -ServiceMode Serverless -AllowedOrigin http://example1.com:12345, https://example2.cn
4343
4444
HostName Location ExternalIp Sku UnitCount ProvisioningState Version
4545
-------- -------- ---------- --- --------- ----------------- -------
@@ -49,10 +49,10 @@ mysignalr1.service.signalr.net eastus 52.179.3.5 Standard
4949
## PARAMETERS
5050

5151
### -AllowedOrigin
52-
The allowed origins for the SignalR service, splitted by ',', ';' or ' ' (space). To allow all, use "*" and remove all other origins from the list. Slashes are not allowed as part of domain or after TLD
52+
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 TLD
5353

5454
```yaml
55-
Type: System.String
55+
Type: System.String[]
5656
Parameter Sets: (All)
5757
Aliases:
5858

@@ -187,7 +187,7 @@ Accept wildcard characters: False
187187
The SignalR service unit count, from 1 to 10. Default to 1.
188188
189189
```yaml
190-
Type: System.Nullable`1[System.Int32]
190+
Type: System.Int32
191191
Parameter Sets: (All)
192192
Aliases:
193193

@@ -234,10 +234,12 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable
234234
235235
## INPUTS
236236
237-
### None
237+
### System.String
238+
238239
## OUTPUTS
239240
240241
### Microsoft.Azure.Commands.SignalR.Models.PSSignalRResource
242+
241243
## NOTES
242244
243245
## RELATED LINKS

src/SignalR/SignalR/help/Update-AzSignalR.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,23 @@ Update a SignalR service.
1616
```
1717
Update-AzSignalR [-ResourceGroupName <String>] [-Name] <String> [-Sku <String>] [-UnitCount <Int32>]
1818
[-Tag <System.Collections.Generic.IDictionary`2[System.String,System.String]>] [-ServiceMode <String>]
19-
[-AllowedOrigin <String>] [-AsJob] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
19+
[-AllowedOrigin <String[]>] [-AsJob] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
2020
[<CommonParameters>]
2121
```
2222

2323
### ResourceIdParameterSet
2424
```
2525
Update-AzSignalR -ResourceId <String> [-Sku <String>] [-UnitCount <Int32>]
2626
[-Tag <System.Collections.Generic.IDictionary`2[System.String,System.String]>] [-ServiceMode <String>]
27-
[-AllowedOrigin <String>] [-AsJob] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
27+
[-AllowedOrigin <String[]>] [-AsJob] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
2828
[<CommonParameters>]
2929
```
3030

3131
### InputObjectParameterSet
3232
```
3333
Update-AzSignalR -InputObject <PSSignalRResource> [-Sku <String>] [-UnitCount <Int32>]
3434
[-Tag <System.Collections.Generic.IDictionary`2[System.String,System.String]>] [-ServiceMode <String>]
35-
[-AllowedOrigin <String>] [-AsJob] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
35+
[-AllowedOrigin <String[]>] [-AsJob] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
3636
[<CommonParameters>]
3737
```
3838

@@ -55,7 +55,7 @@ mysignalr1.service.signalr.net eastus 52.179.3.5 Standard
5555

5656
### Specify ServiceMode and AllowedOrigin
5757
```powershell
58-
PS C:\> Update-AzSignalR -ResourceGroupName myResourceGroup1 -Name mysignalr2 -ServiceMode Serverless -AllowedOrigin "http://example1.com:12345, http://example2.com"
58+
PS C:\> Update-AzSignalR -ResourceGroupName myResourceGroup1 -Name mysignalr2 -ServiceMode Serverless -AllowedOrigin http://example1.com:12345, https://example2.cn
5959
6060
HostName Location ExternalIp Sku UnitCount ProvisioningState Version
6161
-------- -------- ---------- --- --------- ----------------- -------
@@ -65,10 +65,10 @@ mysignalr1.service.signalr.net eastus 52.179.3.5 Standard
6565
## PARAMETERS
6666

6767
### -AllowedOrigin
68-
The allowed origins for the SignalR service, splitted by ',', ';' or ' ' (space). To allow all, use "*" and remove all other origins from the list. Slashes are not allowed as part of domain or after TLD
68+
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 TLD
6969

7070
```yaml
71-
Type: System.String
71+
Type: System.String[]
7272
Parameter Sets: (All)
7373
Aliases:
7474

0 commit comments

Comments
 (0)