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-AzPostgreSqlFirewallRule {
23
+ [OutputType ([Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Models.Api20171201.IFirewallRule ])]
24
+ [CmdletBinding (DefaultParameterSetName = ' CreateExpanded' , PositionalBinding = $false , SupportsShouldProcess , ConfirmImpact = ' Medium' )]
25
+ param (
26
+ [Parameter ()]
27
+ [Alias (' FirewallRuleName' )]
28
+ [Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category (' Path' )]
29
+ [System.String ]
30
+ # The name of the server firewall rule.
31
+ ${Name} ,
32
+
33
+ [Parameter (Mandatory )]
34
+ [Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category (' Path' )]
35
+ [System.String ]
36
+ # The name of the resource group.
37
+ # The name is case insensitive.
38
+ ${ResourceGroupName} ,
39
+
40
+ [Parameter (Mandatory )]
41
+ [Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category (' Path' )]
42
+ [System.String ]
43
+ # The name of the server.
44
+ ${ServerName} ,
45
+
46
+ [Parameter ()]
47
+ [Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category (' Path' )]
48
+ [Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Runtime.DefaultInfo (Script= ' (Get-AzContext).Subscription.Id' )]
49
+ [System.String ]
50
+ # The ID of the target subscription.
51
+ ${SubscriptionId} ,
52
+
53
+ [Parameter (ParameterSetName = ' CreateExpanded' , Mandatory )]
54
+ [Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category (' Body' )]
55
+ [System.String ]
56
+ # The end IP address of the server firewall rule.
57
+ # Must be IPv4 format.
58
+ ${EndIPAddress} ,
59
+
60
+ [Parameter (ParameterSetName = ' CreateExpanded' , Mandatory )]
61
+ [Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category (' Body' )]
62
+ [System.String ]
63
+ # The start IP address of the server firewall rule.
64
+ # Must be IPv4 format.
65
+ ${StartIPAddress} ,
66
+
67
+ [Parameter (ParameterSetName = ' ClientIPAddress' , Mandatory )]
68
+ [Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category (' Body' )]
69
+ [System.String ]
70
+ # Client specified single IP of the server firewall rule.
71
+ # Must be IPv4 format.
72
+ ${ClientIPAddress} ,
73
+
74
+ [Parameter (ParameterSetName = ' AllowAll' , Mandatory )]
75
+ [Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category (' Body' )]
76
+ [System.Management.Automation.SwitchParameter ]
77
+ # Present to allow all range IPs, from 0.0.0.0 to 255.255.255.255.
78
+ ${AllowAll} ,
79
+
80
+ [Parameter ()]
81
+ [Alias (' AzureRMContext' , ' AzureCredential' )]
82
+ [ValidateNotNull ()]
83
+ [Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category (' Azure' )]
84
+ [System.Management.Automation.PSObject ]
85
+ # The credentials, account, tenant, and subscription used for communication with Azure.
86
+ ${DefaultProfile} ,
87
+
88
+ [Parameter ()]
89
+ [Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category (' Runtime' )]
90
+ [System.Management.Automation.SwitchParameter ]
91
+ # Run the command as a job
92
+ ${AsJob} ,
93
+
94
+ [Parameter (DontShow)]
95
+ [Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category (' Runtime' )]
96
+ [System.Management.Automation.SwitchParameter ]
97
+ # Wait for .NET debugger to attach
98
+ ${Break} ,
99
+
100
+ [Parameter (DontShow)]
101
+ [ValidateNotNull ()]
102
+ [Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category (' Runtime' )]
103
+ [Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Runtime.SendAsyncStep []]
104
+ # SendAsync Pipeline Steps to be appended to the front of the pipeline
105
+ ${HttpPipelineAppend} ,
106
+
107
+ [Parameter (DontShow)]
108
+ [ValidateNotNull ()]
109
+ [Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category (' Runtime' )]
110
+ [Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Runtime.SendAsyncStep []]
111
+ # SendAsync Pipeline Steps to be prepended to the front of the pipeline
112
+ ${HttpPipelinePrepend} ,
113
+
114
+ [Parameter ()]
115
+ [Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category (' Runtime' )]
116
+ [System.Management.Automation.SwitchParameter ]
117
+ # Run the command asynchronously
118
+ ${NoWait} ,
119
+
120
+ [Parameter (DontShow)]
121
+ [Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category (' Runtime' )]
122
+ [System.Uri ]
123
+ # The URI for the proxy server to use
124
+ ${Proxy} ,
125
+
126
+ [Parameter (DontShow)]
127
+ [ValidateNotNull ()]
128
+ [Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category (' Runtime' )]
129
+ [System.Management.Automation.PSCredential ]
130
+ # Credentials for a proxy server to use for the remote call
131
+ ${ProxyCredential} ,
132
+
133
+ [Parameter (DontShow)]
134
+ [Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category (' Runtime' )]
135
+ [System.Management.Automation.SwitchParameter ]
136
+ # Use the default credentials for the proxy
137
+ ${ProxyUseDefaultCredentials}
138
+ )
139
+
140
+ process {
141
+ try {
142
+ if ($PSBoundParameters.ContainsKey (' AllowAll' ))
143
+ {
144
+ if (! $PSBoundParameters.ContainsKey (' Name' ))
145
+ {
146
+ $PSBoundParameters [' Name' ] = Get-Date - Format " AllowAll_yyyy-MM-dd_HH-mm-ss"
147
+ }
148
+ $PSBoundParameters [' StartIPAddress' ] = " 0.0.0.0"
149
+ $PSBoundParameters [' EndIPAddress' ] = " 255.255.255.255"
150
+
151
+ $null = $PSBoundParameters.Remove (' AllowAll' )
152
+ }
153
+ elseif ($PSBoundParameters.ContainsKey (' ClientIPAddress' ))
154
+ {
155
+ $PSBoundParameters [' StartIPAddress' ] = $PSBoundParameters [' ClientIPAddress' ]
156
+ $PSBoundParameters [' EndIPAddress' ] = $PSBoundParameters [' ClientIPAddress' ]
157
+
158
+ if (! $PSBoundParameters.ContainsKey (' Name' ))
159
+ {
160
+ $PSBoundParameters [' Name' ] = " ClientIPAddress_" + (Get-Date - Format " yyyy-MM-dd_HH-mm-ss" )
161
+ }
162
+
163
+ $null = $PSBoundParameters.Remove (' ClientIPAddress' )
164
+ }
165
+ else
166
+ {
167
+ if (! $PSBoundParameters.ContainsKey (' Name' ))
168
+ {
169
+ $PSBoundParameters [' Name' ] = " undefined"
170
+ }
171
+ }
172
+
173
+ Az.PostgreSql.internal\New-AzPostgreSqlFirewallRule @PSBoundParameters
174
+ } catch {
175
+ throw
176
+ }
177
+ }
178
+ }
0 commit comments