|
| 1 | + |
| 2 | +# ---------------------------------------------------------------------------------- |
| 3 | +# |
| 4 | +# Copyright Microsoft Corporation |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | +# ---------------------------------------------------------------------------------- |
| 15 | + |
| 16 | +<# |
| 17 | +.Synopsis |
| 18 | +Creates a new firewall rule or updates an existing firewall rule. |
| 19 | +.Description |
| 20 | +Creates a new firewall rule or updates an existing firewall rule. |
| 21 | +#> |
| 22 | +function New-AzMySqlFirewallRule { |
| 23 | +[OutputType([Microsoft.Azure.PowerShell.Cmdlets.MySql.Models.Api20171201.IFirewallRule])] |
| 24 | +[CmdletBinding(DefaultParameterSetName='CreateExpanded', PositionalBinding=$false, SupportsShouldProcess, ConfirmImpact='Medium')] |
| 25 | +param( |
| 26 | + [Parameter()] |
| 27 | + [Alias('FirewallRuleName')] |
| 28 | + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Path')] |
| 29 | + [System.String] |
| 30 | + # 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. |
| 33 | + ${Name}, |
| 34 | + |
| 35 | + [Parameter(Mandatory)] |
| 36 | + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Path')] |
| 37 | + [System.String] |
| 38 | + # The name of the resource group. |
| 39 | + # The name is case insensitive. |
| 40 | + ${ResourceGroupName}, |
| 41 | + |
| 42 | + [Parameter(Mandatory)] |
| 43 | + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Path')] |
| 44 | + [System.String] |
| 45 | + # The name of the server. |
| 46 | + ${ServerName}, |
| 47 | + |
| 48 | + [Parameter()] |
| 49 | + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Path')] |
| 50 | + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Runtime.DefaultInfo(Script='(Get-AzContext).Subscription.Id')] |
| 51 | + [System.String] |
| 52 | + # The ID of the target subscription. |
| 53 | + ${SubscriptionId}, |
| 54 | + |
| 55 | + [Parameter(ParameterSetName='CreateExpanded')] |
| 56 | + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Body')] |
| 57 | + [System.String] |
| 58 | + # The end IP address of the server firewall rule. |
| 59 | + # Must be IPv4 format. |
| 60 | + ${EndIPAddress}, |
| 61 | + |
| 62 | + [Parameter(ParameterSetName='CreateExpanded', Mandatory)] |
| 63 | + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Body')] |
| 64 | + [System.String] |
| 65 | + # The start IP address of the server firewall rule. |
| 66 | + # Must be IPv4 format. |
| 67 | + # If range contains one IP, use StartIPAddress only. |
| 68 | + ${StartIPAddress}, |
| 69 | + |
| 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 | + |
| 76 | + [Parameter()] |
| 77 | + [Alias('AzureRMContext', 'AzureCredential')] |
| 78 | + [ValidateNotNull()] |
| 79 | + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Azure')] |
| 80 | + [System.Management.Automation.PSObject] |
| 81 | + # The credentials, account, tenant, and subscription used for communication with Azure. |
| 82 | + ${DefaultProfile}, |
| 83 | + |
| 84 | + [Parameter()] |
| 85 | + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Runtime')] |
| 86 | + [System.Management.Automation.SwitchParameter] |
| 87 | + # Run the command as a job |
| 88 | + ${AsJob}, |
| 89 | + |
| 90 | + [Parameter(DontShow)] |
| 91 | + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Runtime')] |
| 92 | + [System.Management.Automation.SwitchParameter] |
| 93 | + # Wait for .NET debugger to attach |
| 94 | + ${Break}, |
| 95 | + |
| 96 | + [Parameter(DontShow)] |
| 97 | + [ValidateNotNull()] |
| 98 | + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Runtime')] |
| 99 | + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Runtime.SendAsyncStep[]] |
| 100 | + # SendAsync Pipeline Steps to be appended to the front of the pipeline |
| 101 | + ${HttpPipelineAppend}, |
| 102 | + |
| 103 | + [Parameter(DontShow)] |
| 104 | + [ValidateNotNull()] |
| 105 | + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Runtime')] |
| 106 | + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Runtime.SendAsyncStep[]] |
| 107 | + # SendAsync Pipeline Steps to be prepended to the front of the pipeline |
| 108 | + ${HttpPipelinePrepend}, |
| 109 | + |
| 110 | + [Parameter()] |
| 111 | + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Runtime')] |
| 112 | + [System.Management.Automation.SwitchParameter] |
| 113 | + # Run the command asynchronously |
| 114 | + ${NoWait}, |
| 115 | + |
| 116 | + [Parameter(DontShow)] |
| 117 | + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Runtime')] |
| 118 | + [System.Uri] |
| 119 | + # The URI for the proxy server to use |
| 120 | + ${Proxy}, |
| 121 | + |
| 122 | + [Parameter(DontShow)] |
| 123 | + [ValidateNotNull()] |
| 124 | + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Runtime')] |
| 125 | + [System.Management.Automation.PSCredential] |
| 126 | + # Credentials for a proxy server to use for the remote call |
| 127 | + ${ProxyCredential}, |
| 128 | + |
| 129 | + [Parameter(DontShow)] |
| 130 | + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Runtime')] |
| 131 | + [System.Management.Automation.SwitchParameter] |
| 132 | + # Use the default credentials for the proxy |
| 133 | + ${ProxyUseDefaultCredentials} |
| 134 | +) |
| 135 | + |
| 136 | +process { |
| 137 | + try { |
| 138 | + if($PSBoundParameters.ContainsKey('AllowAll')) |
| 139 | + { |
| 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') |
| 148 | + } |
| 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 | + |
| 161 | + Az.MySql.internal\New-AzMySqlFirewallRule @PSBoundParameters |
| 162 | + } catch { |
| 163 | + throw |
| 164 | + } |
| 165 | +} |
| 166 | +} |
0 commit comments