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

Added ClientIpAddress Modes to firewall rule cmdlets #12689

Merged
merged 1 commit into from
Aug 18, 2020
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
4 changes: 2 additions & 2 deletions src/MySql/Az.MySql.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# Generated by: Microsoft Corporation
#
# Generated on: 8/12/2020
# Generated on: 8/18/2020
#

@{
Expand Down Expand Up @@ -45,7 +45,7 @@ PowerShellVersion = '5.1'
DotNetFrameworkVersion = '4.7.2'

# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
# CLRVersion = ''
# ClrVersion = ''

# Processor architecture (None, X86, Amd64) required by this module
# ProcessorArchitecture = ''
Expand Down
16 changes: 8 additions & 8 deletions src/MySql/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
- Additional information about change #1
-->
## Upcoming Release
* Remove legacy SkuSize from input and output (#11725)
* Specify a default name when create MySql firewall rule without name and add AllowAll mode (#11932)
* Enable EndIpAddress to be absent if only one IP to be authorized in firewall rule (#11933)
* Add validateset for parameter StorageAutogrow (#11936)
* Rename New-AzMySqlServerReplica to New-AzMySqlReplica (#11938)
* Use 'master' and 'replica' to avoid confusion when create mysql replica server (#11939)
* Provide hint in doc to use Update-AzMySqlServer & Update-AzMySqlServerConfiguration as a candidate for each other (#11954)
* Removed legacy SkuSize from input and output (#11725)
* Added AllowAll & ClientIpAddress Modes to firewall rule cmdlets (#11932)
* specified a default name when created MySql firewall rule without a name (#11932)
* Added validateset for parameter StorageAutogrow (#11936)
* Renamed New-AzMySqlServerReplica to New-AzMySqlReplica (#11938)
* Used 'master' and 'replica' to avoid confusion when created mysql replica server (#11939)
* Provided hint in doc to use Update-AzMySqlServer & Update-AzMySqlServerConfiguration as a candidate for each other (#11954)

## Version 0.1.0
* the first preview release
* The first preview release

26 changes: 20 additions & 6 deletions src/MySql/custom/New-AzMySqlFirewallRule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ param(
# The ID of the target subscription.
${SubscriptionId},

[Parameter(ParameterSetName='CreateExpanded')]
[Parameter(ParameterSetName='CreateExpanded', Mandatory)]
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Body')]
[System.String]
# The end IP address of the server firewall rule.
Expand All @@ -64,9 +64,15 @@ param(
[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='ClientIPAddress', Mandatory)]
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Body')]
[System.String]
# Client specified single IP of the server firewall rule.
# Must be IPv4 format.
${ClientIPAddress},

[Parameter(ParameterSetName='AllowAll', Mandatory)]
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Body')]
[System.Management.Automation.SwitchParameter]
Expand Down Expand Up @@ -146,15 +152,23 @@ process {

$null = $PSBoundParameters.Remove('AllowAll')
}
else
elseif($PSBoundParameters.ContainsKey('ClientIPAddress'))
{
$PSBoundParameters['StartIPAddress'] = $PSBoundParameters['ClientIPAddress']
$PSBoundParameters['EndIPAddress'] = $PSBoundParameters['ClientIPAddress']

if(!$PSBoundParameters.ContainsKey('Name'))
{
$PSBoundParameters['Name'] = "undefined"
$PSBoundParameters['Name'] = "ClientIPAddress_" + (Get-Date -Format "yyyy-MM-dd_HH-mm-ss")
}
if(!$PSBoundParameters.ContainsKey('EndIPAddress'))

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

Expand Down
26 changes: 21 additions & 5 deletions src/MySql/custom/Update-AzMySqlFirewallRule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,54 +24,68 @@ function Update-AzMySqlFirewallRule {
[CmdletBinding(DefaultParameterSetName='UpdateExpanded', PositionalBinding=$false, SupportsShouldProcess, ConfirmImpact='Medium')]
param(
[Parameter(ParameterSetName='UpdateExpanded', Mandatory)]
[Parameter(ParameterSetName='ClientIPAddress', Mandatory)]
[Alias('FirewallRuleName')]
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Path')]
[System.String]
# The name of the server firewall rule.
${Name},

[Parameter(ParameterSetName='UpdateExpanded', Mandatory)]
[Parameter(ParameterSetName='ClientIPAddress', Mandatory)]
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Path')]
[System.String]
# The name of the resource group.
# The name is case insensitive.
${ResourceGroupName},

[Parameter(ParameterSetName='UpdateExpanded', Mandatory)]
[Parameter(ParameterSetName='ClientIPAddress', Mandatory)]
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Path')]
[System.String]
# The name of the server.
${ServerName},

[Parameter(ParameterSetName='UpdateExpanded')]
[Parameter(ParameterSetName='ClientIPAddress')]
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Path')]
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Runtime.DefaultInfo(Script='(Get-AzContext).Subscription.Id')]
[System.String]
# The ID of the target subscription.
${SubscriptionId},

[Parameter(ParameterSetName='UpdateViaIdentityExpanded', Mandatory, ValueFromPipeline)]
[Parameter(ParameterSetName='ClientIPAddressViaIdentity', Mandatory, ValueFromPipeline)]
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Path')]
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Models.IMySqlIdentity]
# Identity Parameter
# To construct, see NOTES section for INPUTOBJECT properties and create a hash table.
${InputObject},

[Parameter()]
[Parameter(ParameterSetName='UpdateExpanded', Mandatory)]
[Parameter(ParameterSetName='UpdateViaIdentityExpanded', Mandatory)]
[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='UpdateExpanded', Mandatory)]
[Parameter(ParameterSetName='UpdateViaIdentityExpanded', 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='ClientIPAddress', Mandatory)]
[Parameter(ParameterSetName='ClientIPAddressViaIdentity', Mandatory)]
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Body')]
[System.String]
# Client specified single IP of the server firewall rule.
# Must be IPv4 format.
${ClientIPAddress},

[Parameter()]
[Alias('AzureRMContext', 'AzureCredential')]
[ValidateNotNull()]
Expand Down Expand Up @@ -134,9 +148,11 @@ param(

process {
try {
if(!$PSBoundParameters.ContainsKey('EndIPAddress'))
if($PSBoundParameters.ContainsKey('ClientIPAddress'))
{
$PSBoundParameters['EndIPAddress'] = $PSBoundParameters['StartIPAddress']
$PSBoundParameters['StartIPAddress'] = $PSBoundParameters['ClientIPAddress']
$PSBoundParameters['EndIPAddress'] = $PSBoundParameters['ClientIPAddress']
$null = $PSBoundParameters.Remove('ClientIPAddress')
}
Az.MySql.internal\Update-AzMySqlFirewallRule @PSBoundParameters
} catch {
Expand Down
12 changes: 6 additions & 6 deletions src/MySql/examples/New-AzMySqlFirewallRule.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ rule 0.0.0.0 0.0.0.1

This cmdlets create a MySql server Firewall Rule.

### Example 2: Create a new MySql Firewall Rule use only one parameter StartIPAddress when only one IP needs to be authorized
### Example 2: Create a new MySql Firewall Rule using -ClientIPAddress.
```powershell
PS C:\> New-AzMySqlFirewallRule -Name rule -ResourceGroupName PowershellMySqlTest -ServerName mysql-test -StartIPAddress 0.0.0.1
PS C:\> New-AzMySqlFirewallRule -ResourceGroupName PowershellMySqlTest -ServerName mysql-test -ClientIPAddress 0.0.0.1

Name StartIPAddress EndIPAddress
---- -------------- ------------
rule 0.0.0.1 0.0.0.1
Name StartIPAddress EndIPAddress
---- -------------- ------------
ClientIPAddress_2020-08-11_18-19-27 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 using -ClientIPAddress.

### Example 3: Create a new MySql Firewall Rule to allow all IPs
```powershell
Expand Down
8 changes: 4 additions & 4 deletions src/MySql/examples/Update-AzMySqlFirewallRule.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ rule 0.0.0.2 0.0.0.3

These cmdlets update MySql Firewall Rule by identity.

### Example 3: Update MySql Firewall Rule use only one parameter StartIPAddress when only one IP needs to be authorized
### Example 3: Update MySql Firewall Rule by -ClientIPAddress.
```powershell
PS C:\> $ID = "/subscriptions/<SubscriptionId>/resourceGroups/PowershellMySqlTest/providers/Microsoft.DBforMySQL/servers/mysql-test/firewallRules/rule"
PS C:\> Update-AzMySqlFirewallRule -InputObject $ID -StartIPAddress 0.0.0.2
PS C:\> Update-AzMySqlFirewallRule -InputObject $ID --ClientIPAddress 0.0.0.2

Name StartIPAddress EndIPAddress
---- -------------- ------------
rule 0.0.0.2 0.0.0.3
rule 0.0.0.2 0.0.0.2
```

These cmdlets update MySql Firewall Rule use only one parameter StartIPAddress when only one IP needs to be authorized.
These cmdlets update MySql Firewall Rule by -ClientIPAddress.
25 changes: 16 additions & 9 deletions src/MySql/exports/New-AzMySqlFirewallRule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ Name StartIPAddress EndIPAddress
---- -------------- ------------
rule 0.0.0.0 0.0.0.1
.Example
PS C:\> New-AzMySqlFirewallRule -Name rule -ResourceGroupName PowershellMySqlTest -ServerName mysql-test -StartIPAddress 0.0.0.1
PS C:\> New-AzMySqlFirewallRule -ResourceGroupName PowershellMySqlTest -ServerName mysql-test -ClientIPAddress 0.0.0.1

Name StartIPAddress EndIPAddress
---- -------------- ------------
rule 0.0.0.1 0.0.0.1
Name StartIPAddress EndIPAddress
---- -------------- ------------
ClientIPAddress_2020-08-11_18-19-27 0.0.0.1 0.0.0.1
.Example
PS C:\> New-AzMySqlFirewallRule -Name rule -ResourceGroupName PowershellMySqlTest -ServerName mysql-test -AllowAll

Expand Down Expand Up @@ -75,20 +75,26 @@ param(
# The ID of the target subscription.
${SubscriptionId},

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

[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='CreateExpanded')]
[Parameter(ParameterSetName='ClientIPAddress', Mandatory)]
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Body')]
[System.String]
# The end IP address of the server firewall rule.
# Client specified single IP of the server firewall rule.
# Must be IPv4 format.
${EndIPAddress},
${ClientIPAddress},

[Parameter(ParameterSetName='AllowAll', Mandatory)]
[Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Body')]
Expand Down Expand Up @@ -165,9 +171,10 @@ begin {
$parameterSet = $PSCmdlet.ParameterSetName
$mapping = @{
CreateExpanded = 'Az.MySql.custom\New-AzMySqlFirewallRule';
ClientIPAddress = 'Az.MySql.custom\New-AzMySqlFirewallRule';
AllowAll = 'Az.MySql.custom\New-AzMySqlFirewallRule';
}
if (('CreateExpanded', 'AllowAll') -contains $parameterSet -and -not $PSBoundParameters.ContainsKey('SubscriptionId')) {
if (('CreateExpanded', 'ClientIPAddress', 'AllowAll') -contains $parameterSet -and -not $PSBoundParameters.ContainsKey('SubscriptionId')) {
$PSBoundParameters['SubscriptionId'] = (Get-AzContext).Subscription.Id
}
$wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand(($mapping[$parameterSet]), [System.Management.Automation.CommandTypes]::Cmdlet)
Expand Down
Loading