Skip to content
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 32 additions & 5 deletions src/MySql/custom/New-AzMySqlFirewallRule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ function New-AzMySqlFirewallRule {
[OutputType([Microsoft.Azure.PowerShell.Cmdlets.MySql.Models.Api20171201.IFirewallRule])]
[CmdletBinding(DefaultParameterSetName='CreateExpanded', PositionalBinding=$false, SupportsShouldProcess, ConfirmImpact='Medium')]
param(
[Parameter(Mandatory)]
[Parameter()]
[Alias('FirewallRuleName')]
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Path')]
[System.String]
# The name of the server firewall rule.
# If not specified, the default is undefined.
# If AllowAll is present, the default name is AllowAll_yyyy-MM-dd_HH-mm-ss.
${Name},

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

[Parameter()]
[Parameter(ParameterSetName='CreateExpanded')]
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Body')]
[System.String]
# The end IP address of the server firewall rule.
# Must be IPv4 format.
${EndIPAddress},

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

[Parameter(ParameterSetName='AllowAll', Mandatory)]
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Body')]
[System.Management.Automation.SwitchParameter]
# Present to allow all range IPs, from 0.0.0.0 to 255.255.255.255.
${AllowAll},

[Parameter()]
[Alias('AzureRMContext', 'AzureCredential')]
[ValidateNotNull()]
Expand Down Expand Up @@ -127,10 +135,29 @@ param(

process {
try {
if(!$PSBoundParameters.ContainsKey('EndIPAddress'))
if($PSBoundParameters.ContainsKey('AllowAll'))
{
$PSBoundParameters['EndIPAddress'] = $PSBoundParameters['StartIPAddress']
if(!$PSBoundParameters.ContainsKey('Name'))
{
$PSBoundParameters['Name'] = Get-Date -Format "AllowAll_yyyy-MM-dd_HH-mm-ss"
}
$PSBoundParameters['StartIPAddress'] = "0.0.0.0"
$PSBoundParameters['EndIPAddress'] = "255.255.255.255"

$null = $PSBoundParameters.Remove('AllowAll')
}
else
{
if(!$PSBoundParameters.ContainsKey('Name'))
{
$PSBoundParameters['Name'] = "undefined"
}
if(!$PSBoundParameters.ContainsKey('EndIPAddress'))
{
$PSBoundParameters['EndIPAddress'] = $PSBoundParameters['StartIPAddress']
}
}

Az.MySql.internal\New-AzMySqlFirewallRule @PSBoundParameters
} catch {
throw
Expand Down
2 changes: 1 addition & 1 deletion src/MySql/docs/Az.MySql.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
Module Name: Az.MySql
Module Guid: 963f9799-010a-4688-a6d4-7eb6aea40e10
Module Guid: 34e4ccf3-3db4-43f5-8e28-26d94c4d67f9
Download Help Link: https://docs.microsoft.com/en-us/powershell/module/az.mysql
Help Version: 1.0.0.0
Locale: en-US
Expand Down
60 changes: 48 additions & 12 deletions src/MySql/docs/New-AzMySqlFirewallRule.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,18 @@ Creates a new firewall rule or updates an existing firewall rule.

## SYNTAX

### CreateExpanded (Default)
```
New-AzMySqlFirewallRule -Name <String> -ResourceGroupName <String> -ServerName <String>
-StartIPAddress <String> [-SubscriptionId <String>] [-EndIPAddress <String>] [-DefaultProfile <PSObject>]
[-AsJob] [-NoWait] [-Confirm] [-WhatIf] [<CommonParameters>]
New-AzMySqlFirewallRule -ResourceGroupName <String> -ServerName <String> -StartIPAddress <String>
[-Name <String>] [-SubscriptionId <String>] [-EndIPAddress <String>] [-DefaultProfile <PSObject>] [-AsJob]
[-NoWait] [-Confirm] [-WhatIf] [<CommonParameters>]
```

### AllowAll
```
New-AzMySqlFirewallRule -ResourceGroupName <String> -ServerName <String> -AllowAll [-Name <String>]
[-SubscriptionId <String>] [-DefaultProfile <PSObject>] [-AsJob] [-NoWait] [-Confirm] [-WhatIf]
[<CommonParameters>]
```

## DESCRIPTION
Expand All @@ -27,9 +35,9 @@ Creates a new firewall rule or updates an existing firewall rule.
```powershell
PS C:\> New-AzMySqlFirewallRule -Name rule -ResourceGroupName PowershellMySqlTest -ServerName mysql-test -EndIPAddress 0.0.0.1 -StartIPAddress 0.0.0.0

Name Type
---- ----
rule Microsoft.DBforMySQL/servers/firewallRules
Name StartIPAddress EndIPAddress
---- -------------- ------------
rule 0.0.0.0 0.0.0.1
```

This cmdlets create a MySql server Firewall Rule.
Expand All @@ -38,15 +46,41 @@ This cmdlets create a MySql server Firewall Rule.
```powershell
PS C:\> New-AzMySqlFirewallRule -Name rule -ResourceGroupName PowershellMySqlTest -ServerName mysql-test -StartIPAddress 0.0.0.1

Name Type
---- ----
rule Microsoft.DBforMySQL/servers/firewallRules
Name StartIPAddress EndIPAddress
---- -------------- ------------
rule 0.0.0.1 0.0.0.1
```

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

### Example 3: Create a new MySql Firewall Rule to allow all IPs
```powershell
PS C:\> New-AzMySqlFirewallRule -Name rule -ResourceGroupName PowershellMySqlTest -ServerName mysql-test -AllowAll

Name StartIPAddress EndIPAddress
---- -------------- ------------
AllowAll_2020-08-11_18-19-27 0.0.0.0 255.255.255.255
```

This cmdlets create a new MySql Firewall Rule to allow all IPs.

## PARAMETERS

### -AllowAll
Present to allow all range IPs, from 0.0.0.0 to 255.255.255.255.

```yaml
Type: System.Management.Automation.SwitchParameter
Parameter Sets: AllowAll
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -AsJob
Run the command as a job

Expand Down Expand Up @@ -83,7 +117,7 @@ Must be IPv4 format.

```yaml
Type: System.String
Parameter Sets: (All)
Parameter Sets: CreateExpanded
Aliases:

Required: False
Expand All @@ -95,13 +129,15 @@ Accept wildcard characters: False

### -Name
The name of the server firewall rule.
If not specified, the default is undefined.
If AllowAll is present, the default name is AllowAll_yyyy-MM-dd_HH-mm-ss.

```yaml
Type: System.String
Parameter Sets: (All)
Aliases: FirewallRuleName

Required: True
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Expand Down Expand Up @@ -161,7 +197,7 @@ If range contains one IP, use StartIPAddress only.

```yaml
Type: System.String
Parameter Sets: (All)
Parameter Sets: CreateExpanded
Aliases:

Required: True
Expand Down
25 changes: 18 additions & 7 deletions src/MySql/examples/New-AzMySqlFirewallRule.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
```powershell
PS C:\> New-AzMySqlFirewallRule -Name rule -ResourceGroupName PowershellMySqlTest -ServerName mysql-test -EndIPAddress 0.0.0.1 -StartIPAddress 0.0.0.0

Name Type
---- ----
rule Microsoft.DBforMySQL/servers/firewallRules
Name StartIPAddress EndIPAddress
---- -------------- ------------
rule 0.0.0.0 0.0.0.1
```

This cmdlets create a MySql server Firewall Rule.
Expand All @@ -13,9 +13,20 @@ This cmdlets create a MySql server Firewall Rule.
```powershell
PS C:\> New-AzMySqlFirewallRule -Name rule -ResourceGroupName PowershellMySqlTest -ServerName mysql-test -StartIPAddress 0.0.0.1

Name Type
---- ----
rule Microsoft.DBforMySQL/servers/firewallRules
Name StartIPAddress EndIPAddress
---- -------------- ------------
rule 0.0.0.1 0.0.0.1
```

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

### Example 3: Create a new MySql Firewall Rule to allow all IPs
```powershell
PS C:\> New-AzMySqlFirewallRule -Name rule -ResourceGroupName PowershellMySqlTest -ServerName mysql-test -AllowAll

Name StartIPAddress EndIPAddress
---- -------------- ------------
AllowAll_2020-08-11_18-19-27 0.0.0.0 255.255.255.255
```

This cmdlets create a new MySql Firewall Rule to allow all IPs.
Loading