Skip to content

Commit 0c9a550

Browse files
authored
Add AllowAll to New-AzMySqlFirewallRule (#12638)
Fix issue: #11932
1 parent 6972661 commit 0c9a550

File tree

7 files changed

+542
-221
lines changed

7 files changed

+542
-221
lines changed

src/MySql/custom/New-AzMySqlFirewallRule.ps1

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ function New-AzMySqlFirewallRule {
2323
[OutputType([Microsoft.Azure.PowerShell.Cmdlets.MySql.Models.Api20171201.IFirewallRule])]
2424
[CmdletBinding(DefaultParameterSetName='CreateExpanded', PositionalBinding=$false, SupportsShouldProcess, ConfirmImpact='Medium')]
2525
param(
26-
[Parameter(Mandatory)]
26+
[Parameter()]
2727
[Alias('FirewallRuleName')]
2828
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Path')]
2929
[System.String]
3030
# The name of the server firewall rule.
31+
# If not specified, the default is undefined.
32+
# If AllowAll is present, the default name is AllowAll_yyyy-MM-dd_HH-mm-ss.
3133
${Name},
3234

3335
[Parameter(Mandatory)]
@@ -50,21 +52,27 @@ param(
5052
# The ID of the target subscription.
5153
${SubscriptionId},
5254

53-
[Parameter()]
55+
[Parameter(ParameterSetName='CreateExpanded')]
5456
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Body')]
5557
[System.String]
5658
# The end IP address of the server firewall rule.
5759
# Must be IPv4 format.
5860
${EndIPAddress},
5961

60-
[Parameter(Mandatory)]
62+
[Parameter(ParameterSetName='CreateExpanded', Mandatory)]
6163
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Body')]
6264
[System.String]
6365
# The start IP address of the server firewall rule.
6466
# Must be IPv4 format.
6567
# If range contains one IP, use StartIPAddress only.
6668
${StartIPAddress},
6769

70+
[Parameter(ParameterSetName='AllowAll', Mandatory)]
71+
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Body')]
72+
[System.Management.Automation.SwitchParameter]
73+
# Present to allow all range IPs, from 0.0.0.0 to 255.255.255.255.
74+
${AllowAll},
75+
6876
[Parameter()]
6977
[Alias('AzureRMContext', 'AzureCredential')]
7078
[ValidateNotNull()]
@@ -127,10 +135,29 @@ param(
127135

128136
process {
129137
try {
130-
if(!$PSBoundParameters.ContainsKey('EndIPAddress'))
138+
if($PSBoundParameters.ContainsKey('AllowAll'))
131139
{
132-
$PSBoundParameters['EndIPAddress'] = $PSBoundParameters['StartIPAddress']
140+
if(!$PSBoundParameters.ContainsKey('Name'))
141+
{
142+
$PSBoundParameters['Name'] = Get-Date -Format "AllowAll_yyyy-MM-dd_HH-mm-ss"
143+
}
144+
$PSBoundParameters['StartIPAddress'] = "0.0.0.0"
145+
$PSBoundParameters['EndIPAddress'] = "255.255.255.255"
146+
147+
$null = $PSBoundParameters.Remove('AllowAll')
133148
}
149+
else
150+
{
151+
if(!$PSBoundParameters.ContainsKey('Name'))
152+
{
153+
$PSBoundParameters['Name'] = "undefined"
154+
}
155+
if(!$PSBoundParameters.ContainsKey('EndIPAddress'))
156+
{
157+
$PSBoundParameters['EndIPAddress'] = $PSBoundParameters['StartIPAddress']
158+
}
159+
}
160+
134161
Az.MySql.internal\New-AzMySqlFirewallRule @PSBoundParameters
135162
} catch {
136163
throw

src/MySql/docs/Az.MySql.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
Module Name: Az.MySql
3-
Module Guid: 963f9799-010a-4688-a6d4-7eb6aea40e10
3+
Module Guid: 34e4ccf3-3db4-43f5-8e28-26d94c4d67f9
44
Download Help Link: https://docs.microsoft.com/en-us/powershell/module/az.mysql
55
Help Version: 1.0.0.0
66
Locale: en-US

src/MySql/docs/New-AzMySqlFirewallRule.md

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,18 @@ Creates a new firewall rule or updates an existing firewall rule.
1212

1313
## SYNTAX
1414

15+
### CreateExpanded (Default)
1516
```
16-
New-AzMySqlFirewallRule -Name <String> -ResourceGroupName <String> -ServerName <String>
17-
-StartIPAddress <String> [-SubscriptionId <String>] [-EndIPAddress <String>] [-DefaultProfile <PSObject>]
18-
[-AsJob] [-NoWait] [-Confirm] [-WhatIf] [<CommonParameters>]
17+
New-AzMySqlFirewallRule -ResourceGroupName <String> -ServerName <String> -StartIPAddress <String>
18+
[-Name <String>] [-SubscriptionId <String>] [-EndIPAddress <String>] [-DefaultProfile <PSObject>] [-AsJob]
19+
[-NoWait] [-Confirm] [-WhatIf] [<CommonParameters>]
20+
```
21+
22+
### AllowAll
23+
```
24+
New-AzMySqlFirewallRule -ResourceGroupName <String> -ServerName <String> -AllowAll [-Name <String>]
25+
[-SubscriptionId <String>] [-DefaultProfile <PSObject>] [-AsJob] [-NoWait] [-Confirm] [-WhatIf]
26+
[<CommonParameters>]
1927
```
2028

2129
## DESCRIPTION
@@ -27,9 +35,9 @@ Creates a new firewall rule or updates an existing firewall rule.
2735
```powershell
2836
PS C:\> New-AzMySqlFirewallRule -Name rule -ResourceGroupName PowershellMySqlTest -ServerName mysql-test -EndIPAddress 0.0.0.1 -StartIPAddress 0.0.0.0
2937
30-
Name Type
31-
---- ----
32-
rule Microsoft.DBforMySQL/servers/firewallRules
38+
Name StartIPAddress EndIPAddress
39+
---- -------------- ------------
40+
rule 0.0.0.0 0.0.0.1
3341
```
3442

3543
This cmdlets create a MySql server Firewall Rule.
@@ -38,15 +46,41 @@ This cmdlets create a MySql server Firewall Rule.
3846
```powershell
3947
PS C:\> New-AzMySqlFirewallRule -Name rule -ResourceGroupName PowershellMySqlTest -ServerName mysql-test -StartIPAddress 0.0.0.1
4048
41-
Name Type
42-
---- ----
43-
rule Microsoft.DBforMySQL/servers/firewallRules
49+
Name StartIPAddress EndIPAddress
50+
---- -------------- ------------
51+
rule 0.0.0.1 0.0.0.1
4452
```
4553

4654
This cmdlets create a MySql Firewall Rule use only one parameter StartIPAddress when only one IP needs to be authorized.
4755

56+
### Example 3: Create a new MySql Firewall Rule to allow all IPs
57+
```powershell
58+
PS C:\> New-AzMySqlFirewallRule -Name rule -ResourceGroupName PowershellMySqlTest -ServerName mysql-test -AllowAll
59+
60+
Name StartIPAddress EndIPAddress
61+
---- -------------- ------------
62+
AllowAll_2020-08-11_18-19-27 0.0.0.0 255.255.255.255
63+
```
64+
65+
This cmdlets create a new MySql Firewall Rule to allow all IPs.
66+
4867
## PARAMETERS
4968

69+
### -AllowAll
70+
Present to allow all range IPs, from 0.0.0.0 to 255.255.255.255.
71+
72+
```yaml
73+
Type: System.Management.Automation.SwitchParameter
74+
Parameter Sets: AllowAll
75+
Aliases:
76+
77+
Required: True
78+
Position: Named
79+
Default value: None
80+
Accept pipeline input: False
81+
Accept wildcard characters: False
82+
```
83+
5084
### -AsJob
5185
Run the command as a job
5286
@@ -83,7 +117,7 @@ Must be IPv4 format.
83117
84118
```yaml
85119
Type: System.String
86-
Parameter Sets: (All)
120+
Parameter Sets: CreateExpanded
87121
Aliases:
88122

89123
Required: False
@@ -95,13 +129,15 @@ Accept wildcard characters: False
95129
96130
### -Name
97131
The name of the server firewall rule.
132+
If not specified, the default is undefined.
133+
If AllowAll is present, the default name is AllowAll_yyyy-MM-dd_HH-mm-ss.
98134
99135
```yaml
100136
Type: System.String
101137
Parameter Sets: (All)
102138
Aliases: FirewallRuleName
103139

104-
Required: True
140+
Required: False
105141
Position: Named
106142
Default value: None
107143
Accept pipeline input: False
@@ -161,7 +197,7 @@ If range contains one IP, use StartIPAddress only.
161197
162198
```yaml
163199
Type: System.String
164-
Parameter Sets: (All)
200+
Parameter Sets: CreateExpanded
165201
Aliases:
166202

167203
Required: True

src/MySql/examples/New-AzMySqlFirewallRule.md

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
```powershell
33
PS C:\> New-AzMySqlFirewallRule -Name rule -ResourceGroupName PowershellMySqlTest -ServerName mysql-test -EndIPAddress 0.0.0.1 -StartIPAddress 0.0.0.0
44
5-
Name Type
6-
---- ----
7-
rule Microsoft.DBforMySQL/servers/firewallRules
5+
Name StartIPAddress EndIPAddress
6+
---- -------------- ------------
7+
rule 0.0.0.0 0.0.0.1
88
```
99

1010
This cmdlets create a MySql server Firewall Rule.
@@ -13,9 +13,20 @@ This cmdlets create a MySql server Firewall Rule.
1313
```powershell
1414
PS C:\> New-AzMySqlFirewallRule -Name rule -ResourceGroupName PowershellMySqlTest -ServerName mysql-test -StartIPAddress 0.0.0.1
1515
16-
Name Type
17-
---- ----
18-
rule Microsoft.DBforMySQL/servers/firewallRules
16+
Name StartIPAddress EndIPAddress
17+
---- -------------- ------------
18+
rule 0.0.0.1 0.0.0.1
1919
```
2020

21-
This cmdlets create a MySql Firewall Rule use only one parameter StartIPAddress when only one IP needs to be authorized.
21+
This cmdlets create a MySql Firewall Rule use only one parameter StartIPAddress when only one IP needs to be authorized.
22+
23+
### Example 3: Create a new MySql Firewall Rule to allow all IPs
24+
```powershell
25+
PS C:\> New-AzMySqlFirewallRule -Name rule -ResourceGroupName PowershellMySqlTest -ServerName mysql-test -AllowAll
26+
27+
Name StartIPAddress EndIPAddress
28+
---- -------------- ------------
29+
AllowAll_2020-08-11_18-19-27 0.0.0.0 255.255.255.255
30+
```
31+
32+
This cmdlets create a new MySql Firewall Rule to allow all IPs.

0 commit comments

Comments
 (0)