Skip to content

Commit d673a3a

Browse files
authored
Improving Test-AzPostgreSqlFlexibleServerConnect (#28077)
1 parent 2b16d26 commit d673a3a

File tree

8 files changed

+95
-38
lines changed

8 files changed

+95
-38
lines changed

src/PostgreSql/PostgreSql.Autorest/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
[assembly: System.Reflection.AssemblyCopyrightAttribute("Copyright © Microsoft")]
2121
[assembly: System.Reflection.AssemblyProductAttribute("Microsoft Azure PowerShell")]
2222
[assembly: System.Reflection.AssemblyTitleAttribute("Microsoft Azure PowerShell - PostgreSql")]
23-
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.2.0")]
24-
[assembly: System.Reflection.AssemblyVersionAttribute("1.2.0")]
23+
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.3.0")]
24+
[assembly: System.Reflection.AssemblyVersionAttribute("1.3.0")]
2525
[assembly: System.Runtime.InteropServices.ComVisibleAttribute(false)]
2626
[assembly: System.CLSCompliantAttribute(false)]

src/PostgreSql/PostgreSql.Autorest/custom/Test-AzPostgreSqlFlexibleServerConnect.ps1

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ function Test-AzPostgreSqlFlexibleServerConnect {
4242
[System.String]
4343
${QueryText},
4444

45+
[Parameter(HelpMessage = 'The timeout in seconds for query execution. Valid range is 1-31536000 seconds.')]
46+
[Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category('Body')]
47+
[ValidateRange(1, 31536000)]
48+
[System.Int32]
49+
${Timeout},
50+
4551
[Parameter(ParameterSetName='TestViaIdentity', Mandatory, ValueFromPipeline, HelpMessage = 'The server to connect.')]
4652
[Parameter(ParameterSetName='TestViaIdentityAndQuery', Mandatory, ValueFromPipeline, HelpMessage = 'The server to connect.')]
4753
[Microsoft.Azure.PowerShell.Cmdlets.PostgreSql.Category('Body')]
@@ -118,6 +124,12 @@ function Test-AzPostgreSqlFlexibleServerConnect {
118124
$null = $PSBoundParameters.Remove('QueryText')
119125
}
120126

127+
$TimeoutValue = 0
128+
if ($PSBoundParameters.ContainsKey('Timeout')) {
129+
$TimeoutValue = $PSBoundParameters.Timeout
130+
$null = $PSBoundParameters.Remove('Timeout')
131+
}
132+
121133
$DatabaseName = [string]::Empty
122134
if ($PSBoundParameters.ContainsKey('DatabaseName')) {
123135
$DatabaseName = $PSBoundParameters.DatabaseName
@@ -143,14 +155,24 @@ function Test-AzPostgreSqlFlexibleServerConnect {
143155
if ($Server.NetworkPublicNetworkAccess -eq 'Disabled'){
144156
Write-Host "You have to run the test cmdlet in the subnet your server is linked."
145157
}
158+
159+
# Create PSCredential object for database connection
160+
$SecurePassword = ConvertTo-SecureString -String $Password -AsPlainText -Force
161+
$Credential = New-Object System.Management.Automation.PSCredential($AdministratorUserName, $SecurePassword)
146162

147163
try {
148-
if ([string]::IsNullOrEmpty($DatabaseName)){
149-
Open-PostGreConnection -Database "postgres" -Server $HostAddr -UserName $AdministratorUserName -Password $Password -RequireSSL -WarningAction 'silentlycontinue'
164+
$DbToUse = if ([string]::IsNullOrEmpty($DatabaseName)) { "postgres" } else { $DatabaseName }
165+
$OpenConnParams = @{
166+
Database = $DbToUse
167+
Server = $HostAddr
168+
Credential = $Credential
169+
SSLMode = 'Require'
170+
WarningAction = 'SilentlyContinue'
150171
}
151-
else {
152-
Open-PostGreConnection -Database $DatabaseName -Server $HostAddr -UserName $AdministratorUserName -Password $Password -RequireSSL -WarningAction 'silentlycontinue'
172+
if ($TimeoutValue -gt 0) {
173+
$OpenConnParams['CommandTimeout'] = $TimeoutValue
153174
}
175+
Open-PostGreConnection @OpenConnParams
154176

155177
} catch {
156178
Write-Host $_.Exception.GetType().FullName

src/PostgreSql/PostgreSql.Autorest/docs/Test-AzPostgreSqlFlexibleServerConnect.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,28 @@ Test out the connection to the database server
1616
```
1717
Test-AzPostgreSqlFlexibleServerConnect -Name <String> -ResourceGroupName <String>
1818
-AdministratorLoginPassword <SecureString> [-DatabaseName <String>] [-AdministratorUserName <String>]
19-
[-DefaultProfile <PSObject>] [<CommonParameters>]
19+
[-Timeout <Int32>] [-DefaultProfile <PSObject>] [<CommonParameters>]
2020
```
2121

2222
### TestAndQuery
2323
```
2424
Test-AzPostgreSqlFlexibleServerConnect -Name <String> -QueryText <String> -ResourceGroupName <String>
2525
-AdministratorLoginPassword <SecureString> [-DatabaseName <String>] [-AdministratorUserName <String>]
26-
[-DefaultProfile <PSObject>] [<CommonParameters>]
26+
[-Timeout <Int32>] [-DefaultProfile <PSObject>] [<CommonParameters>]
2727
```
2828

2929
### TestViaIdentity
3030
```
3131
Test-AzPostgreSqlFlexibleServerConnect -AdministratorLoginPassword <SecureString>
3232
-InputObject <IPostgreSqlIdentity> [-DatabaseName <String>] [-AdministratorUserName <String>]
33-
[-DefaultProfile <PSObject>] [<CommonParameters>]
33+
[-Timeout <Int32>] [-DefaultProfile <PSObject>] [<CommonParameters>]
3434
```
3535

3636
### TestViaIdentityAndQuery
3737
```
3838
Test-AzPostgreSqlFlexibleServerConnect -QueryText <String> -AdministratorLoginPassword <SecureString>
3939
-InputObject <IPostgreSqlIdentity> [-DatabaseName <String>] [-AdministratorUserName <String>]
40-
[-DefaultProfile <PSObject>] [<CommonParameters>]
40+
[-Timeout <Int32>] [-DefaultProfile <PSObject>] [<CommonParameters>]
4141
```
4242

4343
## DESCRIPTION
@@ -226,6 +226,22 @@ Accept pipeline input: False
226226
Accept wildcard characters: False
227227
```
228228
229+
### -Timeout
230+
The timeout in seconds for query execution.
231+
Valid range is 1-31536000 seconds.
232+
233+
```yaml
234+
Type: System.Int32
235+
Parameter Sets: (All)
236+
Aliases:
237+
238+
Required: False
239+
Position: Named
240+
Default value: None
241+
Accept pipeline input: False
242+
Accept wildcard characters: False
243+
```
244+
229245
### CommonParameters
230246
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
231247
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"generate_Id": "f0b983f7-1a63-4b8a-b719-bcd0e1c97929"
2+
"generate_Id": "bfbf7319-ac2b-49dc-bb4f-1077a26134ae"
33
}

src/PostgreSql/PostgreSql.sln

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PostgreSql", "PostgreSql\Po
2121
EndProject
2222
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "PostgreSql.Autorest", "PostgreSql.Autorest", "{13094E6E-96F2-6DF6-64F8-503BB38C0FC8}"
2323
EndProject
24-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Az.PostgreSql", "..\..\generated\PostgreSql\PostgreSql.Autorest\Az.PostgreSql.csproj", "{821300FF-FF06-4721-AF0E-7F3578E797B9}"
24+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Az.PostgreSql", "..\..\generated\PostgreSql\PostgreSql.Autorest\Az.PostgreSql.csproj", "{0E9754EB-32F4-49B8-B063-312688BF7BB1}"
2525
EndProject
2626
Global
2727
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -117,18 +117,18 @@ Global
117117
{8B793448-8CB8-40DC-9269-356B1272E2BB}.Release|x64.Build.0 = Release|Any CPU
118118
{8B793448-8CB8-40DC-9269-356B1272E2BB}.Release|x86.ActiveCfg = Release|Any CPU
119119
{8B793448-8CB8-40DC-9269-356B1272E2BB}.Release|x86.Build.0 = Release|Any CPU
120-
{821300FF-FF06-4721-AF0E-7F3578E797B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
121-
{821300FF-FF06-4721-AF0E-7F3578E797B9}.Debug|Any CPU.Build.0 = Debug|Any CPU
122-
{821300FF-FF06-4721-AF0E-7F3578E797B9}.Debug|x64.ActiveCfg = Debug|Any CPU
123-
{821300FF-FF06-4721-AF0E-7F3578E797B9}.Debug|x64.Build.0 = Debug|Any CPU
124-
{821300FF-FF06-4721-AF0E-7F3578E797B9}.Debug|x86.ActiveCfg = Debug|Any CPU
125-
{821300FF-FF06-4721-AF0E-7F3578E797B9}.Debug|x86.Build.0 = Debug|Any CPU
126-
{821300FF-FF06-4721-AF0E-7F3578E797B9}.Release|Any CPU.ActiveCfg = Release|Any CPU
127-
{821300FF-FF06-4721-AF0E-7F3578E797B9}.Release|Any CPU.Build.0 = Release|Any CPU
128-
{821300FF-FF06-4721-AF0E-7F3578E797B9}.Release|x64.ActiveCfg = Release|Any CPU
129-
{821300FF-FF06-4721-AF0E-7F3578E797B9}.Release|x64.Build.0 = Release|Any CPU
130-
{821300FF-FF06-4721-AF0E-7F3578E797B9}.Release|x86.ActiveCfg = Release|Any CPU
131-
{821300FF-FF06-4721-AF0E-7F3578E797B9}.Release|x86.Build.0 = Release|Any CPU
120+
{0E9754EB-32F4-49B8-B063-312688BF7BB1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
121+
{0E9754EB-32F4-49B8-B063-312688BF7BB1}.Debug|Any CPU.Build.0 = Debug|Any CPU
122+
{0E9754EB-32F4-49B8-B063-312688BF7BB1}.Debug|x64.ActiveCfg = Debug|Any CPU
123+
{0E9754EB-32F4-49B8-B063-312688BF7BB1}.Debug|x64.Build.0 = Debug|Any CPU
124+
{0E9754EB-32F4-49B8-B063-312688BF7BB1}.Debug|x86.ActiveCfg = Debug|Any CPU
125+
{0E9754EB-32F4-49B8-B063-312688BF7BB1}.Debug|x86.Build.0 = Debug|Any CPU
126+
{0E9754EB-32F4-49B8-B063-312688BF7BB1}.Release|Any CPU.ActiveCfg = Release|Any CPU
127+
{0E9754EB-32F4-49B8-B063-312688BF7BB1}.Release|Any CPU.Build.0 = Release|Any CPU
128+
{0E9754EB-32F4-49B8-B063-312688BF7BB1}.Release|x64.ActiveCfg = Release|Any CPU
129+
{0E9754EB-32F4-49B8-B063-312688BF7BB1}.Release|x64.Build.0 = Release|Any CPU
130+
{0E9754EB-32F4-49B8-B063-312688BF7BB1}.Release|x86.ActiveCfg = Release|Any CPU
131+
{0E9754EB-32F4-49B8-B063-312688BF7BB1}.Release|x86.Build.0 = Release|Any CPU
132132
EndGlobalSection
133133
GlobalSection(SolutionProperties) = preSolution
134134
HideSolutionNode = FALSE
@@ -140,6 +140,6 @@ Global
140140
{5A8C3DAF-DF74-4B98-952B-14FFA02F8083} = {DDF03C15-34E0-4EF7-B432-7B4B8366B206}
141141
{A76B07F7-0B1C-4AB1-9466-1A687D8D0E92} = {DDF03C15-34E0-4EF7-B432-7B4B8366B206}
142142
{BB6BD8B7-F08E-4ED4-A7C5-B79CAB788176} = {DDF03C15-34E0-4EF7-B432-7B4B8366B206}
143-
{821300FF-FF06-4721-AF0E-7F3578E797B9} = {13094E6E-96F2-6DF6-64F8-503BB38C0FC8}
143+
{0E9754EB-32F4-49B8-B063-312688BF7BB1} = {13094E6E-96F2-6DF6-64F8-503BB38C0FC8}
144144
EndGlobalSection
145145
EndGlobal

src/PostgreSql/PostgreSql/Az.PostgreSql.psd1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
# Generated by: Microsoft Corporation
55
#
6-
# Generated on: 5/28/2025
6+
# Generated on: 7/1/2025
77
#
88

99
@{
@@ -51,16 +51,16 @@ DotNetFrameworkVersion = '4.7.2'
5151
# ProcessorArchitecture = ''
5252

5353
# Modules that must be imported into the global environment prior to importing this module
54-
RequiredModules = @(@{ModuleName = 'Az.Accounts'; ModuleVersion = '5.0.2'; })
54+
RequiredModules = @(@{ModuleName = 'Az.Accounts'; ModuleVersion = '5.1.1'; })
5555

5656
# Assemblies that must be loaded prior to importing this module
5757
RequiredAssemblies = 'PostgreSql.Autorest/bin/Az.PostgreSql.private.dll'
5858

5959
# Script files (.ps1) that are run in the caller's environment prior to importing this module.
60-
# ScriptsToProcess = @()
60+
ScriptsToProcess = @()
6161

6262
# Type files (.ps1xml) to be loaded when importing this module
63-
# TypesToProcess = @()
63+
TypesToProcess = @()
6464

6565
# Format files (.ps1xml) to be loaded when importing this module
6666
FormatsToProcess = 'PostgreSql.Autorest/Az.PostgreSql.format.ps1xml'
@@ -126,7 +126,7 @@ PrivateData = @{
126126
PSData = @{
127127

128128
# Tags applied to this module. These help with module discovery in online galleries.
129-
Tags = 'Azure','ResourceManager','ARM','PSModule','PostgreSql'
129+
Tags = 'Azure', 'ResourceManager', 'ARM', 'PSModule', 'PostgreSql'
130130

131131
# A URL to the license for this module.
132132
LicenseUri = 'https://aka.ms/azps-license'
@@ -153,7 +153,7 @@ PrivateData = @{
153153

154154
} # End of PSData hashtable
155155

156-
} # End of PrivateData hashtable
156+
} # End of PrivateData hashtable
157157

158158
# HelpInfo URI of this module
159159
# HelpInfoURI = ''

src/PostgreSql/PostgreSql/ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
- Additional information about change #1
1919
-->
2020
## Upcoming Release
21+
- Aligned with SimplySql, use a PSCredential object instead of UserName/Password parameters when calling Open-PostGreConnection
22+
- Introduced a Timeout value when running Test-AzPostgreSqlFlexibleServerConnect with long running query
2123

2224
## Version 1.3.0
2325
* Added support for Geo-restore in `Restore-AzPostgreSqlFlexibleServer` cmdlets.

src/PostgreSql/PostgreSql/help/Test-AzPostgreSqlFlexibleServerConnect.md

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,31 @@ Test out the connection to the database server
1515
### Test (Default)
1616
```
1717
Test-AzPostgreSqlFlexibleServerConnect -Name <String> -ResourceGroupName <String> [-DatabaseName <String>]
18-
-AdministratorLoginPassword <SecureString> [-AdministratorUserName <String>] [-DefaultProfile <PSObject>]
19-
[<CommonParameters>]
18+
-AdministratorLoginPassword <SecureString> [-Timeout <Int32>] [-AdministratorUserName <String>]
19+
[-DefaultProfile <PSObject>] [<CommonParameters>]
2020
```
2121

2222
### TestAndQuery
2323
```
2424
Test-AzPostgreSqlFlexibleServerConnect -Name <String> -ResourceGroupName <String> [-DatabaseName <String>]
25-
-QueryText <String> -AdministratorLoginPassword <SecureString> [-AdministratorUserName <String>]
26-
[-DefaultProfile <PSObject>] [<CommonParameters>]
25+
-QueryText <String> -AdministratorLoginPassword <SecureString> [-Timeout <Int32>]
26+
[-AdministratorUserName <String>] [-DefaultProfile <PSObject>]
27+
[<CommonParameters>]
2728
```
2829

2930
### TestViaIdentityAndQuery
3031
```
3132
Test-AzPostgreSqlFlexibleServerConnect [-DatabaseName <String>] -QueryText <String>
32-
-AdministratorLoginPassword <SecureString> [-AdministratorUserName <String>]
33+
-AdministratorLoginPassword <SecureString> [-Timeout <Int32>] [-AdministratorUserName <String>]
3334
-InputObject <IPostgreSqlIdentity> [-DefaultProfile <PSObject>]
3435
[<CommonParameters>]
3536
```
3637

3738
### TestViaIdentity
3839
```
3940
Test-AzPostgreSqlFlexibleServerConnect [-DatabaseName <String>] -AdministratorLoginPassword <SecureString>
40-
[-AdministratorUserName <String>] -InputObject <IPostgreSqlIdentity> [-DefaultProfile <PSObject>]
41-
[<CommonParameters>]
41+
[-Timeout <Int32>] [-AdministratorUserName <String>] -InputObject <IPostgreSqlIdentity>
42+
[-DefaultProfile <PSObject>] [<CommonParameters>]
4243
```
4344

4445
## DESCRIPTION
@@ -227,6 +228,22 @@ Accept pipeline input: False
227228
Accept wildcard characters: False
228229
```
229230
231+
### -Timeout
232+
The timeout in seconds for query execution.
233+
Valid range is 1-31536000 seconds.
234+
235+
```yaml
236+
Type: System.Int32
237+
Parameter Sets: (All)
238+
Aliases:
239+
240+
Required: False
241+
Position: Named
242+
Default value: None
243+
Accept pipeline input: False
244+
Accept wildcard characters: False
245+
```
246+
230247
### CommonParameters
231248
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
232249

0 commit comments

Comments
 (0)