Skip to content

Commit 53a535e

Browse files
authored
Improve PostgreSql (#13077)
Fix the following issues #12956 #12745 #12743 #12738 #12736
1 parent 7a459cd commit 53a535e

File tree

46 files changed

+4061
-2918
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+4061
-2918
lines changed
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
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+
}

src/PostgreSql/custom/New-AzPostgreSqlReplica.ps1

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ function New-AzPostgreSqlReplica {
1919
[Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Description('Creates a new replica from an existing database.')]
2020
param(
2121
[Parameter(Mandatory, HelpMessage = 'The name of the server.')]
22-
[Alias('ReplicaServerName')]
22+
[Alias('ReplicaServerName', 'Name')]
2323
[Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category('Path')]
2424
[System.String]
25-
${Name},
25+
${ReplicaName},
2626

2727
[Parameter(Mandatory, HelpMessage = 'The name of the resource group that contains the resource, You can obtain this value from the Azure Resource Manager API or the portal.')]
2828
[Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category('Path')]
@@ -36,9 +36,10 @@ function New-AzPostgreSqlReplica {
3636
${SubscriptionId},
3737

3838
[Parameter(Mandatory, ValueFromPipeline, HelpMessage = 'The source server object to create replica from.')]
39+
[Alias('InputObject')]
3940
[Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category('Body')]
4041
[Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Models.Api20171201.IServer]
41-
${InputObject},
42+
${Master},
4243

4344
[Parameter(HelpMessage = 'The location the resource resides in.')]
4445
[Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category('Body')]
@@ -112,10 +113,10 @@ function New-AzPostgreSqlReplica {
112113
$Parameter.Property = [Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Models.Api20171201.ServerPropertiesForReplica]::new()
113114
$Parameter.CreateMode = [Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Support.CreateMode]::Replica
114115

115-
$server = $PSBoundParameters['InputObject']
116+
$server = $PSBoundParameters['Master']
116117
$Parameter.Property.SourceServerId = $server.Id
117118
$Parameter.Location = $server.Location
118-
$null = $PSBoundParameters.Remove('InputObject')
119+
$null = $PSBoundParameters.Remove('Master')
119120

120121
if ($PSBoundParameters.ContainsKey('Location')) {
121122
$Parameter.Location = $PSBoundParameters['Location']
@@ -127,6 +128,12 @@ function New-AzPostgreSqlReplica {
127128
$null = $PSBoundParameters.Remove('Sku')
128129
}
129130

131+
if ($PSBoundParameters.ContainsKey('ReplicaName'))
132+
{
133+
$PSBoundParameters['Name'] = $PSBoundParameters['ReplicaName']
134+
$null = $PSBoundParameters.Remove('ReplicaName')
135+
}
136+
130137
$PSBoundParameters.Add('Parameter', $Parameter)
131138

132139
Az.PostgreSql.internal\New-AzPostgreSqlServer @PSBoundParameters

src/PostgreSql/custom/New-AzPostgreSqlServer.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ function New-AzPostgreSqlServer {
7575

7676
[Parameter(HelpMessage = 'Enable Storage Auto Grow.')]
7777
[ArgumentCompleter([Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Support.StorageAutogrow])]
78+
[Validateset('Enabled', 'Disabled')]
7879
[Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category('Body')]
7980
[Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Support.StorageAutogrow]
8081
${StorageAutogrow},
@@ -211,7 +212,7 @@ function New-AzPostgreSqlServer {
211212
$Parameter.Property.AdministratorLogin = $PSBoundParameters['AdministratorUserName']
212213
$null = $PSBoundParameters.Remove('AdministratorUserName')
213214

214-
$Parameter.Property.AdministratorLoginPassword = [System.Runtime.InteropServices.marshal]::PtrToStringAuto([System.Runtime.InteropServices.marshal]::SecureStringToBSTR($PSBoundParameters['AdministratorLoginPassword']))
215+
$Parameter.Property.AdministratorLoginPassword = . "$PSScriptRoot/../utils/Unprotect-SecureString.ps1" $PSBoundParameters['AdministratorLoginPassword']
215216
$null = $PSBoundParameters.Remove('AdministratorLoginPassword')
216217

217218
$PSBoundParameters.Add('Parameter', $Parameter)
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
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+
Updates a configuration of a server.
19+
Use Update-AzPostgreSqlServer instead if you want update AdministratorLoginPassword, sku, etc.
20+
.Description
21+
Updates a configuration of a server.
22+
Use Update-AzPostgreSqlServer instead if you want update AdministratorLoginPassword, sku, etc.
23+
#>
24+
function Update-AzPostgreSqlConfiguration {
25+
[OutputType([Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Models.Api20171201.IConfiguration])]
26+
[CmdletBinding(DefaultParameterSetName='UpdateExpanded', PositionalBinding=$false, SupportsShouldProcess, ConfirmImpact='Medium')]
27+
param(
28+
[Parameter(ParameterSetName='UpdateExpanded', Mandatory)]
29+
[Alias('ConfigurationName')]
30+
[Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category('Path')]
31+
[System.String]
32+
# The name of the server configuration.
33+
${Name},
34+
35+
[Parameter(ParameterSetName='UpdateExpanded', Mandatory)]
36+
[Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category('Path')]
37+
[System.String]
38+
# The name of the resource group.
39+
# The name is case insensitive.
40+
${ResourceGroupName},
41+
42+
[Parameter(ParameterSetName='UpdateExpanded', Mandatory)]
43+
[Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category('Path')]
44+
[System.String]
45+
# The name of the server.
46+
${ServerName},
47+
48+
[Parameter(ParameterSetName='UpdateExpanded')]
49+
[Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category('Path')]
50+
[Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Runtime.DefaultInfo(Script='(Get-AzContext).Subscription.Id')]
51+
[System.String]
52+
# The ID of the target subscription.
53+
${SubscriptionId},
54+
55+
[Parameter(ParameterSetName='UpdateViaIdentityExpanded', Mandatory, ValueFromPipeline)]
56+
[Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category('Path')]
57+
[Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Models.IPostgreSqlIdentity]
58+
# Identity Parameter
59+
# To construct, see NOTES section for INPUTOBJECT properties and create a hash table.
60+
${InputObject},
61+
62+
[Parameter(ParameterSetName='UpdateExpanded')]
63+
[Parameter(ParameterSetName='UpdateViaIdentityExpanded')]
64+
[Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category('Body')]
65+
[System.String]
66+
# Source of the configuration.
67+
${Source},
68+
69+
[Parameter(ParameterSetName='UpdateExpanded')]
70+
[Parameter(ParameterSetName='UpdateViaIdentityExpanded')]
71+
[Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category('Body')]
72+
[System.String]
73+
# Value of the configuration.
74+
${Value},
75+
76+
[Parameter()]
77+
[Alias('AzureRMContext', 'AzureCredential')]
78+
[ValidateNotNull()]
79+
[Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.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.PostgreSql.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.PostgreSql.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.PostgreSql.Category('Runtime')]
99+
[Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.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.PostgreSql.Category('Runtime')]
106+
[Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.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.PostgreSql.Category('Runtime')]
112+
[System.Management.Automation.SwitchParameter]
113+
# Run the command asynchronously
114+
${NoWait},
115+
116+
[Parameter(DontShow)]
117+
[Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.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.PostgreSql.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.PostgreSql.Category('Runtime')]
131+
[System.Management.Automation.SwitchParameter]
132+
# Use the default credentials for the proxy
133+
${ProxyUseDefaultCredentials}
134+
)
135+
136+
process {
137+
try {
138+
Az.PostgreSql.internal\Update-AzPostgreSqlConfiguration @PSBoundParameters
139+
} catch {
140+
throw
141+
}
142+
}
143+
}

0 commit comments

Comments
 (0)